#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    346
    Rep Power
    0

    date and string probs


    i have this code:
    Code:
    from shutil import *
    import datetime
    
    t = datetime.date.today()
    copytree('C:/Documents and Settings/dave/Desktop/install',
    		'C:/Documents and Settings/dave/Desktop/' + t, 0)
    
    raw_input()
    it won't run. i think the problem is that t may not be a string, so you can't add it to the file path to make a string.

    Any ideas?

    Thanks from the python newbie.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    17
    Rep Power
    0
    Did you read the interpreters output?

    It says something like:

    TypeError: cannot concatenate 'str' and 'datetime.date' objects

    ---

    coerce t to a string with str(t);

    Code:
    copytree('C:/Documents and Settings/dave/Desktop/install',
    		'C:/Documents and Settings/dave/Desktop/' + str(t), 0)
    I can't test beyond that because i dont have the same dir structure as you
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    346
    Rep Power
    0
    cheers buddy

    i guessed i might of had to cast it - i tried string(obj)

    wasn't far out!

IMN logo majestic logo threadwatch logo seochat tools logo