[Tutor] Re: newbie question

Gregor Lingl glingl@aon.at
Mon Jul 21 13:09:05 2003


Hi Jan!

Two short remarks to your problems:

(1)

>But here I get only one dictionary item for both:
>
>
>Kjeu
>
>And=20
>
>Kjeu I
>

You get this because here line is "kjeu I        984"
and thus line.split() has three items:

>>> line ="kjeu I        984"
>>> line.split()
['kjeu', 'I', '984']
>>> 

One way to handle this problem could be:

>>> line.rfind(" ")
13
>>> sep = line.rfind(" ")
>>> line[:sep]
'kjeu I       '
>>> line[:sep].strip()
'kjeu I'
>>> line[sep:]
' 984'
>>> line[sep:].strip()
'984'
>>> table = {}
>>> table[line[:sep].strip()] = line[sep:].strip()
>>> table
{'kjeu I': '984'}
>>> 

(2)

>When I print out the M=E9g post I get M\xe9g , how can I deal with =
>this? This
>might not a problem if only the output to the new file is ok.

>>> print "M\xe9g"
Még
>>> ord("\xe9")
233

This shows, that "\xe9" is the internal (hex-) representation of
a character with ascii-code > 127, namely an e with some accent
and ascii-code 233.

If you feed it directly into a print-statement it will be displayed 
correctly.

HTH
Gregor