Python + IIS/ASP questions (modules, namespaces, etc)

Mark Hammond mhammond at skippinet.com.au
Fri Dec 20 18:22:58 EST 2002


Preston Landers wrote:
> And since I really want all the strings as regular strings instead of
> unicode, I also did this:
> 
> import types
> def ununicode(x):
>     if type(x) is types.UnicodeType:
>         return str(x)
>     else:
>         return x

Note that this will bite your bum as soon as you have non-ASCII data in 
one of your rows.

You really are better off trying to avoid converting from Unicode to 
string at all - you will probably be amazed how far this will get you.

When you *do* need to convert, you should pick a real encoding, so 
non-ASCII characters are handled.  On Windows systems:

      if type(x) is types.UnicodeType:
          return x.encode("mbcs")
      else:
          return x

is generally correct.

Mark.




More information about the Python-list mailing list