Would I be able to convert these files:
### one.py ###
print("one")
### two.py ###
print("two")
to a Python class so then say I want to import one.py
, I would be able to do:
importFile(MyClass.one)
or something like that?
Would I be able to convert these files:
### one.py ###
print("one")
### two.py ###
print("two")
to a Python class so then say I want to import one.py
, I would be able to do:
importFile(MyClass.one)
or something like that?
You can do this by putting those statements into a class or a method and them importing the file. This is what one.py
would look like if you wanted to make it into a method and then import it:
def print_one():
print("one")
def method_one():
pass
def method_two():
print("In method 2!")
>>> import one
>>> one.print_one()
>>> import two
>>> two.method_one() # does nothing
>>> two.method_two()
You can do other more sophisticated things with Python packages by structuring your project and using things like $PYTHONPATH
(documentation).