Let’s say I have a python package like this :
my-python-package/
__init__.py
app.py
__init__.py
is empty and it is just for telling python that we have a python package. And app.py
is this :
FAVORITE_COLORS = ['blue', 'purple']
Here is the idea, I want to append another color to this list using python shell. I started from changing directory, so we can simply import app.py :
>>> import os
>>> os.chdir('C:UsersJavadDesktopmy-python-package')
>>> os.getcwd()
'C:\Users\Javad\Desktop\my-python-package'
After that, We do our general task :
>>> import app
>>> app.FAVORITE_COLORS
['blue', 'purple']
>>> app.FAVORITE_COLORS.append('red')
>>> app.FAVORITE_COLORS
['blue', 'purple', 'red']
According to what we see in python shell, ‘red’ successfully appended to the app.FAVORITE_COLORS. But when you open app.py, it’s exactly the same before modify :
FAVORITE_COLORS = ['blue', 'purple']
I would be appreciated if someone explains what’s happened. Thank you.
Aucun commentaire:
Enregistrer un commentaire