Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Why does this (very simple piece of) code does not work?

Reply
Thread Tools

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

 
 
jblazi
Guest
Posts: n/a
 
      08-16-2004
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

 
Reply With Quote
 
 
 
 
Matteo Dell'Amico
Guest
Posts: n/a
 
      08-16-2004
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
 
Reply With Quote
 
 
 
 
Richard Brodie
Guest
Posts: n/a
 
      08-16-2004

"jblazi" <> wrote in message news...

> 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.


 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      08-16-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
 
Reply With Quote
 
Chris Cioffi
Guest
Posts: n/a
 
      08-16-2004
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!
 
Reply With Quote
 
jblazi
Guest
Posts: n/a
 
      08-16-2004
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with simple VHDL piece of code Jaco Naude VHDL 9 07-16-2007 10:26 PM
This small piece of code works in Firefox but not in IE 7... why? SM Javascript 2 04-30-2007 01:06 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Download a file piece by piece Patrick Plattes Ruby 2 11-30-2006 07:48 PM
Random Numbers -- why doesn't this piece of code work? Moritz Beller C++ 19 06-04-2004 04:16 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57