User Tools

Site Tools


software:python

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
software:python [2020/12/27 04:01] – [Plotly] superwizardsoftware:python [2024/08/03 02:18] (current) – [Python install] superwizard
Line 2: Line 2:
  
 ------------------------------------------------------------------------------------------------------------------------------------------------\\ ------------------------------------------------------------------------------------------------------------------------------------------------\\
 +
 +====== Python install ======
 +
 +<WRAP center round box >
 +2024-08-02
 +
 +    python -m pip install pandas
 +
 +But when you use python -m pip with python being the specific interpreter you want to use, all of the above ambiguity is gone. If I say python3.8 -m pip then I know pip will be using and installing for my Python 3.8 interpreter (same goes for if I had said python3.7).
 +And if you're on Windows there is an added benefit to using python -m pip as it lets pip update itself. Basically because pip.exe is considered running when you do pip install --upgrade pip, Windows won't let you overwrite pip.exe. But if you do python -m pip install --upgrade pip you avoid that issue as it's python.exe that's running, not pip.exe.
 +
 +From <https://snarky.ca/why-you-should-use-python-m-pip/> 
 +
 +
 +</WRAP>
 +
 +====== Wireshark tcpdump to neo4j plot ======
 +
  
 <WRAP center round box > <WRAP center round box >
Line 531: Line 549:
 From <https://plot.ly/python/axes/>  From <https://plot.ly/python/axes/> 
  
 +</WRAP>
  
 +====== Regular Expression ======
 +
 +
 +<WRAP center round box >
  
 2019-05-29 2019-05-29
Line 555: Line 578:
  
 From <https://www.regular-expressions.info/regexmagic.html>  From <https://www.regular-expressions.info/regexmagic.html> 
- 
- 
- 
- 
  
 </WRAP> </WRAP>
  
-====== Plotly ======+====== Split the string at the last occurrence of sep ======
  
 <WRAP center round box > <WRAP center round box >
Line 572: Line 591:
  
 From <https://docs.python.org/3/library/stdtypes.html#string-methods>  From <https://docs.python.org/3/library/stdtypes.html#string-methods> 
 +</WRAP>
  
 +====== The built-in os module has a number of useful functions ======
 +
 +<WRAP center round box >
 The built-in os module has a number of useful functions that can be used to list directory contents and filter the results. To get a list of all the files and folders in a particular directory in the filesystem, use os.listdir() in legacy versions of Python or os.scandir() in Python 3.x. os.scandir() is the preferred method to use if you also want to get file and directory properties such as file size and modification date. The built-in os module has a number of useful functions that can be used to list directory contents and filter the results. To get a list of all the files and folders in a particular directory in the filesystem, use os.listdir() in legacy versions of Python or os.scandir() in Python 3.x. os.scandir() is the preferred method to use if you also want to get file and directory properties such as file size and modification date.
  
Line 579: Line 602:
  
  
 +</WRAP>
 +
 +====== Splitting, Concatenating, and Joining Strings in Python ======
 +
 +<WRAP center round box >
 2019-05-20 2019-05-20
  
Line 586: Line 614:
  
  
 +</WRAP>
 +
 +====== Regex Testor ======
 +
 +<WRAP center round box >
 Regex Testor Regex Testor
  
Line 591: Line 624:
 https://regex101.com/ https://regex101.com/
  
 +</WRAP>
 +
 +====== processdokuwikifile ======
 +
 +<WRAP center round box >
 2019-05-15 2019-05-15
  
Line 623: Line 661:
  
 From <https://www.vipinajayakumar.com/parsing-text-with-python/>  From <https://www.vipinajayakumar.com/parsing-text-with-python/> 
 +</WRAP>
  
 +====== PASS BY OBJECT REFERENCE (Case in python): ======
  
 +<WRAP center round box >
  
 2019-04-08 2019-04-08
Line 656: Line 697:
  
 From <https://stackoverflow.com/questions/13299427/python-functions-call-by-reference>  From <https://stackoverflow.com/questions/13299427/python-functions-call-by-reference> 
 +</WRAP>
  
  
  
 +====== Plotly ======
 +
 +<WRAP center round box >
 2019-03-31 2019-03-31
  
