Mar-21-2024, 06:29 AM
(Mar-21-2024, 01:12 AM)MorningWave Wrote: two.py would have a function receiving a parameter which is a variable set in one.pyCan make a package then can have one import eg
import my_pack
then can access all from my_pack.
.Depends on how your code are,this can tricky and not so easy when new to this.
Example.
myproject/ │ ├── my_pack/ │ ├── __init__.py │ ├── egg.py │ ├── spam.py │ ├── foo.pyegg.py
# Absolute path when import from a other module inside a package from my_pack.spam import spam_var def egg_func(): return f'Variable: <{spam_var}> from spam.py'spam.py
spam_var = 999foo.py
def foo_func(): return 'foo'Here glue it togethere,this make import easy.
__init__.py
from .egg import egg_func from .foo import foo_funcUsage of this package,see that i can access all from
my_pack
.@snippsat ➜ /workspaces/codespaces-blank $ ptpython >>> import my_pack >>> >>> my_pack.foo_func() 'foo' >>> my_pack.egg_func() 'Variable: <999> from spam.py' >>> my_pack.spam.spam_var 999