Convert from numbers to letters

qwweeeit at yahoo.it qwweeeit at yahoo.it
Thu May 19 13:58:01 EDT 2005


Hi rh0dium,
Your  request gives me the opportunity of  showing a more realistic
example of the technique of "self-modification coding".
Although the coding is not as short as that suggested by the guys who
replayed to you, I think that it can be interesting....

# newVars.py
lCod=[]
for n in range(1,27):
.   lCod.append(chr(n+96)+'='+str(n)+'\n')
# other for-loops if you want define additional variables in sequence
(ex. aa,bb,cc etc...)
# write the variable definitions in the file "varDef.py"
fNewV=open('varDef.py','w')
fNewV.writelines(lCod)
fNewV.close()
from varDef import *
# ...
If you open the generated file (varDef.py) you can see all the variable
definitions, which are runned by "from varDef import *"
Bye.




More information about the Python-list mailing list