How do I import from a file in the current directory in Python 3? -


in python 2 can create module this:

parent ->module   ->__init__.py (init calls 'from file import classname')     file.py     ->class classname(obj) 

and works. in python 3 can same thing command interpreter , works (edit: worked because in same directory running interpreter). if create __ init __.py , same thing this:

"""__init__.py""" file import classname  """file.py""" class classname(object): ...etc etc 

i importerror: cannot import name 'classname', doesn't see 'file' @ all. import module though can import referencing directly (which don't want it's inconsistent rest of our codebase). gives?

try import way:

from .file import classname 

see here more info on "guido's decision" on imports in python 3 , complete example on how import in python 3.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -