Thread: pickle problems

    #1
  1. No Profile Picture
    inexperienced and useless
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Stevenage, uk
    Posts
    10
    Rep Power
    0

    pickle problems


    I am wanting to pickle an object so that I can save it in a file, I seem to be having problems getting it to work, here's my code sample:

    pickle.dump(conn_table, open(proj/daylight/gwcgi/drh25452/merlin/conn_tab(), 'w')

    I wondered if anyone could see any problems or suddest anything else that could be causing this to generate errors?
  2. #2
  3. No Profile Picture
    Python Prophet
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Amersfoort, The Netherlands
    Posts
    45
    Rep Power
    14
    What errors do you get? I can't help you if I don't know the error.

    But I'm not sure if you can use proj/bla/conn_tab() as a vaild filename. It is a filename or a function call that would return a filename?
    Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems. - Jamie Zawinski, in comp.lang.emacs
  4. #3
  5. No Profile Picture
    inexperienced and useless
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2001
    Location
    Stevenage, uk
    Posts
    10
    Rep Power
    0

    the errors


    That's the problem, it's not generating any specific errors, it's just causing all of the code after it to fail, generating syntax errors.

    I don't know if this will help you at all, I'm a bit confused myself.

    Thanks
  6. #4
  7. No Profile Picture
    Python Prophet
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Amersfoort, The Netherlands
    Posts
    45
    Rep Power
    14
    Okay, just try to open the file outside the pickle.dump function, and then pass the file object on to the function. I guess you should be able to see where the syntax error is caused.

    But is this a filename: proj/daylight/gwcgi/drh25452/merlin/conn_tab(), or is it a function that's called to get a filename? If it's a filename, just put quotes around it to make it a string. If it's a function, I have no idea how this could be legal syntax for a function.
    Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems. - Jamie Zawinski, in comp.lang.emacs
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    0
    Rep Power
    0

    You need quotes


    Originally Posted by nickname
    pickle.dump(conn_table, open(proj/daylight/gwcgi/drh25452/merlin/conn_tab(), 'w')
    Try putting quotes around your filename.
    --
    Michael T. Babcock
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    You actually have unbalanced parenthesis too, try rewriting the line to something like this:

    Code:
    pickle.dump(conn_table, file('proj/daylight/gwcgi/drh25452/merlin/conn_tab', 'w'))
    Note: file() was introduced in Python 2.3 as the prefered way to open a file() opject.

    Mark.
    programming language development: www.netytan.com Hula

  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2004
    Location
    London, England
    Posts
    1,585
    Rep Power
    1373
    Since the original post was December 2001, I doubt that the poster is still worrying about this problem.

    Dave
  14. #8
  15. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    No, but it was easy enough to clear up. If only for mtb . So no real loss there.

    Now, the jetlag has me and its time for bed me thinks.

    Later Dave,

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo