is it the "name" in the setup.py gets to be the name of the module?
so in this instance when i use this module is the code going to be written as "from myfirstmodule import siblings_game enter image description here?
the other modules ive tried creating have nor worked when applied to flask ( the next part of the textbook is to create a webapp) and i am trying to find the root of the priblem. idk if im not importing the right name.
CodePudding user response:
Start at the start. All that's needed to write a module in Python is naming a file like my_mod.py
:
print('Hello')
Now this code will execute the module (once):
import my_mod
If you have anything named in your module, it can be referenced on the module, or imported directly, like this other my_mod.py
:
def fun():
...
ten = 10
Now this works:
import my_mod
my_mod.fun()
from my_mod import ten
print(ten)
Once you're comfortable with that, you can put the module in an appropriately named folder, add an __init__.py
and you have the beginnings of a package. The package can be provided with a setup.py
and that allows you to specify more relevant metadata about the package, like what its requirements are, what platform it is for, etc.
And once you have your package, you can turn that into a wheel (.whl) file, or publish it on a service like PyPI and use it in any other application, by installing it. That can be a web application, or any other type of application.
CodePudding user response:
The name
attribute is the name of your package. It is the identifier that you or someone else will have to import in order to use its functionality, just like you say:
import myfirstpackage
from myfirstpackage import myfirstfunction
If your package is not correctly imported, chances are that Python can find it from your working directory, or that your "package" isn't a package at all! (Have you added an __init__.py
file to myfirstpackage/
?)
Other than that, you may have to repost a question showing exactly what you are doing.