Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

deleted 11 characters in body
Source Link
Pawel Miech
  • 7.9k
  • 4
  • 41
  • 58

This is actually somewhat tricky, assuming we have structure like this:

├── bar
│  ├── __init__.py
│  └── some_bar.py
├── foo
│  ├── __init__.py
│  └── some_foo.py
├── __init__.py
└── something.py

the correct way to get objects from something.py in some_foo.py is by adding:

# foo/some_foo.py
from something import *some_module

and then running some_foo from top level directory as a module, with -m option like so:

python -m foo.some_foo

add some print statements to something.py to test it, if everything goes right you should see some output from something.py after running some_foo. Remember you need to run some_foo from top level, not from foo directory.

This is actually somewhat tricky, assuming we have structure like this:

├── bar
│  ├── __init__.py
│  └── some_bar.py
├── foo
│  ├── __init__.py
│  └── some_foo.py
├── __init__.py
└── something.py

the correct way to get objects from something.py in some_foo.py is by adding:

# foo/some_foo.py
from something import *

and then running some_foo from top level directory as a module, with -m option like so:

python -m foo.some_foo

add some print statements to something.py to test it, if everything goes right you should see some output from something.py after running some_foo. Remember you need to run some_foo from top level, not from foo directory.

This is actually somewhat tricky, assuming we have structure like this:

├── bar
│  ├── __init__.py
│  └── some_bar.py
├── foo
│  ├── __init__.py
│  └── some_foo.py
└── something.py

the correct way to get objects from something.py in some_foo.py is by adding:

# foo/some_foo.py
from something import some_module

and then running some_foo from top level directory as a module, with -m option like so:

python -m foo.some_foo

add some print statements to something.py to test it, if everything goes right you should see some output from something.py after running some_foo. Remember you need to run some_foo from top level, not from foo directory.

Source Link
Pawel Miech
  • 7.9k
  • 4
  • 41
  • 58

This is actually somewhat tricky, assuming we have structure like this:

├── bar
│  ├── __init__.py
│  └── some_bar.py
├── foo
│  ├── __init__.py
│  └── some_foo.py
├── __init__.py
└── something.py

the correct way to get objects from something.py in some_foo.py is by adding:

# foo/some_foo.py
from something import *

and then running some_foo from top level directory as a module, with -m option like so:

python -m foo.some_foo

add some print statements to something.py to test it, if everything goes right you should see some output from something.py after running some_foo. Remember you need to run some_foo from top level, not from foo directory.

lang-py

AltStyle によって変換されたページ (->オリジナル) /