I just had to post this link – a few great abbreviations to use here.
Monthly Archives: December 2014
Myths about Python
I use Python for a few script applications, I think that many other users are in the same situation.
I will however try to implement more solutions in the systems I work with, the following link may provide some well founded arguments in the upcoming discussions you may face.
Generate it!
A collection of brilliant tools to aid in generating output, I tried the cronjob generator!
Character mapping
When processing intergration or conversion between systems you will more often than not come across differences in character encoding.
An example may be conversion from some characters in latin1 to iso646-se
[code lang=”python”]
# Conversion dictionary
latin1_to_iso646se = { 0xC5:0x5D, 0xC4:0x5B, 0xD6:0x5C, 0xE5:0x7D, 0xE4:0x7B, 0xF6:0x7C, 0xC9:0x40, 0xCB:0x45, 0xE9:0x60, 0xEB:0x65, 0x00:0x20 }
def translate_latin1_iso646se(latin1):
“””
Help translate latin1 to usascii.
:param latin1:
:return:
“””
return chr(latin1_to_iso646se[latin1])
def encode_line(line):
l = “”
try:
l = str(line).encode(‘us-ascii’)
except UnicodeDecodeError:
l = “”
r = range(len(line))
for c in range(len(line)):
j = ord(line[c])
if j > 127:
if j in latin1_to_iso646se.keys():
l += translate_latin1_iso646se(j)
else:
print “Skip char {0} {1}”.format(str(j),line[c])
else:
l += line[c]
finally:
return l
# Conversion called
print “latin1_line encoded as iso646se: “, encode_line(latin1_line):
[/code]
Python
Python is a script and programming language.