Line 673: Line 718:
  
  
 +</WRAP>
 +
 +====== Python write to CSV ======
 +
 +
 +<WRAP center round box >
  
 2019-03-29 2019-03-29
Line 705: Line 756:
  
 From <https://stackoverflow.com/questions/2084069/create-a-csv-file-with-values-from-a-python-list>  From <https://stackoverflow.com/questions/2084069/create-a-csv-file-with-values-from-a-python-list> 
 +</WRAP>
  
 +====== CSV in Python adding an extra carriage return, on Windows ======
 +
 +<WRAP center round box >
  
 CSV in Python adding an extra carriage return, on Windows CSV in Python adding an extra carriage return, on Windows
Line 717: Line 772:
 From <https://stackoverflow.com/questions/3191528/csv-in-python-adding-an-extra-carriage-return-on-windows>  From <https://stackoverflow.com/questions/3191528/csv-in-python-adding-an-extra-carriage-return-on-windows> 
  
 +</WRAP>
 +
 +====== Examples of simple type checking in Python: ======
 +
 +
 +<WRAP center round box >
 2019-02-17 2019-02-17
  
Line 740: Line 801:
 From <https://stackoverflow.com/questions/402504/how-to-determine-a-python-variables-type>  From <https://stackoverflow.com/questions/402504/how-to-determine-a-python-variables-type> 
  
 +</WRAP>
 +
 +====== isinstance() ======
 +
 +<WRAP center round box >
 With one argument, return the type of an object. The return value is a type object. The isinstance() built-in function is recommended for testing With one argument, return the type of an object. The return value is a type object. The isinstance() built-in function is recommended for testing
  
Line 756: Line 822:
  
 From <https://www.geeksforgeeks.org/type-isinstance-python/>  From <https://www.geeksforgeeks.org/type-isinstance-python/> 
- 
- 
- 
  
 </WRAP> </WRAP>
  
-<WRAP center round box 60%>+====== graph-cli ====== 
 + 
 +<WRAP center round box >
 2019-01-05 2019-01-05
  
Line 773: Line 838:
  
  
 +</WRAP>
 +
 +====== copy2 ======
 +
 +<WRAP center round box >
  
 2018-12-25 2018-12-25
Line 785: Line 855:
 From <https://stackabuse.com/how-to-copy-a-file-in-python/>  From <https://stackabuse.com/how-to-copy-a-file-in-python/> 
  
 +</WRAP>
 +
 +====== Start of String Only: \A ======
 +
 +<WRAP center round box >
  
 Start of String Only: \A Start of String Only: \A
Line 790: Line 865:
  
 From <https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions>  From <https://docs.microsoft.com/en-us/dotnet/standard/base-types/anchors-in-regular-expressions> 
 +
 +</WRAP>
 +
 +====== Decimals interact well with much of the rest of Python ======
 +
 +<WRAP center round box >
  
 decimal — Decimal fixed point and floating point arithmetic decimal — Decimal fixed point and floating point arithmetic
Line 821: Line 902:
  
 From <https://docs.python.org/3/library/decimal.html>  From <https://docs.python.org/3/library/decimal.html> 
 +
 +</WRAP>
 +
 +====== splitting a number into the integer and decimal parts ======
 +
 +<WRAP center round box >
 +
  
 splitting a number into the integer and decimal parts splitting a number into the integer and decimal parts
Line 856: Line 944:
 From <https://www.w3schools.com/python/python_datetime.asp>  From <https://www.w3schools.com/python/python_datetime.asp> 
  
 +</WRAP>
 +
 +====== Module datetime provides ======
 +
 +<WRAP center round box >
  
 Module datetime provides classes for manipulating date and time in more object oriented way. One of them is datetime.datetime.now which return number of seconds since the epoch. Module datetime provides classes for manipulating date and time in more object oriented way. One of them is datetime.datetime.now which return number of seconds since the epoch.
Line 876: Line 969:
  
  
 +</WRAP>
 +
 +====== Example 2: Right justify string and fill the remaining spaces ======
 +
 +<WRAP center round box >
 Example 2: Right justify string and fill the remaining spaces Example 2: Right justify string and fill the remaining spaces
  
