[Tutor] creating a tab delimited filename

Max Noel maxnoel_fr at yahoo.fr
Wed Mar 16 05:01:59 CET 2005


On Mar 16, 2005, at 03:54, jrlen balane wrote:

> how would i make this the correct path:
> filename = "%s%s.txt" %('C:\Documents and Settings\nyer\My
> Documents\Info',time.strftime("%Y%m%d%H%M"))
> table_file = open(os.path.normpath(filename),"a")
>
> running on IDLE, i get the following error:
>
> Traceback (most recent call last):
>   File "C:/Python23/practices/serialnewesttes3.py", line 65, in 
> -toplevel-
>     table_file = open(os.path.normpath(filename),"a")
> IOError: [Errno 2] No such file or directory: 'C:\\Documents and
> Settings\nyer\\My Documents\\Info200503161153.txt'
>
> it seems that it adds "\".

	The "\n" of "\nyer" is escaped as a new line. That's a Bad Thing. In 
fact, relying on backslashes being automatically escaped thanks to the 
following character not having a special meaning in escape context is a 
Bad Thing.
	Either way, it's better to use forward slashes (or os.sep if you're 
going for overkill and/or obscure, non-POSIX platforms), with which 
such problems just don't happen.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting 
and sweating as you run through my corridors... How can you challenge a 
perfect, immortal machine?"



More information about the Tutor mailing list