| Line 1: |
Line 1: |
| − | == Install == | + | ====[[Python: Install|Install]]==== |
| | | | |
| − | == Indentation == | + | ==Indentation== |
| | Python is an indented language, so the code indentation matters. A good practice is to indent with 4 spaces (if you mix spaces and tabs the code won't work. | | Python is an indented language, so the code indentation matters. A good practice is to indent with 4 spaces (if you mix spaces and tabs the code won't work. |
| − | == Operators == | + | ==Operators== |
| − | === Arithmetic === | + | ===Arithmetic=== |
| | <nowiki>+ Addition | | <nowiki>+ Addition |
| − | - Substraction | + | - Substraction |
| − | * Multiplication | + | * Multiplication |
| − | / Division | + | / Division |
| − | ** Power | + | ** Power |
| − | % Reminder | + | % Reminder |
| − | // Floor division (Reminder is removed)</nowiki> | + | // Floor division (Reminder is removed)</nowiki> |
| − | === Comparison === | + | ===Comparison=== |
| | <nowiki> | | <nowiki> |
| − | == Equal | + | == Equal |
| − | != Not equal | + | != Not equal |
| − | > Greater | + | > Greater |
| − | >= Greater or equal | + | >= Greater or equal |
| − | < Smaller | + | < Smaller |
| − | <= Smaller or equal | + | <= Smaller or equal |
| − | <> Similar to !=</nowiki> | + | <> Similar to !=</nowiki> |
| − | === Assignment === | + | ===Assignment=== |
| | <nowiki> | | <nowiki> |
| − | = Simple assignment | + | = Simple assignment |
| − | += Add and as | + | += Add and as |
| − | -= Substract and assignment | + | -= Substract and assignment |
| − | *= Multiply and assignment | + | *= Multiply and assignment |
| − | /= Divide and assignment | + | /= Divide and assignment |
| − | %= Modulus and assignment | + | %= Modulus and assignment |
| − | **= Exponent and assignment | + | **= Exponent and assignment |
| − | //= Floor Divisionn and assignment</nowiki> | + | //= Floor Divisionn and assignment</nowiki> |
| | | | |
| − | === Bitwise operators === | + | ===Bitwise operators=== |
| | They perform operations on binary terms. a= 8 → 100; b= 9 → 101; a & b → 100 | | They perform operations on binary terms. a= 8 → 100; b= 9 → 101; a & b → 100 |
| | <nowiki> | | <nowiki> |
| − | $ Binary AND | + | $ Binary AND |
| − | | Binary OR | + | | Binary OR |
| − | ^ Binary XOR | + | ^ Binary XOR |
| − | ~ Binary complement | + | ~ Binary complement |
| − | << Binary left shift | + | << Binary left shift |
| − | >> Binary right shift</nowiki> | + | >> Binary right shift</nowiki> |
| | | | |
| − | === Logic === | + | ===Logic=== |
| | <nowiki> | | <nowiki> |
| − | and | + | and |
| − | or | + | or |
| − | not</nowiki> | + | not</nowiki> |
| | | | |
| − | === Membership operators === | + | ===Membership operators=== |
| | in<br /> | | in<br /> |
| | not in<br /> | | not in<br /> |
| | | | |
| − | == Variables == | + | ==Variables== |
| − | === Numbers === | + | ===Numbers=== |
| − | === String === | + | ===String=== |
| | String assingment:<br /> | | String assingment:<br /> |
| | MyString = 'Hello World' OR MyString = "Hello World"<br /> | | MyString = 'Hello World' OR MyString = "Hello World"<br /> |
| Line 87: |
Line 87: |
| | len(MyString) → returns the lenght of a string | | len(MyString) → returns the lenght of a string |
| | | | |
| − | === Collections === | + | ===Collections=== |
| − | ==== List ==== | + | ====List==== |
| | Collection - allows us to put many values in a single variable. | | Collection - allows us to put many values in a single variable. |
| | Simple variables are not collections. The previous value is overwritten when changed. | | Simple variables are not collections. The previous value is overwritten when changed. |
| − | * A List is made up of list 'constants'. Lists are surrounded by square brackets [] and the constants in the list are separated by commas. ([2,4,6,8]) | + | |
| − | * A List element can be any Python object, even another list | + | *A List is made up of list 'constants'. Lists are surrounded by square brackets [] and the constants in the list are separated by commas. ([2,4,6,8]) |
| − | * A List can be empty | + | *A List element can be any Python object, even another list |
| − | * Lists are mutable (they can be changed) | + | *A List can be empty |
| − | * When len() is used on a list, it counts the number of constants that make up the list. (not the number of characters) | + | *Lists are mutable (they can be changed) |
| − | * Lists can be concatenated using + | + | *When len() is used on a list, it counts the number of constants that make up the list. (not the number of characters) |
| − | * Lists can be sliced | + | *Lists can be concatenated using + |
| − | * List is a unique type that can be checked using type() (result: <type 'list'>) | + | *Lists can be sliced |
| − | * An empty list can be created with list() | + | *List is a unique type that can be checked using type() (result: <type 'list'>) |
| − | * Lists can be tested for contents using in/not in | + | *An empty list can be created with list() |
| − | * List is an ordered sequence | + | *Lists can be tested for contents using in/not in |
| − | * A list can be sorted with .sort(). Sort changes the list permanently. | + | *List is an ordered sequence |
| − | * sorted(list) → Returns a list sorted. | + | *A list can be sorted with .sort(). Sort changes the list permanently. |
| − | * Methods: append, count, extend, index, insert, pop, remove, reverse, sort | + | *sorted(list) → Returns a list sorted. |
| − | * Functions len() - find length, max() - find highest value, min() - find lowest value, sum() - add all values average can be found with sum()/len() | + | *Methods: append, count, extend, index, insert, pop, remove, reverse, sort |
| − | * reversed list: | + | *Functions len() - find length, max() - find highest value, min() - find lowest value, sum() - add all values average can be found with sum()/len() |
| − | ** list.reverse() | + | *reversed list: |
| − | ** list[::-1] | + | **list.reverse() |
| − | ** reversed(list) | + | **list[::-1] |
| | + | **reversed(list) |
| | + | |
| | '''Del''' | | '''Del''' |
| | Removes an item from a list.<br /> | | Removes an item from a list.<br /> |
| | example: a = [1, 2, 3, 4, 5] del a[0] returns [2, 3, 4, 5] | | example: a = [1, 2, 3, 4, 5] del a[0] returns [2, 3, 4, 5] |
| | | | |
| − | ==== Tuple ==== | + | ====Tuple==== |
| | Inmutable, declared by () | | Inmutable, declared by () |
| − | * My_tuple = (3, 2, 1) | + | |
| | + | *My_tuple = (3, 2, 1) |
| | + | |
| | You can iterate trough tuples.<br /> | | You can iterate trough tuples.<br /> |
| | You can also refer to the items of a tuple like in a list.<br /> | | You can also refer to the items of a tuple like in a list.<br /> |
| Line 180: |
Line 184: |
| | </source> | | </source> |
| | | | |
| − | ==== Dictionary ==== | + | ====Dictionary==== |
| | Key - Value pairs. They are called diferent in diferent languages:<br /> | | Key - Value pairs. They are called diferent in diferent languages:<br /> |
| | dictionary[key] = value <br /> | | dictionary[key] = value <br /> |
| | | | |
| − | * Perl → Associative arrays | + | *Perl → Associative arrays |
| − | * Java → Properties, Map or HashMap | + | *Java → Properties, Map or HashMap |
| − | * C# → Property bag | + | *C# → Property bag |
| | + | |
| | <br /> | | <br /> |
| | Declarationn and assigment:<br /> | | Declarationn and assigment:<br /> |
| | There are two posible ways to declare them: | | There are two posible ways to declare them: |
| − | * purse = dict() | + | |
| − | * puse = {} | + | *purse = dict() |
| | + | *puse = {} |
| | <source lang="python"> | | <source lang="python"> |
| | purse = dict() | | purse = dict() |
| Line 206: |
Line 212: |
| | purse.get(name, default_value) | | purse.get(name, default_value) |
| | '''Other methods and functions'''<br /> | | '''Other methods and functions'''<br /> |
| − | * list(purse) → Returns a list of keys. | + | |
| − | * dict.keys() → Returns a list of keys. | + | *list(purse) → Returns a list of keys. |
| − | * dict.values() → Returns a list of values. | + | *dict.keys() → Returns a list of keys. |
| − | * dict.items → Returns a list of tuples ( [(key, value), (key, value)...] ) | + | *dict.values() → Returns a list of values. |
| | + | *dict.items → Returns a list of tuples ( [(key, value), (key, value)...] ) |
| | + | |
| | ''' Word count using files and dictionarys'''<br /> | | ''' Word count using files and dictionarys'''<br /> |
| | <source lang="python"> | | <source lang="python"> |
| Line 231: |
Line 239: |
| | </source> | | </source> |
| | | | |
| − | == Conditional == | + | ==Conditional== |
| − | === if/elif/else === | + | ===if/elif/else=== |
| | <source lang="python"> | | <source lang="python"> |
| | if a < 10: | | if a < 10: |
| Line 242: |
Line 250: |
| | </source> | | </source> |
| | | | |
| − | === try/except/finally === | + | ===try/except/finally=== |
| | <source lang="python"> | | <source lang="python"> |
| | try: | | try: |
| Line 252: |
Line 260: |
| | </source> | | </source> |
| | | | |
| − | == Loops == | + | ==Loops== |
| − | === For === | + | ===For=== |
| | <source lang="python"> | | <source lang="python"> |
| | NumberList = [1, 3, 7, 12, 24] | | NumberList = [1, 3, 7, 12, 24] |
| Line 265: |
Line 273: |
| | </source> | | </source> |
| | | | |
| − | === while === | + | ===while=== |
| | <source lang="python"> | | <source lang="python"> |
| | CtrlNum = 7 | | CtrlNum = 7 |
| Line 273: |
Line 281: |
| | </source> | | </source> |
| | | | |
| − | == Functions == | + | ==Functions== |
| | All arguments in Python are passed by reference, if you change a variable value inside a function it will be changed at the calling function. | | All arguments in Python are passed by reference, if you change a variable value inside a function it will be changed at the calling function. |
| | <source lang="python"> | | <source lang="python"> |
| Line 283: |
Line 291: |
| | print arg | | print arg |
| | </source> | | </source> |
| − | == Regular Expressions == | + | ==Regular Expressions== |
| | <nowiki> | | <nowiki> |
| − | ^ → Matches the beginning of a line
| + | ^ → Matches the beginning of a line |
| − | $ → Matches the end of a line
| + | $ → Matches the end of a line |
| − | . → Matches any character
| + | . → Matches any character |
| − | \s → Matches any whitespace
| + | \s → Matches any whitespace |
| − | \S → Matches any non-whitespace
| + | \S → Matches any non-whitespace |
| − | * → Repeats a character 0 or more times
| + | * → Repeats a character 0 or more times |
| − | *? → Repeats a character 0 or more times (non-greedy)
| + | *? → Repeats a character 0 or more times (non-greedy) |
| − | + → Repeats a character 1 or more times
| + | + → Repeats a character 1 or more times |
| − | +? → Repeats a character 1 or more times (non-greedy)
| + | +? → Repeats a character 1 or more times (non-greedy) |
| − | [aeiou] → Matches a single character in the listed set
| + | [aeiou] → Matches a single character in the listed set |
| − | [^XYZ] → Matches a single character NOT in the listed set
| + | [^XYZ] → Matches a single character NOT in the listed set |
| − | [a-z0-9] → The set of characters can include a range | + | [a-z0-9] → The set of characters can include a range |
| − | ( → Indicates where string extraction is to start
| + | ( → Indicates where string extraction is to start |
| − | ) → Indicates where string extraction is to end</nowiki>
| + | ) → Indicates where string extraction is to end</nowiki> |
| | \ → Escape character | | \ → Escape character |
| − | === Regular Expression Module === | + | ===Regular Expression Module=== |
| | It must be imported at the begining of a program: | | It must be imported at the begining of a program: |
| | <source lang="python"> | | <source lang="python"> |
| | import re | | import re |
| | </source> | | </source> |
| − | * re.search(re_string, string) → similar to find() | + | |
| − | * re.findall(re_string, string) → similar to find, returns a list | + | *re.search(re_string, string) → similar to find() |
| − | * re.match(re_string, string) | + | *re.findall(re_string, string) → similar to find, returns a list |
| | + | *re.match(re_string, string) |
| | | | |
| | <source lang="python"> | | <source lang="python"> |
| Line 317: |
Line 326: |
| | print line | | print line |
| | </source> | | </source> |
| − | == Date == | + | ==Date== |
| − | === Today as string === | + | ===Today as string=== |
| | <source lang="python"> | | <source lang="python"> |
| | import datetime | | import datetime |
| | datetime.date.today().strftime("%B %d, %Y") | | datetime.date.today().strftime("%B %d, %Y") |
| | </source> | | </source> |
| − | === String date to date type === | + | ===String date to date type=== |
| | <source lang="python"> | | <source lang="python"> |
| | from datetime import datetime | | from datetime import datetime |
| Line 330: |
Line 339: |
| | </source> | | </source> |
| | | | |
| − | == Files == | + | ==Files== |
| | '''Counting lines in a file''' | | '''Counting lines in a file''' |
| | <source lang="python"> | | <source lang="python"> |
| Line 371: |
Line 380: |
| | print "\n"+("That was "+fname+".").center(40) | | print "\n"+("That was "+fname+".").center(40) |
| | </source> | | </source> |
| − | === CSV === | + | ===CSV=== |
| | <source lang="python"> | | <source lang="python"> |
| | import csv | | import csv |
| Line 417: |
Line 426: |
| | </source> | | </source> |
| | | | |
| − | == Class == | + | ==Class== |
| | <source lang="python"> | | <source lang="python"> |
| | class MyClass: | | class MyClass: |
| Line 443: |
Line 452: |
| | </source> | | </source> |
| | | | |
| − | * issubclass(sub, sup) | + | *issubclass(sub, sup) |
| − | * isinstance(obj, Class) | + | *isinstance(obj, Class) |
| | | | |
| | '''Generic functionality that can be overriden in own classes'''<br /> | | '''Generic functionality that can be overriden in own classes'''<br /> |
| Line 456: |
Line 465: |
| | '''Hiding attributes''' | | '''Hiding attributes''' |
| | attributes that start with a __ wont be visible to others<br /> | | attributes that start with a __ wont be visible to others<br /> |
| − | == os.system() == | + | ==os.system()== |
| | To execute a Linux command from Python: | | To execute a Linux command from Python: |
| | <source lang="python"> | | <source lang="python"> |
| | os.system(command) → returns exit status | | os.system(command) → returns exit status |
| | </source> | | </source> |
| − | == Database Access == | + | ==Database Access== |
| − | === MySQLdb === | + | ===MySQLdb=== |
| | '''Table creation''' | | '''Table creation''' |
| | <source lang="python"> | | <source lang="python"> |
| Line 520: |
Line 529: |
| | '''Read example''' | | '''Read example''' |
| | Once the query is made you can: | | Once the query is made you can: |
| | + | |
| | *fetchone() | | *fetchone() |
| | *fetchall() | | *fetchall() |
| Line 558: |
Line 568: |
| | db.close() | | db.close() |
| | </source> | | </source> |
| − | === PostgreSQL === | + | ===PostgreSQL=== |
| | Refer to: [https://wiki.python.org/moin/PostgreSQL PostgreSQL] | | Refer to: [https://wiki.python.org/moin/PostgreSQL PostgreSQL] |
| − | === Other === | + | ===Other=== |
| | Refer to: [https://wiki.python.org/moin/DatabaseInterfaces Database Interfaces] | | Refer to: [https://wiki.python.org/moin/DatabaseInterfaces Database Interfaces] |
| | | | |
| − | == ssh tunneling == | + | ==ssh tunneling== |
| | <source lang="python"> | | <source lang="python"> |
| | import subprocess | | import subprocess |
| Line 572: |
Line 582: |
| | </source> | | </source> |
| | | | |
| − | == Multithreading == | + | ==Multithreading== |
| | <source lang="python"> | | <source lang="python"> |
| | #!/usr/bin/python | | #!/usr/bin/python |
| Line 601: |
Line 611: |
| | import threading | | import threading |
| | </source> | | </source> |
| − | == Python GUI Programming == | + | ==Python GUI Programming== |
| | + | |
| | *Tkinter: Tkinter is the Python interface to the Tk GUI toolkit shipped with Python. We would look this option in this tutorial. | | *Tkinter: Tkinter is the Python interface to the Tk GUI toolkit shipped with Python. We would look this option in this tutorial. |
| | *wxPython: This is an open-source Python interface for wxWindows http://wxpython.org. | | *wxPython: This is an open-source Python interface for wxWindows http://wxpython.org. |
| Line 616: |
Line 627: |
| | </source> | | </source> |
| | '''Widgets''' | | '''Widgets''' |
| | + | |
| | *Button The Button widget is used to display buttons in your application. | | *Button The Button widget is used to display buttons in your application. |
| | *Canvas The Canvas widget is used to draw shapes, such as lines, ovals, polygons and rectangles, in your application. | | *Canvas The Canvas widget is used to draw shapes, such as lines, ovals, polygons and rectangles, in your application. |
| Line 637: |
Line 649: |
| | | | |
| | '''Standard attributes''' | | '''Standard attributes''' |
| | + | |
| | *Dimensions | | *Dimensions |
| | *Colors | | *Colors |
| Line 646: |
Line 659: |
| | | | |
| | '''Geometry Management''' | | '''Geometry Management''' |
| | + | |
| | *The pack() Method - This geometry manager organizes widgets in blocks before placing them in the parent widget. | | *The pack() Method - This geometry manager organizes widgets in blocks before placing them in the parent widget. |
| | *The grid() Method - This geometry manager organizes widgets in a table-like structure in the parent widget. | | *The grid() Method - This geometry manager organizes widgets in a table-like structure in the parent widget. |
| Line 652: |
Line 666: |
| | For further reference visit: tutorialspoint.com/python/python_gui_programming.htm | | For further reference visit: tutorialspoint.com/python/python_gui_programming.htm |
| | | | |
| − | == Enable auto complete in python interpreter == | + | ==Enable auto complete in python interpreter== |
| | Create a file in your home directory named: .pythonrc<br /> | | Create a file in your home directory named: .pythonrc<br /> |
| | Content of this file: | | Content of this file: |
| Line 667: |
Line 681: |
| | To test it import a library, write librariname. and hit tab twice | | To test it import a library, write librariname. and hit tab twice |
| | | | |
| − | == Delete *.pyc == | + | ==Delete *.pyc== |
| | find . -name "*.pyc" -exec rm -rf {} \; | | find . -name "*.pyc" -exec rm -rf {} \; |
| | | | |
| − | == format hex == | + | ==format hex== |
| | | | |
| | | | |
| Line 691: |
Line 705: |
| | '0XFF'<br /> | | '0XFF'<br /> |
| | | | |
| − | == Command completion == | + | ==Command completion== |
| | $ nano ~/.pythonrc | | $ nano ~/.pythonrc |
| | | | |
| Line 710: |
Line 724: |
| | export PYTHONSTARTUP=~/.pythonrc</source> | | export PYTHONSTARTUP=~/.pythonrc</source> |
| | | | |
| − | == nose debug == | + | ==nose debug== |
| | nosetests --debug=nose,nose.importer --debug-log=nose_debug <your usual args> | | nosetests --debug=nose,nose.importer --debug-log=nose_debug <your usual args> |
| | | | |
| − | == Publish Python Package == | + | ==Publish Python Package== |
| | Upload a package to pypi. This would make your package available with: | | Upload a package to pypi. This would make your package available with: |
| | pip install mypackage | | pip install mypackage |
| − | === With setup.py === | + | ===With setup.py=== |
| | nano ~/.pypirc | | nano ~/.pypirc |
| | <nowiki>[distutils] | | <nowiki>[distutils] |
| − | index-servers = | + | index-servers = |
| − | pypi
| + | pypi |
| − | pypitest
| + | pypitest |
| − | | + | |
| − | [pypi] | + | [pypi] |
| − | repository=https://upload.pypi.org/legacy/ | + | repository=https://upload.pypi.org/legacy/ |
| − | username=your_username | + | username=your_username |
| − | password=your_password | + | password=your_password |
| − | | + | |
| − | [pypitest] | + | [pypitest] |
| − | repository=https://testpypi.python.org/pypi | + | repository=https://testpypi.python.org/pypi |
| − | username=your_username | + | username=your_username |
| − | password=your_password</nowiki> | + | password=your_password</nowiki> |
| | Adjust .pypirc permissions | | Adjust .pypirc permissions |
| | chmod 600 ~/.pypirc | | chmod 600 ~/.pypirc |
| Line 809: |
Line 823: |
| | nano setup.cfg | | nano setup.cfg |
| | <nowiki>[metadata] | | <nowiki>[metadata] |
| − | description-file = README.md</nowiki> | + | description-file = README.md</nowiki> |
| | | | |
| | nano LICENSE | | nano LICENSE |
| | <nowiki>The MIT License | | <nowiki>The MIT License |
| − | | + | |
| − | SPDX short identifier: MIT | + | SPDX short identifier: MIT |
| − | | + | |
| − | Copyright <YEAR> <COPYRIGHT HOLDER> | + | Copyright <YEAR> <COPYRIGHT HOLDER> |
| − | | + | |
| − | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | + | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| − | | + | |
| − | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | + | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| − | | + | |
| − | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</nowiki> | + | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</nowiki> |
| | Test and upload | | Test and upload |
| | <source lang="bash">python setup.py register -r pypitest | | <source lang="bash">python setup.py register -r pypitest |
| Line 829: |
Line 843: |
| | python setup.py sdist upload -r pypi</source> | | python setup.py sdist upload -r pypi</source> |
| | | | |
| − | === With twine === | + | ===With twine=== |
| | https://packaging.python.org/tutorials/packaging-projects/ | | https://packaging.python.org/tutorials/packaging-projects/ |
| | | | |
| − | == Change PyPi == | + | ==Change PyPi== |
| − | === Using PyPi Local Repository === | + | ===Using PyPi Local Repository=== |
| | nano ~/.pip/pip.conf | | nano ~/.pip/pip.conf |
| | <nowiki>[global] | | <nowiki>[global] |
| − | index-url= http://10.255.0.21/pypi/simple | + | index-url= http://10.255.0.21/pypi/simple |
| − | trusted-host= 10.255.0.21</nowiki> | + | trusted-host= 10.255.0.21</nowiki> |
| | | | |
| − | == Using pip behind proxy == | + | ==Using pip behind proxy== |
| | sudo pip --proxy http://proxy.hell:3128 install requests | | sudo pip --proxy http://proxy.hell:3128 install requests |
| | | | |
| − | == Publish to PyPi == | + | ==Publish to PyPi== |
| | Create the file ~/.pypirc | | Create the file ~/.pypirc |
| | <nowiki>[distutils] | | <nowiki>[distutils] |
| − | index-servers = | + | index-servers = |
| − | pypi
| + | pypi |
| − | pypitest
| + | pypitest |
| − | | + | |
| − | [pypi] | + | [pypi] |
| − | repository=https://pypi.python.org/pypi
| + | repository=https://pypi.python.org/pypi |
| − | username=
| + | username= |
| − | password=
| + | password= |
| − | | + | |
| − | [pypitest] | + | [pypitest] |
| − | repository=https://test.pypi.org/legacy
| + | repository=https://test.pypi.org/legacy |
| − | username=
| + | username= |
| − | password=
| + | password= |
| − | </nowiki> | + | </nowiki> |
| | | | |
| | Test | | Test |
| Line 868: |
Line 882: |
| | python setup.py sdist upload -r pypi | | python setup.py sdist upload -r pypi |
| | | | |
| − | == AWS boto3 EC2 == | + | ==AWS boto3 EC2== |
| − | <source lang="python">
| + | <source lang="python"> |
| | import boto3 | | import boto3 |
| | client = boto3.client('ec2', aws_access_key_id="AKI.............Q", aws_secret_access_key="2..........................s", region_name='us-east-1') | | client = boto3.client('ec2', aws_access_key_id="AKI.............Q", aws_secret_access_key="2..........................s", region_name='us-east-1') |