Line 889: Line 987:
 From <https://www.programiz.com/python-programming/methods/string/rjust>  From <https://www.programiz.com/python-programming/methods/string/rjust> 
  
 +</WRAP>
  
 +====== Practical Business Python ======
  
 +<WRAP center round box >
 2018-12-24 2018-12-24
  
 Practical Business Python Practical Business Python
- 
  
 pbpython/extras/Pathlib-Cheatsheet.pdf pbpython/extras/Pathlib-Cheatsheet.pdf
Line 902: Line 1001:
  
  
 +</WRAP>
  
 +====== The divmod() returns ======
  
 +<WRAP center round box >
  
  
Line 913: Line 1015:
 From <https://www.programiz.com/python-programming/methods/built-in/divmod>  From <https://www.programiz.com/python-programming/methods/built-in/divmod> 
  
 +</WRAP>
 +
 +====== numpy ======
 +
 +<WRAP center round box >
 2018-11-18 2018-11-18
  
 +<code>
 pip install numpy pip install numpy
 +</code>
  
 From <https://pypi.org/project/numpy/>  From <https://pypi.org/project/numpy/> 
  
 +<code>
 pip3.6 install numpy pip3.6 install numpy
 pip3.6 install scipy pip3.6 install scipy
Line 926: Line 1036:
 Install opencv-python instead of cv2. Install opencv-python instead of cv2.
 pip install opencv-python pip install opencv-python
 +</code>
  
 From <https://github.com/jazzsaxmafia/video_to_sequence/issues/3>  From <https://github.com/jazzsaxmafia/video_to_sequence/issues/3> 
  
 +</WRAP>
 +
 +====== compare the use of lambda ======
 +
 +<WRAP center round box >
  
  
Line 936: Line 1052:
  
 From <https://stackoverflow.com/questions/8966538/syntax-behind-sortedkey-lambda>  From <https://stackoverflow.com/questions/8966538/syntax-behind-sortedkey-lambda> 
 +</WRAP>
 +
 +====== Key Functions ======
 +
 +<WRAP center round box >
  
 Key Functions Key Functions
Line 951: Line 1072:
 This image was created with the following code. This image was created with the following code.
  
 +<code>
 1 import operator                                                   1 import operator                                                  
 2 import pylab 2 import pylab
Line 978: Line 1100:
 26 pylab.grid() 26 pylab.grid()
 27 pylab.title("Performance sorted dictionary by values") 27 pylab.title("Performance sorted dictionary by values")
 +</code>
  
 From <http://thomas-cokelaer.info/blog/2017/12/how-to-sort-a-dictionary-by-values-in-python/>  From <http://thomas-cokelaer.info/blog/2017/12/how-to-sort-a-dictionary-by-values-in-python/> 
Line 983: Line 1106:
 As already said, iteritems() will be a problem, but you mention a syntax error, which comes from the lambda declaration with parenthesis: As already said, iteritems() will be a problem, but you mention a syntax error, which comes from the lambda declaration with parenthesis:
 Change: Change:
 +<code>
 key=lambda(k, v): sort_order.index(k) key=lambda(k, v): sort_order.index(k)
 +</code>
 To: To:
 +<code>
 key=lambda k, v: sort_order.index(k) key=lambda k, v: sort_order.index(k)
 +</code>
  
 From <https://stackoverflow.com/questions/47749438/lambda-sorting-in-python-3>  From <https://stackoverflow.com/questions/47749438/lambda-sorting-in-python-3> 
Line 992: Line 1119:
 </WRAP> </WRAP>
  
-<WRAP center round box 60%>+====== What problem does pandas solve? ====== 
 + 
 +<WRAP center round box >
  
 2018-11-15 2018-11-15
Line 1002: Line 1131:
  
 NumPy NumPy
 +<code>
 NumPy is the fundamental package for scientific computing with Python. It contains among other things: NumPy is the fundamental package for scientific computing with Python. It contains among other things:
 • a powerful N-dimensional array object • a powerful N-dimensional array object
Line 1007: Line 1137:
 • tools for integrating C/C++ and Fortran code • tools for integrating C/C++ and Fortran code
 • useful linear algebra, Fourier transform, and random number capabilities • useful linear algebra, Fourier transform, and random number capabilities
 +</code>
  
 From <http://www.numpy.org/>  From <http://www.numpy.org/> 
Line 1013: Line 1144:
  
 From <https://machinelearningmastery.com/broadcasting-with-numpy-arrays/>  From <https://machinelearningmastery.com/broadcasting-with-numpy-arrays/> 
 +
 +</WRAP>
 +
 +====== scikit-learn ======
 +
 +<WRAP center round box >
  
 scikit-learn scikit-learn
Line 1028: Line 1165:
 From <http://pybrain.org/>  From <http://pybrain.org/> 
  
 +</WRAP>
  
 +====== python read fails on special characters ======
  
 +<WRAP center round box >
  
 2018-11-06 2018-11-06
Line 1043: Line 1183:
  
 From <https://stackoverflow.com/questions/47635759/how-to-read-a-text-file-with-special-characters-in-python>  From <https://stackoverflow.com/questions/47635759/how-to-read-a-text-file-with-special-characters-in-python> 
 +</WRAP>
  
 +====== idle args ======
  
 +
 +<WRAP center round box >
  
 2018-10-31 2018-10-31
Line 1058: Line 1202:
  
 Pending application of a patch, the following will work to only add args to sys.argv when running from an Idle editor. Pending application of a patch, the following will work to only add args to sys.argv when running from an Idle editor.
 +<code>
 import sys import sys
 # ... # ...
Line 1072: Line 1217:
 except: except:
     sys.argv = [sys.argv[0], 'argument1', 'argument2', 'argument2']     sys.argv = [sys.argv[0], 'argument1', 'argument2', 'argument2']
 +</code>
  
 From <https://stackoverflow.com/questions/2148994/when-running-a-python-script-in-idle-is-there-a-way-to-pass-in-command-line-arg>  From <https://stackoverflow.com/questions/2148994/when-running-a-python-script-in-idle-is-there-a-way-to-pass-in-command-line-arg> 
  
 +</WRAP>
  
 +====== Auto detect IDLE and prompt for command-line argument values ======
 +
 +
 +<WRAP center round box >
  
 2018-10-31 2018-10-31
Line 1081: Line 1232:
 Auto detect IDLE and prompt for command-line argument values Auto detect IDLE and prompt for command-line argument values
  
-#! /usr/bin/env python3+<code> 
 +c#! /usr/bin/env python3
 import sys import sys
 def ok(x=None): def ok(x=None):
Line 1097: Line 1249:
       root.bind("<Escape>", lambda x: root.destroy())       root.bind("<Escape>", lambda x: root.destroy())
 e.focus() e.focus()
 +</code>
  
 From <https://stackoverflow.com/questions/2148994/when-running-a-python-script-in-idle-is-there-a-way-to-pass-in-command-line-arg/44687632#44687632>  From <https://stackoverflow.com/questions/2148994/when-running-a-python-script-in-idle-is-there-a-way-to-pass-in-command-line-arg/44687632#44687632> 
  
 +</WRAP>
 +
 +====== print the files deleted ======
 +
 +<WRAP center round box >
  
  
Line 1118: Line 1276:
         pass         pass
 </code> </code>
 +
 +</WRAP>
 +
 +====== delete directories ======
 +
 +<WRAP center round box >
 Here's an alternative Python script that is case sensitive and will also delete directories included in the list Here's an alternative Python script that is case sensitive and will also delete directories included in the list
 <code> <code>
Line 1149: Line 1313:
  
  
 +</WRAP>
 +
 +====== checkpoints ======
 +
 +<WRAP center round box >
  
 2018-10-06 2018-10-06
Line 1173: Line 1342:
  
 From <https://www.programcreek.com/python/example/92/glob.glob>  From <https://www.programcreek.com/python/example/92/glob.glob> 
 +</WRAP>
  
 +====== argparse ======
  
 +<WRAP center round box >
  
 2018-10-06 2018-10-06
software/python.1609041705.txt.gz · Last modified: by superwizard