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
5 Antworten
+ 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.
+ 2
tnx, I was asking for python interpreter pc only,
where shld I keep the file and what is the extension
+ 1
same folder as the project and extension .py
+ 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!
+ 1
tnx Markus and ruthless