Reputation: 67
I wrote functions that are applyRules(ch), processString(Oldstr) and named it lsystems.py And I put
import lsystems
def main():
inst = applyRules("F")
print(inst)
main()
and saved it as mainfunctioni
However, when I try to run mainfunctioni, it says 'applyRules' is not defined. Doesn't it work because I put import lsystems?
What should I do to work my mainfunctioni through lsystems?
Upvotes: 0
Views: 55
Reputation: 3345
You have to call it with module.function()
format. So in this case, it should be called like as follows:
inst = lsystems.applyRules("F")
You have to access all the methods from your module with the same format. For processString(Oldstr), it should be similar.
test_string = lsystems.processString("Somestring")
Upvotes: 1
Reputation: 53
When you import a module using import <module>
syntax, you need to access the module's contents through its namespace, like so:
import lsystems
def main():
inst = lsystems.applyRules("F")
print(inst)
main()
Alternatively, you can directly import the function from the module:
from lsystems import applyRules
def main():
inst = applyRules("F")
print(inst)
main()
Upvotes: 1