os.lisdir, gets unicode, returns unicode... USUALLY?!?!?

"Martin v. Löwis" martin at v.loewis.de
Thu Nov 16 18:00:08 EST 2006


gabor schrieb:
> so basically i'd like to ask here: am i reading something incorrectly?

You are reading it correctly. This is how it behaves.

> or am i using os.listdir the "wrong way"? how do other people deal with
> this?

You didn't say why the behavior causes a problem for you -  you only
explained what the behavior is.

Most people use os.listdir in a way like this:

for name in os.listdir(path):
  full = os.path.join(path, name)
  attrib = os.stat(full)
  if some-condition:
    f = open(full)
  ...

All this code will typically work just fine with the current behavior,
so people typically don't see any problem.

Regards,
Martin



More information about the Python-list mailing list