| 1 |
## Purpose |
| 2 |
This directory exists to provide examples of how to use jsonpickle to achieve simple goals, such as: |
| 3 |
- Saving instances of a class to a file |
| 4 |
- And more to come! |
| 5 |
|
| 6 |
## Running the code |
| 7 |
### Linux (Ubuntu) |
| 8 |
If you don't have python and/or git installed, install those first: |
| 9 |
```sh |
| 10 |
apt install git python3 python3-dev python3-pip |
| 11 |
``` |
| 12 |
Once you have those installed, start by cloning the repository and entering into the directory (or copying the file locally): |
| 13 |
```sh |
| 14 |
git clone https://github.com/jsonpickle/jsonpickle.git && cd jsonpickle/examples |
| 15 |
``` |
| 16 |
Then, you should install jsonpickle. The preferred method, using a virtual environment (which isolates packages), goes as so: |
| 17 |
```sh |
| 18 |
# DO NOT RUN LINES BEGINNING WITH # |
| 19 |
# Create a virtualenv in the "env" directory. You don't need to run this again. |
| 20 |
python3 -m venv env |
| 21 |
|
| 22 |
# You must activate the virtualenv anytime you open a new shell in order to |
| 23 |
# make the to-be-installed jsonpickle package available. You should run this |
| 24 |
# in the same directory that you ran the previous command in. |
| 25 |
source env/bin/activate |
| 26 |
|
| 27 |
pip install jsonpickle |
| 28 |
python3 save_class_to_file.py |
| 29 |
``` |
| 30 |
If you'd rather install jsonpickle globally though, you can just run this: |
| 31 |
```sh |
| 32 |
pip install jsonpickle |
| 33 |
``` |
| 34 |
Lastly, you can run any example file as long as you have jsonpickle and Python installed! |
| 35 |
```sh |
| 36 |
python3 save_class_to_file.py |
| 37 |
``` |
| 38 |
You can also open the .py file in your favorite text editor, such as VSCode, gedit, or others! |
| 39 |
### Windows |
| 40 |
If you don't have python, pip, and/or git installed, install those first. Instructions are not included here due to their verbosity, but there exist online guides for this! |
| 41 |
Once you have those installed, start by cloning the repository in a terminal (such as cmd prompt) and entering into the directory (or copying the file locally): |
| 42 |
```sh |
| 43 |
git clone https://github.com/jsonpickle/jsonpickle.git |
| 44 |
cd jsonpickle/examples |
| 45 |
``` |
| 46 |
Then, you should install jsonpickle in the same terminal. The preferred method, using a virtual environment (which isolates packages), goes as so: |
| 47 |
```sh |
| 48 |
pip install virtualenv |
| 49 |
|
| 50 |
# DO NOT RUN LINES BEGINNING WITH # |
| 51 |
# Create a virtualenv in the "env" directory. You don't need to run this again. |
| 52 |
virtualenv venv |
| 53 |
|
| 54 |
# You must activate the virtualenv anytime you open a new shell in order to |
| 55 |
# make the to-be-installed jsonpickle package available. You should run this |
| 56 |
# in the same directory that you ran the previous command in. |
| 57 |
.\venv\Scripts\activate |
| 58 |
|
| 59 |
pip install jsonpickle |
| 60 |
python save_class_to_file.py |
| 61 |
``` |
| 62 |
If you'd rather install jsonpickle globally though, you can just run this: |
| 63 |
```sh |
| 64 |
pip install jsonpickle |
| 65 |
``` |
| 66 |
Lastly, you can run any example file as long as you have jsonpickle and Python installed! |
| 67 |
```sh |
| 68 |
python save_class_to_file.py |
| 69 |
``` |
| 70 |
You can also open the .py file in your favorite text editor, such as VSCode, Notepad++, or others! |