+ 2
How do I make a module?
I want to create a module for python. Advise? Starting point? Can I do it from my phone?
3 Answers
+ 2
Creating a module isn't tough at all! I found it's easier on a computer to get more practice at programming.
I have been using PyDroid and have had issue getting it to work properly. There is a great IDE that is totally free online, at replit.com
Creating your first file, I usually name mine main.py, then make a second file in the same project. You can create a function or a class in that second file, then in the first import it.
As an example, check this out! https://replit.com/@Aliensrnear/calculator-start
That was one of the early things I made. In the middle top right of the screen, you'll see a button that says "Fork". If you click that, it will duplicate the code and put it in YOUR profile so you can play with it! You can see the multiple files and how they are imported into the main.py.
0
Basic modules are just functions :
mymodule.py -
def printThisString(myString) :
print(myString)
def returnthis(this) :
return this
main.py -
import mymodule
printThisString("Hi!")
>> Hi!
# Returning
print(returnthis("Hi!"))
>> Hi!
x = returnthis("Hi!")
print(x)
>> Hi!