You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog_files/pysheet.md
+30-1Lines changed: 30 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3879,7 +3879,7 @@ A module can discover whether or not it is running in the main scope by checking
3879
3879
... main()
3880
3880
```
3881
3881
3882
-
For a package, the same effect can be achieved by including a __main__.py module, the contents of which will be executed when the moduleis runwith-m
3882
+
For a package, the same effect can be achieved by including a __main__.py module, the contents of which will be executed when the moduleis runwith-m.
3883
3883
3884
3884
For example we are developing script whichis designed to be usedas module, we should do:
3885
3885
@@ -3907,6 +3907,35 @@ For example we are developing script which is designed to be used as module, we
3907
3907
3. Python files can actas either reusable modules,oras standalone programs.
3908
3908
4.if`__name__== “main”:`is used to execute some code onlyif thefile was run directly,andnot imported.
3909
3909
3910
+
## setup.py
3911
+
3912
+
The setup scriptis the centre ofall activityin building, distributing,and installing modules using the Distutils. The main purpose of the setup scriptis to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing.
3913
+
3914
+
The`setup.py`fileis at the heart of a Python project. It describesall of the metadata about your project. There a quite a few fields you can add to a project to give it a richset of metadata describing the project. However, there are only three required fields: name, version,and packages. The name field must be uniqueif you wish to publish your package on the Python Package Index (PyPI). The version field keeps track of different releases of the project. The packages field describes where you’ve put the Python source code within your project.
3915
+
3916
+
This allows you to easily install Python packages. Often it's enough to write:
3917
+
3918
+
```
3919
+
$ python setup.py install
3920
+
```
3921
+
3922
+
and module will install itself.
3923
+
3924
+
Our initial setup.py will also include information about thelicenseand will re-use theREADME.txtfilefor the long_description field. This will look like:
3925
+
3926
+
```python
3927
+
>>>from distutils.coreimport setup
3928
+
>>> setup(
3929
+
...name='pythonCheatsheet',
3930
+
...version='0.1',
3931
+
...packages=['pipenv',],
3932
+
...license='MIT',
3933
+
...long_description=open('README.txt').read(),
3934
+
... )
3935
+
```
3936
+
3937
+
Find more information visit http://docs.python.org/install/index.html.
3938
+
3910
3939
## Virtual Environment
3911
3940
3912
3941
The use of a Virtual Environmentis to test python codein encapsulated environmentsand to also avoid filling the base Python installationwith libraries we might usefor only one project.