0
Can I create my own custom module( if so how to do it) and import it the same way as standard modules?
In c++ we can create our custom header file by saving the file with an extension of "file_name.h" and can include it in our program similar to standard header files. for example: #include"iostream.h" #include"file_name.h" . . . similarly what's the procedure in python to create our own module.
2 Réponses
+ 5
Yes, you can...
https://www.learnpython.org/en/Modules_and_Packages
https://www.programiz.com/JUMP_LINK__&&__python__&&__JUMP_LINK-programming/modules
... and so on (google search 'python custom module') ^^
+ 2
It's actually as easy as ...
Create a new python file (awesome.py)
inside awesome.py lets say we have a function to print how awesome it is, and another function to confirm this.
def status():
print("I'm awesome")
def confirm():
print(True)
save this file, and make a new python file in the same folder.
import awesome as awe
awe.status()
awe.confirm()
#output:
"I'm awesome"
True
Seriously, it's that easy. Of course you can involve classes and more advanced techniques into this, but it really is as simple as stated above.