dcl160-2024-jul-08

所属分类:其他
开发工具:Jupyter Notebook
文件大小:0KB
下载次数:0
上传日期:2024-07-09 12:19:05
上 传 者sh-1993
说明:  DCL-160:Python编程
(DCL-160: Python Programming)

文件列表:
module01/
module02/
module03/
module04/
LICENSE
module10-figure01.png
pip-module-fig01.png
pip-module-fig02.png
pip-module-fig03.png

# DCL-160: Python Programming These projects are created as part of the following training: DCL-160 "Python Programming" Please follow the link for the complete training catalog: https://www.deepcloudlabs.com/resources # Module 10 - Modules and Packages Python'da bir paket oluturmak iin bir dizin yaratmanz yeterli olacaktr: ![Installation folder](https://github.com/deepcloudlabs/dcl160-2024-jul-08/blob/master/module10-figure01.png?raw=true "package directory content") Bu dizin yaps iinde **`__init__.py`** dosyas modül yüklenirken bir kere altrlr ve modülle ilgili balang ilemleri gerekletirilir: ```python print("deepcloudlabs module is loaded!") # all initialization code goes here from deepcloudlabs.dictionary import lines with open("deepcloudlabs/dictionary-tur.txt", "r") as the_file: for line in the_file.readlines(): lines.append(line.strip()) ``` Bylelikle modül iindeki **dictionary.py** dosyas iinde tekrar tekrar dosyann yüklenmesine gerek olmaz: ```python lines = [] def get_word(index): return lines[index] ``` Burada **lines** listesi her zaman modül yüklenirken szlük dosyas okunarak doldurulur. Modülün kullanmna ilikin aadaki rneklere gz atalm: ```python from deepcloudlabs.utils import lost_numbers as nums, is_even as cift_mi print(nums) print(cift_mi(42)) import deepcloudlabs.hr print(dir(deepcloudlabs)) example = { "identity": "9876543210", "fullname": "kate austen" } jack = deepcloudlabs.hr.Employee("12345678910", "jack bauer") kate = deepcloudlabs.hr.Employee(**example) print(jack.identity, jack.fullname) print(kate.identity, kate.fullname) from deepcloudlabs.dictionary import get_word print(get_word(42)) ``` **deepcloudlabs** altndaki **utils.py** paketini yüklemek iin aadaki python satrn yazmanz yeterli olacaktr: ```python from deepcloudlabs.utils import lost_numbers as nums, is_even as cift_mi ``` **deepcloudlabs** altndaki **hr.py** paketini yüklemek iin aadaki python satrn yazmanz yeterli olacaktr: ```python import deepcloudlabs.hr ``` Bu ekilde **Employee** snfndan nesne yaratabilirsiniz: ```python example = { "identity": "9876543210", "fullname": "kate austen" } jack = deepcloudlabs.hr.Employee("12345678910", "jack bauer") kate = deepcloudlabs.hr.Employee(**example) print(jack.identity, jack.fullname) print(kate.identity, kate.fullname) ``` Szlükteki 42. sradaki kelimeye erimek iin ise aadaki kodu yazyoruz: ```python from deepcloudlabs.dictionary import get_word print(get_word(42)) ``` # Python'da PIP Paketi Oluturmak Python'da **pip paketi** oluturmak iin aadaki admlar izleyebilirsiniz: ![paket dizin yaps](https://github.com/deepcloudlabs/dcl160-2024-jul-08/blob/master/pip-module-fig01.png?raw=true "package directory content") ![paket dizin yaps](https://github.com/deepcloudlabs/dcl160-2024-jul-08/blob/master/pip-module-fig03.png?raw=true "package directory content") ![paket dizin yaps](https://github.com/deepcloudlabs/dcl160-2024-jul-08/blob/master/pip-module-fig02.png?raw=true "package directory content") **setup.py** dosyas iinde datm dosyalarn oluturacak Python betii yer alyor: ```python import setuptools with open("README.md", "r") as fh: long_description = fh.read() setuptools.setup( name='dcllottery', version='0.1', scripts=['dcl-lottery'] , author="Binnur Kurt", author_email="info@deepcloudlabs.com", description="Lottery utility package", long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/deepcloudlabs/lottery", packages=setuptools.find_packages(where="src"), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ], package_dir={"": "src"}, python_requires=">=3.6", ) ``` **setup.py** betiini altrabilmek iin iki paketin kurulu olmas gerekiyor: **setuptools** ve **wheel**. Eer kurulu deil iseler aadaki verildii ekilde bu iki paketi kurabilirsiniz: ```bash $ pip install setuptools wheel Collecting setuptools Using cached setuptools-57.4.0-py3-none-any.whl (819 kB) Collecting wheel Using cached wheel-0.36.2-py2.py3-none-any.whl (35 kB) Installing collected packages: wheel, setuptools Successfully installed setuptools-57.4.0 wheel-0.36.2 ``` **setup.py** dosyasn altrarak datm dosylarn oluturabilirsiniz: ```bash $ python setup.py bdist_wheel running bdist_wheel running build running build_py creating build creating build\lib creating build\lib\dcllottery copying src\dcllottery\utils.py -> build\lib\dcllottery copying src\dcllottery\__init__.py -> build\lib\dcllottery running build_scripts creating build\scripts-3.9 copying dcl-lottery -> build\scripts-3.9 installing to build\bdist.win-amd64\wheel running install running install_lib creating build\bdist.win-amd64 creating build\bdist.win-amd64\wheel creating build\bdist.win-amd64\wheel\dcllottery copying build\lib\dcllottery\utils.py -> build\bdist.win-amd64\wheel\.\dcllottery copying build\lib\dcllottery\__init__.py -> build\bdist.win-amd64\wheel\.\dcllottery running install_egg_info running egg_info creating src\dcllottery.egg-info writing src\dcllottery.egg-info\PKG-INFO writing dependency_links to src\dcllottery.egg-info\dependency_links.txt writing top-level names to src\dcllottery.egg-info\top_level.txt writing manifest file 'src\dcllottery.egg-info\SOURCES.txt' reading manifest file 'src\dcllottery.egg-info\SOURCES.txt' adding license file 'LICENSE' writing manifest file 'src\dcllottery.egg-info\SOURCES.txt' Copying src\dcllottery.egg-info to build\bdist.win-amd64\wheel\.\dcllottery-0.1-py3.9.egg-info running install_scripts creating build\bdist.win-amd64\wheel\dcllottery-0.1.data creating build\bdist.win-amd64\wheel\dcllottery-0.1.data\scripts copying build\scripts-3.9\dcl-lottery -> build\bdist.win-amd64\wheel\dcllottery-0.1.data\scripts adding license file "LICENSE" (matched pattern "LICEN[CS]E*") creating build\bdist.win-amd64\wheel\dcllottery-0.1.dist-info\WHEEL creating 'dist\dcllottery-0.1-py3-none-any.whl' and adding 'build\bdist.win-amd64\wheel' to it adding 'dcllottery/__init__.py' adding 'dcllottery/utils.py' adding 'dcllottery-0.1.data/scripts/dcl-lottery' adding 'dcllottery-0.1.dist-info/LICENSE' adding 'dcllottery-0.1.dist-info/METADATA' adding 'dcllottery-0.1.dist-info/WHEEL' adding 'dcllottery-0.1.dist-info/top_level.txt' adding 'dcllottery-0.1.dist-info/RECORD' removing build\bdist.win-amd64\wheel ``` Artk datm dosyalarn https://pypi.org sitesine tayabiliriz: ```bash $ python -m twine upload dist/* Uploading distributions to https://upload.pypi.org/legacy/ Enter your password: *your password* Uploading dcllottery-0.1-py3-none-any.whl 100%|████████████████████████████████████████████████████████████████████| 6.06k/6.06k [00:02<00:00, 2.25kB/s] View at: https://pypi.org/project/dcllottery/0.1/ ``` Artk herhangi bir proje iinden bu pakete ulaabilirsiniz: ```bash $ pip install dcllottery Collecting dcllottery Using cached dcllottery-0.1-py3-none-any.whl (3.0 kB) Installing collected packages: dcllottery Successfully installed dcllottery-0.1 ``` rnek bir kullanm iin aadaki kodu kullanabilirsiniz: ```python import dcllottery.utils as dcl numbers = dcl.get_lottery_numbers(1,60,6) print(numbers) ```

近期下载者

相关文件


收藏者