[Tutor] creating a tab delimited filename

jrlen balane nbbalane at gmail.com
Wed Mar 16 04:54:34 CET 2005


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


On Tue, 15 Mar 2005 19:45:31 -0500, Jacob S. <keridee at jayco.net> wrote:
> 
> 
> > that is exactly what i am looking for, but how would i add this to my
> > filename???
> > should i use this:
> >
> > output_file = open(os.path.join(self.Save_Session.GetValue(),
> > time.strftime('%Y%m%d%H%M')), 'w')
> >
> > the self.Save_Session.GetValue() is generated by a dirdialog
> >
> 
> Uck,uck, uck, no...
> 
> That's what Kent's post was for...
> This will do the trick.
> 
> filename = "%s%s.txt" %
> (self.Save_Session.GetValue(),time.strftime("%Y%m%d%H%M"))
> output_file = open(filename,"a")
> 
> This uses string formatting, are you familiar with that?
> 
> If not -- see here  http://docs.python.org/lib/typesseq-strings.html#l2h-211
> remember, if you don't understand--not that you wouldn't--you can always ask
> here.
> 
> HTH,
> Jacob
> 
>


More information about the Tutor mailing list