Please help me figure it out. With a few questions.
Task one:
I have two files: C: \ pytest \ One \ main.py C: \ pytest \ One \ mymodule.py
mymodule.py contains:
class example: def hello(): print('Hello, world!') def fib(n): a = b = 1 for i in range(n - 2): a, b = b, a + b return b main.py contains:
import mymodule mymodule.example.hello() print(mymodule.example.fib(10)) In this case, I imported the entire module. Can I call to import only a class or a function?
from mymodule import example or
from mymodule import hello An error occurs:
ImportError: cannot import name 'fib' Task two: The files are the same, but they are in a different folder. I have two files: C: \ pytest \ One \ main.py C: \ pytest \ Two \ mymodule.py
How to import a file / class or function?
__init__not forgotten? - titov_andreipython? - approximatenumber@staticmethod- gil9red adddefdeclarations of the method