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.

8th Jul 2017, 2:26 PM
sandhya
sandhya - avatar
2 Réponses
8th Jul 2017, 2:31 PM
visph
visph - avatar
+ 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.
8th Jul 2017, 2:38 PM
Sapphire