Import and python source file in folders -
i have troubles understanding how python import works.
i forked this repository , going play having troubles understanding how python import
works file in directories.
the directory structure following:
fitbit/ __init__.py gather_keys_cli.py api.py exceptions.py utils.py
as preliminary step need run gather_keys_cli.py
. depends on api.py
, in turn depends on exceptions.py
.
if try run python interpreter works expected. if try run command line (as suggested in documentation) have obtain following exception.
$./fitbit/gather_keys_cli.py key secret traceback (most recent call last): file "./fitbit/gather_keys_cli.py", line 34, in <module> api import fitbitoauthclient file "/users/mariosangiorgio/fitbithacks/python-fitbit/fitbit/api.py", line 9, in <module> fitbit.exceptions import (badresponse, deleteerror, httpbadrequest, importerror: no module named fitbit.exceptions
my understanding when invoke command line base path set folder containing it. @ point, scripts correctly imports oauth client because uses instruction from api import fitbitoauthclient
, not contain reference fitbit directory.
on opposite, api.py
uses instruction import exceptions from fitbit.exceptions import (list_of_classes)
. instruction contains reference fitbit directory , hence got error.
i not familiar python i'd understand pythonic way solve issue. have feeling there wrong going on , found workaround moving gather_keys_cli.py
, changing api import import fitbit.api
. works not sure right way solve issue i'm experiencing.
Comments
Post a Comment