[Tutor] Making Incremental Filenames

Brian Hicks therealcaffeine at gmail.com
Wed Jul 11 07:59:34 CEST 2007


Hi, I'm making a webcam automation script (for a project 365 photo 
thing) and I can't figure out how to increment the filename every time 
the script saves an image.  I'm using this snippet of code to count the 
tiles in the directory:

    filecount = len(os.walk("C:\Users\Username\Desktop").next()[2])


This returns 4 in my case.  I tried using os.path.join to join 
"C:\Users\Username\Pictures\365\day",filecount (which is 4),".jpg" so I 
can save it using the webcam library I have, but that throws a rather 
serious looking error, which is like this:

    Traceback (most recent call last):
      File "<pyshell#16>", line 1, in <module>
        filename =
    os.path.join("C:\Users\Brian\Desktop\day",file_count,".jpg")
      File "C:\Python25\lib\ntpath.py", line 67, in join
        elif isabs(b):
      File "C:\Python25\lib\ntpath.py", line 53, in isabs
        s = splitdrive(s)[1]
      File "C:\Python25\lib\ntpath.py", line 119, in splitdrive
        if p[1:2] == ':':
    TypeError: 'int' object is unsubscriptable

I think I need to be looking into converting filecount to a string 
somehow instead of an integer, but once again I'm not sure how and all 
I've tried has given me errors.  Please help?

-Brian Hicks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070710/05a95cec/attachment.htm 


More information about the Tutor mailing list