Answers for "creating your own python library"

0

how to i make my own python package

# So first, create a file structure following
# this template:
"""
package_name
|-- __init__.py
|-- sayHello.py
"""
# This will be a dummy package
# (Some python code to automatically create this dummy file structure)
import os
os.mkdir("package_name")
open("package_name/__init__.py", "w")
open("package_name/sayHello.py", "w")
# Now we have our file structure
# Im gonna explain what the shit this means
"""
	1. __init__.py
The __init__.py file is the file that will be run when importing the package,
normally people write in it the imports to import the rest
	2. sayHello.py
Will be imported from __init__.py and will contain an init function,
which will, obviously, print "Hello, World!"
"""
# So now we write the following content in the following files:
###### __init__.py
from sayHello import init
# you also can add a bunch of shit
__author__ = "YourName"
__version__ = (0)
# etc..
###### sayHello
def init():
  print("Hello, World!")
# Now we're done!
# you can make a new file named test.py
"""
The file structure becomes this:
test.py
package_name
|-- __init__.py
|-- sayHello.py
"""
# And write this in test.py
###### test.py
import package_name

package_name.init()
# If your python version is not from the dark web
# it should work
# kthxbye
Posted by: Guest on August-31-2021
-1

add your own library to python

python -m site --user-site
Posted by: Guest on November-26-2020

Code answers related to "creating your own python library"

Python Answers by Framework

Browse Popular Code Answers by Language