0

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?

2 Answers 2

1

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")
Sign up to request clarification or add additional context in comments.

Comments

1

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.