Module | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Module

how to create our own module and import in our script like import my_script #where my_script will be one more my own py script file is it possible

20th Feb 2018, 3:25 AM
Pradeep Vc
Pradeep Vc - avatar
5 Answers
+ 4
You can't with the code playground; in a folder or something (on a computer, for example), you can make one file with functions and constants in it, then type "import name_of_module" in the file to import it, where "name_of_module" is the name of the file with functions and constants.
20th Feb 2018, 3:52 AM
LunarCoffee
LunarCoffee - avatar
+ 2
tnx, I was asking for python interpreter pc only, where shld I keep the file and what is the extension
20th Feb 2018, 4:18 AM
Pradeep Vc
Pradeep Vc - avatar
+ 1
same folder as the project and extension .py
20th Feb 2018, 8:37 AM
Markus Kaleton
Markus Kaleton - avatar
+ 1
On code playground? You can’t. However, on PC you can. Just create a new folder then make a new file and add some functions(e.g. def show(data): print(data) ) then save it as a .py file. Now you can create a new .py file and type "import name_of_file" now you can use the function in that module. Example: Module_File.py: def show(data): print(data) New_File.py: import Module_File Module_File.show("Hello World!") OUTPUT: Hello World!
20th Feb 2018, 1:25 PM
RuthlessDust
RuthlessDust - avatar
+ 1
tnx Markus and ruthless
20th Feb 2018, 3:52 PM
Pradeep Vc
Pradeep Vc - avatar