3
How to store and read an item in a file (Python 3, works with 2)
AllAwesome497 (80)

Setup

1) Simply add import ast to the top of your file
2) Make a new .txt file to store data in. (If you wan't that file to be hid to others, name the file .env


Read a file

with open('userLib.txt', 'r') as f: #If the file is a `.env` file put `.env` in the first string
            <item> = ast.literal_eval(f.read())

Write to a file

with open('<File name and extension>', 'w') as f: #If the file is a `.env` file put `.env` in the first string
     i.write(str(<Item name>))
You are viewing a single comment. View All
1
OathOfCode (2)

You have saved my life