Skip to content Skip to sidebar Skip to footer

How To Use Class Methods From Another .py File Both Files In Same Package And When Both Are In Different Folders?

Case1: Following is the file structure all are in same folder: `Folder1 |__init__.py |gnewsclient.py |test.py |utils.py` 1)Content of __init__.py `from .gnewscli

Solution 1:

Content of gnewsclient.py

classbaby():
    defmethod(self):
        print'Method call'

Content of test.py

from gnewsclient import baby # from file_name.py import class_name

b = baby()
b.method()

python test.py

Output

Method call

Post a Comment for "How To Use Class Methods From Another .py File Both Files In Same Package And When Both Are In Different Folders?"