Why does this (very simple piece of) code does not work?

Discussion in 'Python' started by jblazi, Aug 16, 2004.

  1. jblazi

    jblazi Guest

    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


    TIA,

    jb
     
    jblazi, Aug 16, 2004
    #1
    1. Advertising

  2. jblazi wrote:
    > os.rename(x,y)


    > Traceback (most recent call last):
    > File "<stdin>", line 9, in ?
    > OSError: [Errno 22] Invalid argument


    Works fine here (Linux). Maybe you're using a platform where you use
    invalid characters for the filename?

    --
    Ciao,
    Matteo
     
    Matteo Dell'Amico, Aug 16, 2004
    #2
    1. Advertising

  3. "jblazi" <> wrote in message news:p...

    > y = 'Kapustin (Hamelin): '+x
    > os.rename(x,y)
    > OSError: [Errno 22] Invalid argument


    You didn't say what platform you are on but if it's Windows, then
    colons aren't allowed in filenames.
     
    Richard Brodie, Aug 16, 2004
    #3
  4. jblazi

    Peter Hansen Guest

    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
     
    Peter Hansen, Aug 16, 2004
    #4
  5. jblazi

    Chris Cioffi Guest

    Just a guess here, but is ':' a valid filename character on your OS?
    Most OSes seem to have it reserved for system use. Try using a
    hyphen.

    Chris

    On Mon, 16 Aug 2004 15:03:51 +0200, 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
    >
    > TIA,
    >
    > jb
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >



    --
    Still searching for an even prime > 2!
     
    Chris Cioffi, Aug 16, 2004
    #5
  6. jblazi

    jblazi Guest

    On Mon, 16 Aug 2004 14:16:21 +0100, Richard Brodie wrote:

    > You didn't say what platform you are on but if it's Windows, then
    > colons aren't allowed in filenames.


    Yes. Now it seems, my age begins to tell, I did not used to be so dumb...
    Thx.

    jb
     
    jblazi, Aug 16, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Moritz Beller
    Replies:
    19
    Views:
    702
    Pete Becker
    Jun 4, 2004
  2. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,249
    Smokey Grindel
    Dec 2, 2006
  3. olivier.melcher

    Help running a very very very simple code

    olivier.melcher, May 12, 2008, in forum: Java
    Replies:
    8
    Views:
    2,379
  4. Patrick Plattes

    Download a file piece by piece

    Patrick Plattes, Nov 30, 2006, in forum: Ruby
    Replies:
    2
    Views:
    239
    Patrick Plattes
    Nov 30, 2006
  5. SM
    Replies:
    2
    Views:
    193
Loading...

Share This Page