Python: How to Save and Load Data for Beginners

Поделиться
HTML-код
  • Опубликовано: 5 сен 2024
  • In this video, you will learn how to use the pickle module, which lets you easily save and load data to and from a file.
    If you want to further help my channel produce great content:
    ►►Support me on Patreon: / tokyoedtech
    ►►Click on the following Amazon Affiliate Links:
    ►►►►My Laptop (Asus Zenbook 13): amzn.to/2H3DLbF
    ►►►►My New Microphone (Blue Yeti Pro): amzn.to/2HmjOgN
    ►►►►My Old Microphone (Blue Snowball): amzn.to/3j8magh
    ►►►►My USB Interface (Focusrite Scarlett Solo): amzn.to/3kqyo5m
    ▶▶NEED HELP?◀◀
    Watch this first and then let me know in the comments below: • Help Me Help You
    ▶▶▶▶ LINKS ◀◀◀◀
    ►►GITHUB: github.com/wyn...
    ►►Support me on Patreon: / tokyoedtech
    ►►Follow me on Twitter: / tokyoedtech
    ►►Subscribe to my Newsletter: eepurl.com/dKgM8k
    ►►Check out my Blog: christianthomp...
    ►►Download Geany Editor: www.geany.org
    ▶▶▶▶ LEARN MORE PYTHON ◀◀◀◀
    ►►Space Invaders: • Python Game Programmin...
    ►►Snake Game: • Python Game Programmin...
    ►►Pong: • Python Game Programmin...
    ►►Space War: • Python Game Programmin...
    ►►Intro to Python (for Java Coders): • Intro to Python for Ja...
    *AND*
    ►►Space Arena - The Ultimate Python Turtle Graphics Game Tutorial: • Ultimate Python Turtle...
    ▶▶▶▶ LEARN MORE JAVA ◀◀◀◀
    ►►Basic Java for Beginners: • Basic Java 1&2: Commen...
    ►►Intro to AP Computer Science A: • AP Computer Science Un...

