• Python-pickle error

    From charles wiewiora@21:1/5 to All on Wed Apr 19 16:14:25 2023
    Hello,
    I am experincing problems with the pickle moducle
    the folowing code was working before,

    import pickle
    number=2
    my_pickeld_object=pickle.dumps(number)
    print("this is my pickled object",{my_pickeld_object},)
    with open('file.pkl', 'rb') as file:
    number=pickle.load(file) my_unpickeled_object=pickle.loads(my_pickeld_object)
    print("this is my unpickeled object",{my_unpickeled_object},)

    but now i get error

    Traceback (most recent call last):
    File "C:\Users\lukwi\Desktop\python\tester2.py", line 5, in <module>
    with open('file.pkl', 'rb') as file:
    FileNotFoundError: [Errno 2] No such file or directory: 'file.pkl'

    im get this problem after this,
    a .pkl came into my Python script files
    i though this could be a spare file made from python becauce i was doing this first,

    import pickle
    number=2
    my_pickeld_object=pickle.dumps(number)
    print("this is my pickled object",{my_pickeld_object},)
    with open('file.pkl', 'rb') as file:
    number=pickle.load(file)

    so i stupidly deleted the file

    do you know how to fix this?
    i reinstalled it but it didn't work
    this is on widnows and on version 3.11.3 on python

    thank you

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to charles wiewiora on Wed Apr 19 17:12:04 2023
    On 4/19/2023 12:14 PM, charles wiewiora wrote:
    Hello,
    I am experincing problems with the pickle moducle
    the folowing code was working before,

    import pickle
    number=2
    my_pickeld_object=pickle.dumps(number)
    print("this is my pickled object",{my_pickeld_object},)
    with open('file.pkl', 'rb') as file:
    number=pickle.load(file) my_unpickeled_object=pickle.loads(my_pickeld_object)
    print("this is my unpickeled object",{my_unpickeled_object},)

    but now i get error

    Traceback (most recent call last):
    File "C:\Users\lukwi\Desktop\python\tester2.py", line 5, in <module>
    with open('file.pkl', 'rb') as file:
    FileNotFoundError: [Errno 2] No such file or directory: 'file.pkl'

    That's because you haven't saved anything to a file named "file.pkl". If
    this code seemed to work in the past, it may have been because there was
    a file named "file.pkl" left over from some previous experiment. But
    it's not there now, and even if it were it would not contain your
    current pickled object.

    Take a look at .load() and .dump() (instead of .loads() and .dumps().
    Maybe they will do what you want a little easier.

    im get this problem after this,
    a .pkl came into my Python script files
    i though this could be a spare file made from python becauce i was doing this first,

    import pickle
    number=2
    my_pickeld_object=pickle.dumps(number)
    print("this is my pickled object",{my_pickeld_object},)
    with open('file.pkl', 'rb') as file:
    number=pickle.load(file)

    so i stupidly deleted the file

    do you know how to fix this?
    i reinstalled it but it didn't work
    this is on widnows and on version 3.11.3 on python

    thank you

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)