# Can't save Python classes : it.wall.Wall and it.ball.Ball objects

**URL:** <https://forum.itascainternational.com/t/cant-save-python-classes-it-wall-wall-and-it-ball-ball-objects/571>\
**Category:** General\
**Tags:** python\
**Created:** [May 28, 2022, 4:12pm UTC](https://forum.itascainternational.com/t/cant-save-python-classes-it-wall-wall-and-it-ball-ball-objects/571 "2022-05-28T16:12:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ppk](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@ppk](https://forum.itascainternational.com/u/ppk)\
**Post date:** [May 28, 2022, 4:12pm UTC](https://forum.itascainternational.com/t/cant-save-python-classes-it-wall-wall-and-it-ball-ball-objects/571/1 "2022-05-28T16:12:09Z")

</div>

I tired to save ball and wall objects into the PFC3D save file but failed

```auto
get_ipython().magic('reset -sf') #command to initialize iPython environment

import itasca as it

it.command("python-reset-state false") #the model new command will not affect python environment

it.command("""
model new
model domain extent -0.1 0.1
ball create id 1 position (0,0,0) radius 0.01
wall generate id 1 name 'test' polygon (-0.1, -0.1, -0.05), (0.1, -0.1, -0.05), (0.1, 0.1, -0.05), (-0.1, 0.1, -0.05)
""")

wall_id_1 = it.wall.find(1)
ball_id_1 = it.ball.find(1)

it.add_save_variable("wall_id_1")
it.add_save_variable("ball_id_1")

it.get_save_variables()

it.command(f"""
model save 'test_220529.sav'
""")

```

The error message is

```auto
ValueError: Error while trying to save the Python object: wall_id_1. Either this object itself or something contained in the object cannot be serialized. Itasca uses the dill Python module for serialization. A description of what can and cannot be serialized can be found here: https://pypi.python.org/pypi/dill The error message follows:

Internal error while calling Python function pickle_dump from module _itasca_internal. The error message was "<class 'TypeError'>"
"can't pickle itasca.wall.Wall objects"
  File "C:\Program Files\Itasca\PFC700\exe64\python36\lib\_itasca_internal.py", line 28, in pickle_dump
    _pickler.dump(obj)

  File "C:\Program Files\Itasca\PFC700\exe64\python36\lib\pickle.py", line 409, in dump
    self.save(obj)

  File "C:\Program Files\Itasca\PFC700\exe64\python36\lib\pickle.py", line 496, in save
    rv = reduce(self.proto)

    While processing line 0 of source Python interpreter.

```

How can I save it?

---

<div class="post-metadata">

**Author:** ![Theophile](https://yyz1.discourse-cdn.com/flex031/user_avatar/forum.itascainternational.com/theophile/32/299_2.png) [@Theophile](https://forum.itascainternational.com/u/Theophile)\
**Post date:** [May 31, 2022, 8:20am UTC](https://forum.itascainternational.com/t/cant-save-python-classes-it-wall-wall-and-it-ball-ball-objects/571/2 "2022-05-31T08:20:19Z")

</div>

> [@ppk](#):
>
> `https://pypi.python.org/pypi/dill`

Hi @ppk!

As the error message details, Itasca softwares use the `dill` library to serialize objects.  
Citing the documentation:

> dill extends python’s pickle module for serializing and de-serializing python objects to the majority of the **built-in** python types

I guess that Python objects are APIs to native Itasca objects (C++?) and no pure Python objects, I am afraid you cannot save these.  
The workaround would be to store your objects through their IDs:

```python
wall_1 = 1
it.add_save_variable("wall_id_1")

```

Then, restore them in your later sessions:

```python
wall_id_1 = it.wall.find(wall_1)

```

NB : [serialization](https://en.wikipedia.org/wiki/Serialization) is the process of storing high-level data into simpler, transmittable datastructures, such as bytes [or byte code in Python](https://docs.python.org/3/library/pickle.html).