Комментарии • 275

  • @valizeth4073
    @valizeth4073 6 лет назад +49

    On windows system("cls") works

    • @valizeth4073
      @valizeth4073 6 лет назад +1

      Christian Thompson I use both linux and windows. The system cls is standard for clearing console in C++/C and it works for python and possibly more langs

    • @kishonoi191
      @kishonoi191 3 года назад

      import os
      print('hello world')
      X = input('click enter to clear')
      os.system('clear')

    • @a-bison
      @a-bison 3 года назад +1

      import os
      os.system("cls")
      #it is a lot more reliable

  • @industrialdonut7681
    @industrialdonut7681 5 лет назад +5

    This is fantastic, I finally understand what pickle actually is. Halfway through the video I did, and I've literally tried reading about how to use it MULTIPLE times before with it just actually making no sense for some reason. This is rather simple though.

  • @Alexrules237
    @Alexrules237 5 лет назад +57

    AC/DC and Python in one video...
    Who could ask for more?

    • @a-bison
      @a-bison 3 года назад

      fish shell, pickles, and Linux, in summary, penguin eating fish pickle

  • @Windfallval
    @Windfallval 3 года назад +19

    rip Bon Scott :(

  • @andrewolacey
    @andrewolacey 4 года назад +9

    You are the best! Such a clear and concise explanation! You have definitely earned a subscriber!

  • @FezanRafique
    @FezanRafique 4 года назад +21

    Thanks, simple but very useful tutorial :)

  • @kurtthorsten4463
    @kurtthorsten4463 3 года назад +7

    Simple and concise, thank you

  • @rafy-ivanmorales3077
    @rafy-ivanmorales3077 2 года назад

    Rafy-Ivan Morales
    0 seconds ago
    I'm a new student trying to learn, so I can become a programmer with python and I have a project on how to make a port scan.
    So far I already make a port scan with Python3, and it scans fine, give a date and everything working good so far.
    I see on your video tutorial you give example on how to send and receiving data.
    I would like to ask for your advice if you can and guide me on how I will add this 3
    in a Python script, I have:
    2. System should look for all the ports between the range of 1 to 1025
    3. If the Ports is open, it should create a file and add an entry for port number
    4. In case of any exception for instance “host is not available”, “host name could not be resolved” or
    due to any other error, you need to write that exception into the same file.
    Thank you and Merry Christmas.

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      That's quite a project! I haven't done anything like that myself, but I7d try breaking it down:
      1. Can you scan a port?
      2. Can you create a file?
      3. Can you update the file?
      4. Can you determine if a host is not available, or not resolved?
      Do it step by step and add each functionality as you go along.

  • @Boy-tz3ow
    @Boy-tz3ow 4 года назад +8

    Oh, so this method doesn't overwrite the values saved in the file when you run the program again.

    • @survivalist2607
      @survivalist2607 3 года назад

      AWWWWWWWWWWWWW MANNNNNNNNNNNNNNN!

    • @mateusz11123
      @mateusz11123 3 года назад

      It does. It work correctly, what do you mean (I now, its been 1 year)

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      It should.

    • @mateusz11123
      @mateusz11123 3 года назад +1

      @@TokyoEdTech it does it does. Btw thanks for the tutorial, very helpful, strict to the point :)

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      You're quite welcome - keep on codin'!

  • @OktaFierce
    @OktaFierce Год назад +1

    Great channel. Could this save then load back a whole instance of a class?

    • @TokyoEdTech
      @TokyoEdTech  Год назад +1

      I am pretty sure the answer is yes. Give it a shot and let us know!

  • @rohitkumarj632
    @rohitkumarj632 4 года назад +1

    Can u please put up a video on pickle by creating a class node and inserting new nodes like binary search tree and save it. Again open the file and add new nodes with some values. And display the output with just a function to search new value as well as old values. The job is to not repeat the insertion of old items again. But the algorithm must only insert new items display the result using the time consumed. Can you please take it as a challenge. Plz help me to solve this. 🙂👍🏻

  • @FilipeHyphen
    @FilipeHyphen 3 года назад +2

    Hi, very informative video, is there a way to create a list of numbers from a bunch of different inputs, probably as floats for what i need, and then be able to save the inputs and change them if i need to?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Sure - you'd need to use a list and a loop but it should be pretty straightforward.

  • @animationsbelike
    @animationsbelike 2 года назад +1

    omg thank you i searched the whole day for a solution xD

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      You're welcome - glad I could help. Keep on codin'!

  • @7own878
    @7own878 4 года назад +2

    I really enjoy your coding style. I might take some inpiration from it.

  • @xorben1981
    @xorben1981 4 года назад +1

    Straight Forward! Love it

  • @pcfin7693
    @pcfin7693 3 года назад +1

    Excellent video! But what if I just want to save the list values to a file, but not the data structure (the list itself)? I've tried to do it, but couldn't figure out how it can be done.

    • @TokyoEdTech
      @TokyoEdTech  3 года назад +1

      Sorry I couldn't give you a better answer in the live chat. But, there's nothing really easier than the pickle module.

    • @pcfin7693
      @pcfin7693 3 года назад

      @@TokyoEdTech No problem. Thank you for trying to help :)

  • @brixlionstudio2402
    @brixlionstudio2402 2 года назад +1

    So is there a way to code it to where I could go out of the code, come back in and say I code a load screen and one of the options in load game, then can I load the file back in?

    • @TokyoEdTech
      @TokyoEdTech  2 года назад +1

      Do you mean closing the program and then coming back later?

    • @brixlionstudio2402
      @brixlionstudio2402 2 года назад

      @@TokyoEdTech yah

    • @brixlionstudio2402
      @brixlionstudio2402 2 года назад +2

      @@TokyoEdTech but I asked my coding teacher and he explained how

    • @TokyoEdTech
      @TokyoEdTech  2 года назад +1

      @@brixlionstudio2402 Ok - glad you got it sorted. Keep on codin'!

  • @Globulov
    @Globulov 2 года назад +1

    simple and clear thx fella !

  • @austino7770
    @austino7770 3 года назад

    soo cool!!!!! but im trying to write a "note" program that saves what you write and you can edit the varible.

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Everything you need is in the video, at least regarding saving and loading data.

  • @Phagocytosis
    @Phagocytosis 4 года назад

    So is the idea that each variable saved in this way would need its own file? Because you do not specify which variable to load from the file, so presumably it's loading the whole file as once to be saved in some variable upon loading, correct? So you would need a different file for each variable you are saving.
    I followed a tutorial once to create a roguelike game in Python and it made use of the Shelve module, which was quite similar, except that it uses a dictionary so that you can save different variables under a given name. If anyone watching would like to save multiple variables in a single file, that is probably something to look into, once you have understood the basics given in this video.

    • @Phagocytosis
      @Phagocytosis 4 года назад

      Ah, right, that makes sense. So I guess pickling a dictionary is about the equivalent of using Shelve. Thank you.

  • @Shiva-ur3ow
    @Shiva-ur3ow 5 лет назад +3

    You can use this to load game data Hint Hint space invaders score loading

    • @Shiva-ur3ow
      @Shiva-ur3ow 5 лет назад

      Christian Thompson Literally all your videos are so helpful. You deserve like a billion dollars.

    • @mr.caveira8043
      @mr.caveira8043 4 года назад

      @@TokyoEdTech how do I put this in space invasers? I went searching for this video to find out bue I just can't figure out what to do... Can you please give me the code to do it please? I have been strugling with this for a week now.

  • @devsquares
    @devsquares 3 года назад +1

    Thank You for this video! Helped me out a lot!

  • @eduardolemus1041
    @eduardolemus1041 4 года назад +1

    nice video man! ty!

  • @r_c_h_d7409
    @r_c_h_d7409 3 года назад

    Why would you not recommend this method for saving anything large? and what would be an example of something you might not save to disk via pickle?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      For example, a large database of information. With pickle, you need to load the entire contents into memory, make a change, and then save the entire contents back to disk. One error in the process and all your data is lost/corrupt.

  • @rafaelboisel5609
    @rafaelboisel5609 4 года назад +1

    I am trying to do a “high score” type function in a game I made, my problem is that I cannot compare the length of a list (my score) to a variable(?) (high score)... my end goal would be to save the score with pickle, compare the score with the highscore which starts at 0 and replace the highscore with the len(list) each time it is necessary... I’ve been struggling for a few days now... I could post the code if you need to see it.
    Great video btw !

    • @adammccamon49
      @adammccamon49 4 года назад

      @@TokyoEdTech why did you ignore my comment

    • @rafaelboisel5609
      @rafaelboisel5609 4 года назад

      Christian Thompson yeah for sure, I’ll do that first thing tomorrow : it’s getting a bit late here

    • @rafaelboisel5609
      @rafaelboisel5609 4 года назад +1

      @@TokyoEdTech Here's the link to the project, hope you can find a solution to my problem :
      pastebin.com/ZB8LYA6y

  • @aadichauhan947
    @aadichauhan947 5 лет назад +1

    wait, is there a way to add or append data to that file

  • @raiyan.aztecscoc6286
    @raiyan.aztecscoc6286 4 года назад

    Can you use the pickle module to save a high score for a game? If you can, how do you do it?

  • @nemene8585
    @nemene8585 3 года назад +1

    Thanks good sir!

  • @sodapopinski9922
    @sodapopinski9922 6 лет назад

    I don't know why you would use this though, say you have ATOM open and your writing code and need to save a list how is it any diff from coping the list and saving to a diff .py file than import that file when needed? its kind of the same thing, no?

  • @oliverlacika4994
    @oliverlacika4994 2 года назад

    it does not work, Have I to use backslashs in the path? When I try it it gives me an unicodec error.

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      Sorry, not sure what to tell you. The slashes depend on your operating system.

  • @ajnick5635
    @ajnick5635 3 года назад

    What if you saved data to a txt and then saved new data to a txt of the same name? Would it replace the data? Or is there a better way to update the data?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Yep - it would replace the data. If you're just saving a small amount of data, you can just save it all again. For larger amounts of data use a database. This will help you get started: ruclips.net/video/IL300fe71cU/видео.html

  • @liamg.-devkat9451
    @liamg.-devkat9451 6 лет назад +4

    Pickle Power!

  • @KrypticDonut
    @KrypticDonut 3 года назад +1

    this works really well thanks for teaching me this :)

  • @kreb216
    @kreb216 3 года назад +1

    Cool and easy stuff!

    • @TokyoEdTech
      @TokyoEdTech  3 года назад +1

      Yeah - easier than I thought!

  • @boyleo9586
    @boyleo9586 4 года назад +2

    What a great vid!!!!!!

  • @principaldogradegreecolleg2861
    @principaldogradegreecolleg2861 6 лет назад +2

    Great tutorial!!!

  • @aprameyaaithal9071
    @aprameyaaithal9071 5 лет назад

    Can u put more than one variable in a file? And how to go about it? Thx

  • @HarshSingh-lp5xo
    @HarshSingh-lp5xo 3 года назад

    but in my program pickle.load() is returning the path of the variable ,,,not the values of variable

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      I’m happy to take a look, but I need to see the actual code. Please share your code via pastebin.com link so I can download and test it. To learn how, please watch this video and then get back to me: ruclips.net/video/L6AwVuu6O3Y/видео.html Keep on codin’!

  • @gamertronky8648
    @gamertronky8648 2 года назад

    Thanks???! I created some python games(Bitcoin mining simulator(4000 lines of code) walkthrough on my channel)that are 100% pure python made but they are without saving system and now i founded a solution!!! THANKS FOR THAT TUTORIAL!!!!

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      You're welcome - glad I could help!

    • @gamertronky8648
      @gamertronky8648 2 года назад

      ​@@TokyoEdTech So for 2 variables you need to create 2 lines of saving?

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      @@gamertronky8648 The easiest way is to put all your values into a dictionary and then save that as one variable.
      game_data = {
      high_score: 2112,
      level: 1;
      player_name: "Tronky"
      }

    • @gamertronky8648
      @gamertronky8648 2 года назад

      @@TokyoEdTech Ahha, I totally forgot this way. Thanks.

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      @@gamertronky8648 Yepper.

  • @vaibhavkrkm
    @vaibhavkrkm 4 года назад

    Nice tutorial 👍
    I think we should close the file also right, after opening it, or use context mangers if possible..🤔

    • @vaibhavkrkm
      @vaibhavkrkm 4 года назад

      @@TokyoEdTech Thanks for replying..

  • @mohaytham7832
    @mohaytham7832 4 года назад

    Do you know you're awesome plus you saved my project thanks man

    • @mohaytham7832
      @mohaytham7832 4 года назад

      @@TokyoEdTech Hey so just wanted to say thanks again and that I finished it... It's a to do list application and you can download it from here (feel free to download it guys)
      drive.google.com/drive/folders/1GG9MdSWk25hMCYSt8aUOiiN93N8XbIjh?usp=sharing
      Also this is a video about it if you can't or don't want to install it
      ruclips.net/video/apO80H4_XV4/видео.html

  • @oliverlacika4994
    @oliverlacika4994 2 года назад

    Does it work on python 3.8?
    because when I try to load it in another session then it says: no such file or directory names.dat (errno 2)

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      If you are on Windows you may need the full path such as C:\....\

  • @SkyFly19853
    @SkyFly19853 4 года назад

    This is one of the things I need.
    Btw, does it work in Python 3?

    • @SkyFly19853
      @SkyFly19853 4 года назад

      @@TokyoEdTech
      Sure, I do!
      I understand!
      Thank you so much!
      💯💯💯💯💯💯

  • @ProHDGamer
    @ProHDGamer 2 года назад +1

    is this method work for save dictionary

  • @raghavkashyap5828
    @raghavkashyap5828 3 года назад

    I am really sorry if this question is stupid, I have just started really. I wanted to save the new list for the next time too. As in now when I close python and open it the next day, I dont want names to start with all 3 of them, I want names to only have those 2 names. How would I do that?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      I think this is addressed in the video - just load the file when you start. If there are two names saved, then that is all you'll have.

    • @raghavkashyap5828
      @raghavkashyap5828 3 года назад

      @@TokyoEdTech when I load it before creating this file, it will show an error that this file doesn't exist. And if I create the file in thr beginning it would be with the 3 names. Now everytime I restart the program it will start with 3 names, I then tried using an if statement, if file exists then ... And if it doesn't then create it, that didn't work either for some reason

  • @MOBZHH
    @MOBZHH 4 года назад

    Bro i have a question. How am i supposed to make a "money save file". I've made a lotery game and i want to save player's money in file, then read it into next game session and if he wins i will add money to his (lets say) wallet. How to sum up his previous balance with newly won money. Please help me

    • @MOBZHH
      @MOBZHH 4 года назад

      Ok nevermind it was so easy xD

  • @NOTNOTCAT
    @NOTNOTCAT 2 года назад

    Thanks a lot very useful tutorial

  • @sandipan17
    @sandipan17 4 года назад +1

    Hello @Christian Thompson,
    First of all, thanks for this informative video. Could you please let me know how to store multiple variables in a single file?

    • @sandipan17
      @sandipan17 4 года назад

      @deadninja Thanks for this!

    • @marzipug5439
      @marzipug5439 3 года назад +1

      @deadninja Wow this was really helpful :) ty for the info

    • @a-bison
      @a-bison 3 года назад +2

      maybe you could dump an array with all the variables, the code is going to be very inelegant but it will work :)

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Also you can use a dictionary.

    • @matiesheikh81
      @matiesheikh81 2 года назад +1

      @@TokyoEdTech
      For your help and join me fever for me

  • @kyleyoung4974
    @kyleyoung4974 4 года назад

    Thanks Christian!

  • @MTMByt
    @MTMByt 4 года назад

    Cool! Can you use this to make normal text, not binary?

    • @TokyoEdTech
      @TokyoEdTech  4 года назад

      You can save a string, but it will still be in a binary format.

  • @jff711
    @jff711 3 года назад

    Thank you very much.

  • @w1jester499
    @w1jester499 3 года назад

    Cool but what location in the disk does it save to

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      It saves it to the same folder as the .py file - at least on my computer it does.

  • @a-bison
    @a-bison 3 года назад +1

    how can i overwrite this? say i am making a game and the player wants to change his name, how can i delete the name, and then save it again with a different... content? @TokyoEdtech, thank you

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Just save the new data again - it will overwrite the previous data.

    • @a-bison
      @a-bison 3 года назад

      @@TokyoEdTech by the same file name you say?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      @@a-bison Yep - you got it.

    • @a-bison
      @a-bison 3 года назад

      @@TokyoEdTech Thank you so much!

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      @@a-bison You're welcome!

  • @manoharsagunthalla9215
    @manoharsagunthalla9215 4 года назад

    Will you please explain what is pickle and is etc in detail

  • @MediaMotifs
    @MediaMotifs 3 года назад

    Thanks :)

  • @redsus650
    @redsus650 4 года назад +1

    Can the pickle module save multiple variables? Great video btw

    • @redsus650
      @redsus650 4 года назад

      @@TokyoEdTech: thanks

    • @alexpedraza6573
      @alexpedraza6573 4 года назад

      @@TokyoEdTech What if I have a loop? Is there a way to save all the data in 1 file?
      Exp
      A dict that gets overwriting every time it loops (new values) but the old data just goes bye bye. Idk if that makes sense

  • @ktz2625
    @ktz2625 3 года назад

    How can I override a saved variable?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Just save the updated value - easy peasy!

  • @algatra6942
    @algatra6942 4 года назад

    Heyy, can i save many data to 1 file 'data.dat' ? Ofcourse in 1 variable only. I want to save my input() data to my 'data.dat' . Can i do that? Pls answer this :))
    Its like :
    bil = int(input('Input ur number : '))
    pickle.dump(bil, open("bil.dat", "wb")
    Then ill call "bil.dat" to a function

    • @algatra6942
      @algatra6942 4 года назад

      @@TokyoEdTech omgg thanks dude, u reply my comment fastly. Even this video was uploaded 1 year ago. Thank you

  • @SigmaLiving
    @SigmaLiving 4 года назад

    Is there a reason for saving it as a .dat file? Would it be wrong if I saved it as a .txt file?

    • @swastiksarkar
      @swastiksarkar 4 года назад

      @@TokyoEdTech Can you tell me how can I access the saved data in our disk externally without opening python? Is it possible. I want to use the saved data to copy and use it for other purposes.

  • @userrrr32
    @userrrr32 Год назад +1

    i made a secret diary that uses a password on my calculator using this tutorial. my calculator has python on it and has a usb plug on it. thanks allot.

    • @userrrr32
      @userrrr32 Год назад +1

      this is the code. it works on windows and linux,
      import pickle
      import sys
      import time
      import os
      permission = False
      passcode = "9089"
      ls = True
      maxguesses = 3
      guesses = 0
      out_of_guesses = False
      while ls == True and out_of_guesses == False:

      guess = input()

      if guess != passcode:
      print("wrong")
      guesses += 1

      if guess == passcode:
      print("correct")
      ls = False
      permission = True
      if guesses >= maxguesses:
      out_of_guesses = True

      if out_of_guesses == True:
      exit()

      if permission == True:
      ask = input("Write:7 Read:9
      reset/new:0")

      if ask == "7":
      diary = pickle.load(open("diary.txt", "rb")) + input()
      pickle.dump(diary, open("diary.txt", "wb"))
      if ask == "9":
      book = pickle.load(open("diary.txt", "rb"))
      print(book)
      if ask == "0":
      clear_book = ""
      pickle.dump(clear_book, open("diary.txt", "wb"))

    • @TokyoEdTech
      @TokyoEdTech  Год назад +1

      That is awesome! Is it a TI calculator? I have one but haven't had much time to play with it.

    • @userrrr32
      @userrrr32 Год назад

      @@TokyoEdTech I used to have a it calc but the calc i use is a casio fx iii

    • @userrrr32
      @userrrr32 Год назад +1

      @@TokyoEdTech IT calculators are the best to play around with and mod

    • @userrrr32
      @userrrr32 Год назад

      btw the script is not 100% done. it works but it looks messy on the terminal

  • @King_Dozlex
    @King_Dozlex 2 года назад

    is there an addition for names. ?

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      Sorry, not sure exactly what you mean. Could you rephrase that?

  • @colwarsstudiobrickfilmandm8580
    @colwarsstudiobrickfilmandm8580 3 года назад +1

    The title sounds like a c64 video!

  • @cintra4867
    @cintra4867 4 года назад

    TypeError: load() takes exactly 1 positional argument (2 given)
    what does this mean?

    • @TokyoEdTech
      @TokyoEdTech  4 года назад

      Can you share the code you are using? ALL OF IT.

    • @cintra4867
      @cintra4867 4 года назад

      @@TokyoEdTech No its actually personal

    • @TokyoEdTech
      @TokyoEdTech  4 года назад

      Fine. Then you'll have to figure it out yourself.

  • @voltifer5267
    @voltifer5267 4 года назад

    Nice video thanks!

  • @oliverlacika4994
    @oliverlacika4994 2 года назад

    it gives me this error: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (I know I am annoying but I really need it)

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      You have some weird character - for example, Japanese, Korean, etc at the start of your program. Delete the first line completely and retype it.

  • @jatinkumar4410
    @jatinkumar4410 4 года назад

    Thank You

  • @peroquecoincidencia9991
    @peroquecoincidencia9991 4 года назад

    very useful thanks

  • @sky-lu2fb
    @sky-lu2fb 3 года назад

    How come when I type in import pickle, the text is greyed out?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      I don't know. Did you save the file? It might be greyed out if you haven't used the module as well. Depends on your editor.

    • @sky-lu2fb
      @sky-lu2fb 3 года назад

      @@TokyoEdTech Thanks for the reply! What does "TERM environment variable not set?"

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Not sure - are you using your computer or a website?

    • @sky-lu2fb
      @sky-lu2fb 3 года назад

      @@TokyoEdTech Pycharm on Macbook

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Check the Pycharm docs or Google "TERM..."

  • @plotb1938
    @plotb1938 3 года назад

    on windows os.system("clr") doesnt work

  • @PSIBoredomOmega
    @PSIBoredomOmega 3 года назад

    Does this work in python 3.8

  • @AshitoshMahajan
    @AshitoshMahajan 4 года назад

    thank you sir

  • @williamostlind5810
    @williamostlind5810 3 года назад

    thank you SO much

  • @adamsonfrankie2909
    @adamsonfrankie2909 5 лет назад

    how do you add things to a list?

    • @tehfilaminer
      @tehfilaminer 5 лет назад

      LIST_NAME.append(#value you wish to input)

  • @randtube401
    @randtube401 4 года назад

    Very helpful

    • @randtube401
      @randtube401 4 года назад

      @@TokyoEdTech After seeing this video, and I found it very helpful, I immediately subscribed to your channel !

  • @programmerrdai
    @programmerrdai 4 года назад +1

    Great content...

    • @programmerrdai
      @programmerrdai 4 года назад +1

      Subscribed and liked the video

    • @programmerrdai
      @programmerrdai 4 года назад +1

      I am currently watching Your play list of python game coding Basic animation....

    • @programmerrdai
      @programmerrdai 4 года назад +1

      Yep it is awesome....
      I finished watching the videos now...
      Now I am looking through your playlists...
      By the way do you know any good laptops for coding?

    • @programmerrdai
      @programmerrdai 4 года назад +1

      Thanks so much...
      I am thinking of buying the thinkpad x1 extreme gen 2...
      Do you have any comments about the laptop....

    • @programmerrdai
      @programmerrdai 4 года назад +1

      @@TokyoEdTech Thanks so much...
      I am thinking of buying the thinkpad x1 extreme gen 2...
      Do you have any comments about the laptop....

  • @egemenedits1383
    @egemenedits1383 Год назад

    Where does it save the file (lists)

    • @TokyoEdTech
      @TokyoEdTech  Год назад

      Usually in the same folder as the python file.

    • @egemenedits1383
      @egemenedits1383 Год назад

      @@TokyoEdTech do you have discord i want to ask some questions :D

  • @syldrus3502
    @syldrus3502 5 лет назад

    I'm trying to make it save security questions. How would I make an IF statement that says "if securityquestionasked = securityquestionone.dat" in a way? Its like a login but I dont know how to make it compare to the .dat file that saves the questions answers. would "if securityquestionasked = pickle.read(securityquestion1.dat) " work? Hope you can help. Thanks in advance

    • @syldrus3502
      @syldrus3502 5 лет назад

      Currently this is my code for the login and setup mechanism.
      "
      def startsetupandlogin():
      runew = input("[+] \"Setup\" to setup! (Type \"Manage\" to login to an existing account)
      ")
      if runew == "Setup":
      print("[+] Lets get started! These are memorable security questions!")
      q1 = input("[+] What school did you or are going to ? : ")
      pickle.dump(q1, open("q1.dat", "wb"))
      q2 = input("[+] Where were you born ? : ")
      pickle.dump(q2, open("q2.dat", "wb"))
      q3 = input("[+] Lucky number ? : ")
      pickle.dump(q3, open("q3.dat", "wb"))
      q4 = input("[+] Favourite subject ? : ")
      pickle.dump(q4, open("q4.dat", "wb"))
      print("You're all setup!")
      if runew == "Manage":
      "

    • @syldrus3502
      @syldrus3502 5 лет назад

      Sorry, one more question. How can I save the dat file in a different location then where the original python file is. I dont want the answers right next to the login. Thanks, sorry for bothering you with so many questions.

    • @syldrus3502
      @syldrus3502 5 лет назад

      Hey, sorry to ask another question but how do I save the .dat files to a different location than saving right next to the python file.

  • @animationsbelike
    @animationsbelike 2 года назад +1

    Niice! :D

  • @aaravkhatri1303
    @aaravkhatri1303 6 лет назад

    Awsome!

  • @pedromazariegos6536
    @pedromazariegos6536 3 года назад +1

    Pickle Rick!

  • @adammccamon49
    @adammccamon49 4 года назад

    Ok, so my first question is: when you save something does it actually save into a folder on your computer?
    For school i have this project where ive basically got to have my python code choose a song at random from an external file and the player has to fill in the missing words from the artist and songs name. The way ive tried doing it is by first making a screen with turtle and then using turtle write like a basic layout of how i want one of the songs to look i then copied the code and changed the variables and song name and artist and tried to save both the variables (song1 and song2) in a list but it came up with the error:
    Traceback (most recent call last):
    File "C:/Users/tipsy/PycharmProjects/Saving Files Practice/Saving Files Practice.py", line 47, in
    pickle.dump(songs, open("songs.dat", "wb"))
    TypeError: cannot pickle '_tkinter.tkapp' object
    which basically says that i cant save things ive made in turtle im guessing
    so what im wondering is: how would i be able to save them? 7
    heres my code:
    #Saving files practice
    #Python Version 3.8
    import turtle
    import os
    import pickle
    #Screem
    screen = turtle.Screen()
    screen.bgcolor("black")
    screen.title("Main Screen")
    #Border
    border = turtle.Turtle()
    border.speed(0)
    border.penup()
    border.color("white")
    border.setposition(-300, -300)
    border.pensize(3)
    border.pendown()
    for side in range(4):
    border.fd(600)
    border.lt(90)
    border.hideturtle()
    song1 = turtle.Turtle()
    song1.color("white")
    song1.penup()
    song1.speed(0)
    song1.setposition(-200, -200)
    song1string = ("_ost malone _n god")
    song1.write(song1string, False, align="Left", font = ("Arial", "14", "normal"))
    song1.hideturtle()
    song2 = turtle.Turtle()
    song2.color("white")
    song2.penup()
    song2.speed(0)
    song2.setposition(-200, -200)
    song2string = ("_minem _ap _od")
    song2.write(song2string, False, align="Left", font = ("Arial", "14", "normal"))
    song2.hideturtle()
    songs = [song1, song2]
    pickle.dump(songs, open("songs.dat", "wb"))
    screen.mainloop()
    thanks

    • @adammccamon49
      @adammccamon49 4 года назад

      @@TokyoEdTech ok ill give it a go thanks, whilst im here i was just wondering if it was better to use pygame instead of turtle? And im not sure if this is easy for you to answer but ive seen videos of people making code and theyll quite frequently put self in brackets like this (self) what exactly does it mean?

    • @adammccamon49
      @adammccamon49 4 года назад

      thank you it worked. is pygame better than turtle? and can i use the random module to randomly pick a song from the songs list?

    • @adammccamon49
      @adammccamon49 4 года назад

      @@TokyoEdTech ive managed to figure out the random part but i only want it to show 1 song at a time so how i would i hide the song1string and song2string after ive saved them so then i can just randomly choose one of them so it only shows one song at a time

    • @adammccamon49
      @adammccamon49 4 года назад

      @@TokyoEdTech could you put an example for me

    • @adammccamon49
      @adammccamon49 4 года назад

      @@TokyoEdTech basiclally where im at is: its letting me save the file but when i look in the file its just both the songs text overlapping so i cant see how the random would work

  • @naveedfanspeed9099
    @naveedfanspeed9099 4 года назад

    hey, is there a way to clear the saved file?

    • @naveedfanspeed9099
      @naveedfanspeed9099 4 года назад

      @@TokyoEdTech haha oh yeah of course! thank you

    • @carmel3121
      @carmel3121 4 года назад

      How come I don’t see his replies

    • @TokyoEdTech
      @TokyoEdTech  4 года назад

      I switched my account to a "brand account" a week ago - it deleted all of my replies...five YEARS of replying to every message...not happy.

  • @tautvydas4546
    @tautvydas4546 3 года назад

    I want to do a high score thing with the snake game. I want that it would save the highscore in data and use it further, but I tried with you method and it did not work. Maybe you could to a tutorial. PS: I am doing everything not in pygame, but in simple turtle.

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Sorry, I can't make it any simpler than I did in this tutorial.

    • @tautvydas4546
      @tautvydas4546 3 года назад +1

      @@TokyoEdTech Sorry for bothering you earlier, I found out that I was using the wrong variable. Everything is now perfect. Thank you for your help. Keep your work up!

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Glad you got it sorted!

  • @oliverlacika4994
    @oliverlacika4994 2 года назад

    does this work cross sessions?

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      Yep - that's the whole purpose of it.

    • @oliverlacika4994
      @oliverlacika4994 2 года назад

      Does it work on python 3.8?
      because when I try to load it in another session then it says: no such file or directory names.dat (errno 2)

  • @angryphoenix2946
    @angryphoenix2946 5 лет назад

    I have a question. Why did you have to type in os.system("clear")?

    • @theschinken
      @theschinken 5 лет назад

      Or simpler it looks better

  • @barara8794
    @barara8794 3 года назад

    May i ask where it will save the data?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      If you don't specify, it will save in the same folder as the .py file.

    • @barara8794
      @barara8794 3 года назад

      @@TokyoEdTech Thanks a lot.

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      @@barara8794 You're welcome.

  • @cap.blue-97sama99
    @cap.blue-97sama99 6 лет назад

    thanks

  • @amalmenon6398
    @amalmenon6398 4 года назад

    when i used this ...an access error popped up

  • @jakubnowak7091
    @jakubnowak7091 4 года назад

    "Since there are no effective ways to verify the pickle
    stream being unpickled, it is possible to provide malicious shell code
    as input, causing remote code execution. The most common attack scenario
    leading to this would be to trust raw pickle data received over the network" json is much better, funny thing I'm saving my variables using import and open functions (i have to convert the variables to str so its kinda stiupid i guess :D)

    • @TokyoEdTech
      @TokyoEdTech  4 года назад

      For sure - but assuming you are making a program for just yourself to use, the chances are extremely remote.

  • @Dopeboyz789
    @Dopeboyz789 5 лет назад

    Will this work if i save the output or save the display

    • @Dopeboyz789
      @Dopeboyz789 5 лет назад

      @@TokyoEdTech it works but i only get the last row and last values. Is there a way to get all rows and values

    • @Dopeboyz789
      @Dopeboyz789 5 лет назад

      @@TokyoEdTech for idx,values_a in enumerate(a):
      df= []
      for values_b in b: df.append(list(set(values_a) & set(values_b)))
      print("{} : {}".format(idx,df))

    • @Dopeboyz789
      @Dopeboyz789 5 лет назад

      @@TokyoEdTech ok give me a sec

    • @Dopeboyz789
      @Dopeboyz789 5 лет назад

      @@TokyoEdTech a=[[9, 15, 25],[4, 14, 18, 25],[11, 12, 24, 25],[4, 8, 9, 26]]
      b=[[2, 4, 7, 13, 14],[3, 5, 8, 13, 14],[6, 9, 10, 13, 14],[5, 6, 7, 13, 15],[3, 4, 9, 13, 15],[2, 8, 12, 13, 15],[4, 6, 8, 14, 15],[2, 5, 9, 14, 15]]
      for idx,values_a in enumerate(a): df = []
      for values_b in b: df.append(list(set(values_a) & set(values_b)))
      print("{} : {}".format(idx,df))
      Basically i would like to match all number from a to b . The loop function work but it will only display all rows and values . Is there a way to do this without using the loop. Maybe list comprehension would work?

    • @Dopeboyz789
      @Dopeboyz789 5 лет назад

      @@TokyoEdTech both

  • @reold
    @reold 4 года назад

    ```
    os.system('clear')
    ```
    Doesn't work for me!

    • @reold
      @reold 4 года назад

      @deadninja Am a ML developer now! That message is old. But thanks!
      Edit: meaning I already know all os commands now.

    • @reold
      @reold 4 года назад

      @deadninja Thanks!

    • @a-bison
      @a-bison 3 года назад

      if on windows, you can use os.system('cls'),
      it isn't working on Windows because it is not a python function, it is what the Terminal uses.

  • @fivethreeone2132
    @fivethreeone2132 3 года назад +1

    saved > daved

  • @Karsonthefoxx
    @Karsonthefoxx 3 года назад

    Hey suggestion, you should make a video on how to add images into a regular python script, perhaps with the pillow module?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      Thanks for the suggestion; however, at this point, I'm not really sure what I can do with Pillow that I can't already do with the turtle, tkinter, or pygame modules (except import pngs and resize / rotate.

    • @Karsonthefoxx
      @Karsonthefoxx 3 года назад

      @@TokyoEdTech makes sense

  • @geetsharma5225
    @geetsharma5225 2 года назад

    No such file directory

    • @TokyoEdTech
      @TokyoEdTech  2 года назад

      Check the path and spelling.

  • @redzyfn2011
    @redzyfn2011 4 года назад

    so how do i do this with the snake game high score?

    • @redzyfn2011
      @redzyfn2011 4 года назад

      Christian Thompson yeah, i’m just having trouble with what to write in the spots. (This is my first day trying programming so i’m sorry if i’m a bit slow with it).

  • @Karsonthefoxx
    @Karsonthefoxx 3 года назад

    Ok, but say I want to store the pickled data for the next time I ran the data... then what?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад +1

      The whole video is about exactly that - you use pickle.dump to save data, and pickle.load to load the data.

    • @Karsonthefoxx
      @Karsonthefoxx 3 года назад

      @@TokyoEdTech ok , dumb question... more accurately can I use this to send values to other programs?

    • @TokyoEdTech
      @TokyoEdTech  3 года назад +1

      As long as both programs can access and read the same file, then yes it should work.

    • @Karsonthefoxx
      @Karsonthefoxx 3 года назад

      @@TokyoEdTech so it should work with two python scripts? When I try to run it i get this Traceback (most recent call last):
      File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in
      start(fakepyfile,mainpyfile)
      File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
      exec(open(mainpyfile).read(), __main__.__dict__)
      File "", line 2, in
      FileNotFoundError: [Errno 2] No such file or directory: 'hello.py'
      [Program finished]
      Parent script
      import pickle
      a = "hello"
      pickle.dump(a, open('hello.py', 'wb'))
      Child script
      import pickle
      h = pickle.load(open('hello.py', 'rb'))
      I made this as a test

    • @TokyoEdTech
      @TokyoEdTech  3 года назад

      It should - buy you'd have to test it out.

  • @endershteker90
    @endershteker90 3 года назад

    Thanks