- 1
Folders.
Is it possible for me to create a function, method or anything in one folder. And call it in another one? If so how?
4 Réponses
+ 1
You can import module, and modules are simple files/folder in Python...
Say you have a main.py file and another mylib.py in same directory, with the definition of a myfunc() function, you can import it by putting this in main.py:
from mylib import myfunc
You obviously can import the whole file:
import mylib
And then access to the function trough dot notation:
mylib.myfunc()
Instead of just:
myfunc()
... in the first case ^^
Now, say you have a subfolder in same directory as main.py, called 'mypackage', in which you have different *.py files, you can say to Python that's this folder is a package of modules, just by putting an empty __init__.py in the subfolder, and then import anything from it by:
import mypackage.filename_without_py_ext
from mypackage.another_module import some_specific_func, some_specific_var
0
in c# :
you can decleare a class and decleare your methods inside this class, after that you can use this class inside other programs and call its methods wherever you want.
0
please in python
- 1
thanks