Python newbie here. I'm having problems trying to import and/or use a method from a class that I've created which I created a "/lib" directory for.
Here is my current file tree:
/tokenmgt /lib/myToken.py From the directory:
/tokenmgt I am running the python from the command line in this directory. I want to use the "create" method defined in my class "TokenMgr":
class TokenMgr(): """Model a Token Manager""" def __init__(self): pass def create(self, privkey, email): """<REST OF CODE HERE>""" I'm getting these errors:
Type "help", "copyright", "credits" or "license" for more information. >>> import lib.myToken >>> from lib.myToken import create Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name 'create' from 'lib.myToken' (C:\Users\FOO\Desktop\MyWork\dev\lib\myToken.py) Do I need to also import the class name ("TokenMgr" defined in the .py script? I'm confused how to do this properly. Thanks
import myToken.TokenMgrgranted the other file you want to make use of this method is within the same directory level.import myToken.TokenMgr as tokenMethodtokenMethod can be anything you want and then call thecreatelike so:tokenMethod.create().