Why does this (very simple piece of) code does not work?
Peter Hansen
peter at engcorp.com
Mon Aug 16 09:16:59 EDT 2004
jblazi wrote:
> import os
>
> L = os.listdir('.')
>
> for x in L:
> print '!'+x+'!'+x[0]
> if x != 'rename.py':
> y = 'Kapustin (Hamelin): '+x
> os.rename(x,y)
>
> I get
>
> Traceback (most recent call last):
> File "<stdin>", line 9, in ?
> OSError: [Errno 22] Invalid argument
You didn't specify your OS, version of Python, etc,
but perhaps we can guess why it doesn't work anyway.
Have you tried executing the equivalent command manually,
either from the command line or from, say, Explorer (assuming
you're on Windows)? Can you rename any file to contain
parentheses and colons on your OS? If not, there's
your answer.
-Peter
More information about the Python-list
mailing list