I have a python file in the location ‘lib/lib_add_participant.py’.And I declared a class in the file.
Now I want to call the class functions from the file call_participant.py.
I tried this code from lib/lib_add_participant.py import LibAddParticipant
Its not worked.Please correct me(I am coming from Ruby).
If your file structure is as follows:
In this case, your
__init__.pyfiles can be empty, if you like (or they can define any number of things – see this fine answer from Alex Martelli for more details.then you can add it by using
However, if
call_participant.pyis your end script, then this tactic will not work, because you “can’t do a relative import in a non-package”, as the interpreter will tell you. In that case, your best bet (in my opinion, at least) is to makelibinto a package in your python path (either in your site-packages directory, or in a path referred to by yourpythonpathenvironment variable).