re.compile.match() results in unicode strings - why?

Axel Bock news-and-lists at the-me.de
Thu Nov 11 10:49:11 EST 2004


Scott David Daniels wrote:

> This shows a misunderstanding.  Python does not have typed variables.
>     a,b,c,d = 'a', 'b', 'c', 'd'
>     a = 4.5
>     b = 3+5j
>     c = u'\N{LATIN CAPITAL LETTER D WITH STROKE}one'
>     d = repr
> is perfectly legal.

sure, but that was not the question ... :-)

> The example is not concrete enough to reproduce.  Please give particular
> examples for blah and string.

if you like ...

** CODE **
string = "1. asdf asdf 327,88"
exp = re.compile("(\S+) (\S+) (\S+) (\S+).*")
m = exp.match(string)
print m.groups()
** /CODE **

the question now is (a little bit more precise): m.groups() delievers a list 
(ok, tuple) of string types. in my app they are all unicode, but the same code 
just typed in the shell produces "normal" strings.

now how does that unicode-string-triggering happen? I do definitely not see 
why python feels inclinded to return a unicode thingy here ...

as said - it is of no great importance, but I like to know ... :))


ciao & thanks anyways,

axel.



More information about the Python-list mailing list