Folders. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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?

11th Jan 2018, 8:01 PM
Smart
4 Answers
+ 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
12th Jan 2018, 6:14 AM
visph
visph - avatar
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.
11th Jan 2018, 8:17 PM
Mojtaba Kangari
Mojtaba Kangari - avatar
0
please in python
12th Jan 2018, 5:06 AM
Smart
- 1
thanks
12th Jan 2018, 7:13 PM
Smart