# Processing/LLToBNG: alphaconv.py

File alphaconv.py, 5.2 KB (added by benj, 11 years ago) |
---|

Line | |
---|---|

1 | # Module containing a couple of simple alphabetic conversion functions |

2 | |

3 | # Function to convert a letter into a number, with A/a=1, B/b=2 etc. |

4 | def letter2number(let): |

5 | if (lower(let) == "a"): |

6 | return 1 |

7 | # end if |

8 | if (lower(let) == "b"): |

9 | return 2 |

10 | # end if |

11 | if (lower(let) == "c"): |

12 | return 3 |

13 | # end if |

14 | if (lower(let) == "d"): |

15 | return 4 |

16 | # end if |

17 | if (lower(let) == "e"): |

18 | return 5 |

19 | # end if |

20 | if (lower(let) == "f"): |

21 | return 6 |

22 | # end if |

23 | if (lower(let) == "g"): |

24 | return 7 |

25 | # end if |

26 | if (lower(let) == "h"): |

27 | return 8 |

28 | # end if |

29 | if (lower(let) == "i"): |

30 | return 9 |

31 | # end if |

32 | if (lower(let) == "j"): |

33 | return 10 |

34 | # end if |

35 | if (lower(let) == "k"): |

36 | return 11 |

37 | # end if |

38 | if (lower(let) == "l"): |

39 | return 12 |

40 | # end if |

41 | if (lower(let) == "m"): |

42 | return 13 |

43 | # end if |

44 | if (lower(let) == "n"): |

45 | return 14 |

46 | # end if |

47 | if (lower(let) == "o"): |

48 | return 15 |

49 | # end if |

50 | if (lower(let) == "p"): |

51 | return 16 |

52 | # end if |

53 | if (lower(let) == "q"): |

54 | return 17 |

55 | # end if |

56 | if (lower(let) == "r"): |

57 | return 18 |

58 | # end if |

59 | if (lower(let) == "s"): |

60 | return 19 |

61 | # end if |

62 | if (lower(let) == "t"): |

63 | return 20 |

64 | # end if |

65 | if (lower(let) == "u"): |

66 | return 21 |

67 | # end if |

68 | if (lower(let) == "v"): |

69 | return 22 |

70 | # end if |

71 | if (lower(let) == "w"): |

72 | return 23 |

73 | # end if |

74 | if (lower(let) == "x"): |

75 | return 24 |

76 | # end if |

77 | if (lower(let) == "y"): |

78 | return 25 |

79 | # end if |

80 | if (lower(let) == "z"): |

81 | return 26 |

82 | # end if |

83 | # end function |

84 | |

85 | # Function to convert a number to a letter, with 1=A/a, 2=B/b etc |

86 | def num2letter(num, case="U"): |

87 | if (num == 1): |

88 | if (case == "U"): |

89 | return "A" |

90 | else: |

91 | return "a" |

92 | # end if |

93 | # end if |

94 | if (num == 2): |

95 | if (case == "U"): |

96 | return "B" |

97 | else: |

98 | return "b" |

99 | # end if |

100 | # end if |

101 | if (num == 3): |

102 | if (case == "U"): |

103 | return "C" |

104 | else: |

105 | return "c" |

106 | # end if |

107 | # end if |

108 | if (num == 4): |

109 | if (case == "U"): |

110 | return "D" |

111 | else: |

112 | return "d" |

113 | # end if |

114 | # end if |

115 | if (num == 5): |

116 | if (case == "U"): |

117 | return "E" |

118 | else: |

119 | return "e" |

120 | # end if |

121 | # end if |

122 | if (num == 6): |

123 | if (case == "U"): |

124 | return "F" |

125 | else: |

126 | return "f" |

127 | # end if |

128 | # end if |

129 | if (num == 7): |

130 | if (case == "U"): |

131 | return "G" |

132 | else: |

133 | return "g" |

134 | # end if |

135 | # end if |

136 | if (num == 8): |

137 | if (case == "U"): |

138 | return "H" |

139 | else: |

140 | return "h" |

141 | # end if |

142 | # end if |

143 | if (num == 9): |

144 | if (case == "U"): |

145 | return "I" |

146 | else: |

147 | return "i" |

148 | # end if |

149 | # end if |

150 | if (num == 10): |

151 | if (case == "U"): |

152 | return "J" |

153 | else: |

154 | return "j" |

155 | # end if |

156 | # end if |

157 | if (num == 11): |

158 | if (case == "U"): |

159 | return "K" |

160 | else: |

161 | return "k" |

162 | # end if |

163 | # end if |

164 | if (num == 12): |

165 | if (case == "U"): |

166 | return "L" |

167 | else: |

168 | return "l" |

169 | # end if |

170 | # end if |

171 | if (num == 13): |

172 | if (case == "U"): |

173 | return "M" |

174 | else: |

175 | return "m" |

176 | # end if |

177 | # end if |

178 | if (num == 14): |

179 | if (case == "U"): |

180 | return "N" |

181 | else: |

182 | return "n" |

183 | # end if |

184 | # end if |

185 | if (num == 15): |

186 | if (case == "U"): |

187 | return "O" |

188 | else: |

189 | return "o" |

190 | # end if |

191 | # end if |

192 | if (num == 16): |

193 | if (case == "U"): |

194 | return "P" |

195 | else: |

196 | return "p" |

197 | # end if |

198 | # end if |

199 | if (num == 17): |

200 | if (case == "U"): |

201 | return "Q" |

202 | else: |

203 | return "q" |

204 | # end if |

205 | # end if |

206 | if (num == 18): |

207 | if (case == "U"): |

208 | return "R" |

209 | else: |

210 | return "r" |

211 | # end if |

212 | # end if |

213 | if (num == 19): |

214 | if (case == "U"): |

215 | return "S" |

216 | else: |

217 | return "s" |

218 | # end if |

219 | # end if |

220 | if (num == 20): |

221 | if (case == "U"): |

222 | return "T" |

223 | else: |

224 | return "t" |

225 | # end if |

226 | # end if |

227 | if (num == 21): |

228 | if (case == "U"): |

229 | return "U" |

230 | else: |

231 | return "u" |

232 | # end if |

233 | # end if |

234 | if (num == 22): |

235 | if (case == "U"): |

236 | return "V" |

237 | else: |

238 | return "v" |

239 | # end if |

240 | # end if |

241 | if (num == 23): |

242 | if (case == "U"): |

243 | return "W" |

244 | else: |

245 | return "w" |

246 | # end if |

247 | # end if |

248 | if (num == 24): |

249 | if (case == "U"): |

250 | return "X" |

251 | else: |

252 | return "x" |

253 | # end if |

254 | # end if |

255 | if (num == 25): |

256 | if (case == "U"): |

257 | return "Y" |

258 | else: |

259 | return "y" |

260 | # end if |

261 | # end if |

262 | if (num == 26): |

263 | if (case == "U"): |

264 | return "Z" |

265 | else: |

266 | return "z" |

267 | # end if |

268 | # end if |

269 | # end function |