A full example of making a package.
From Python 3.3+ supports Implicit Namespace Packages that allows to create a package without an
__init__.py file.
This however only applies to empty
__init__.py files.
So i always have one
__init__.py top level,where bind all together and lift sub-modules.
This can be
very import to make it easier for user of your package.
Folder structure:
my_makehtml\ |-- __init__.py checkboxes\ |-- example.py |-- singel_line doc\ |-- web_doc.py
Files:
__init__.py from .checkboxes.example import checkbox_example from .checkboxes.singe_line import singel_line_checkbox from .checkboxes.doc.web_doc import website_checkboxexample
example.py def checkbox_example(): return ''' <!DOCTYPE html> <html> <body> <h1>Show checkboxes:</h1> <form action="/action_page"> <input type="checkbox" name="vehicle1" value="Bike"> I have a bike<br> <input type="checkbox" name="vehicle2" value="Car"> I have a car<br> <input type="checkbox" name="vehicle3" value="Boat" checked> I have a boat<br><br> <input type="submit" value="Submit"> </form> </body> </html>'''
sing_line.py def singel_line_checkbox(name, value): return f'<input type="checkbox" name={name} value={value}> <br>'web_doc.py import webbrowser def website_checkboxexample(): webbrowser.open_new_tab('https://www.w3schools.com/tags/att_input_checked.asp') if __name__ == '__main__': to_website()
Package usage example:
λ ptpython >>> import my_makehtml >>> my_makehtml.singel_line_checkbox('car', 9) '<input type="checkbox" name=car value=9> <br>' >>> print(my_makehtml.checkbox_example()) <!DOCTYPE html> <html> <body> <h1>Show checkboxes:</h1> <form action="/action_page"> <input type="checkbox" name="vehicle1" value="Bike"> I have a bike<br> <input type="checkbox" name="vehicle2" value="Car"> I have a car<br> <input type="checkbox" name="vehicle3" value="Boat" checked> I have a boat<br><br> <input type="submit" value="Submit"> </form> </body> </html> # This open a webpage in browser with checkbox example >>> my_makehtml.website_checkboxexample() >>> exit()Using it with
from in import:
λ ptpython >>> from my_makehtml import singel_line_checkbox >>> singel_line_checkbox('python', 'forum') '<input type="checkbox" name=python value=forum> <br>'More here
Packaging/Modules--Wheel--pip--setup.py--Freeze It's a topic with many layer,so it can be a little confusing
So the road can be
your_code --> make_package --> setup-py --> distribution on PyPi As a example if want to share code with others.