software:python
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| software:python [2020/12/26 20:05] – superwizard | software: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 < | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | ====== Wireshark tcpdump to neo4j plot ====== | ||
| + | |||
| <WRAP center round box > | <WRAP center round box > | ||
| Line 384: | Line 402: | ||
| Example 3 | Example 3 | ||
| + | < | ||
| import re re.sub(' | import re re.sub(' | ||
| • string1 - Result: 3.11899876595 | • string1 - Result: 3.11899876595 | ||
| • string2 - Result: 2.78014397621 | • string2 - Result: 2.78014397621 | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== Access Dates ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| Access Dates | Access Dates | ||
| Line 408: | Line 432: | ||
| From < | From < | ||
| - | |||
| Line 416: | Line 439: | ||
| From < | From < | ||
| + | </ | ||
| + | ====== Sort a Dictionary ====== | ||
| - | + | <WRAP center round box > | |
| 2019-08-22 | 2019-08-22 | ||
| Line 428: | Line 452: | ||
| + | </ | ||
| + | |||
| + | ====== Plotly Cufflinks ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2019-08-15 | 2019-08-15 | ||
| Line 438: | Line 467: | ||
| From < | From < | ||
| - | |||
| - | |||
| </ | </ | ||
| - | <WRAP center round box 60%> | + | ====== Parsing text with Python ====== |
| + | |||
| + | <WRAP center round box > | ||
| 2019-07-11 | 2019-07-11 | ||
| Line 456: | Line 485: | ||
| + | </ | ||
| + | |||
| + | ====== DataFrames ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2019-08-14 | 2019-08-14 | ||
| Line 465: | Line 499: | ||
| + | </ | ||
| + | |||
| + | ====== Backblaze ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2019-7-11 | 2019-7-11 | ||
| Line 510: | Line 549: | ||
| From < | From < | ||
| + | </ | ||
| + | ====== Regular Expression ====== | ||
| + | |||
| + | |||
| + | <WRAP center round box > | ||
| 2019-05-29 | 2019-05-29 | ||
| - | ValidIpAddressRegex = " | + | |
| From < | From < | ||
| + | < | ||
| \b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | \b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | ||
| (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | ||
| (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | ||
| (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | (25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]? | ||
| + | </ | ||
| From < | From < | ||
| Line 532: | Line 578: | ||
| From < | From < | ||
| - | |||
| - | |||
| - | |||
| - | |||
| </ | </ | ||
| - | ====== | + | ====== |
| <WRAP center round box > | <WRAP center round box > | ||
| Line 545: | Line 587: | ||
| str.rpartition(sep) | str.rpartition(sep) | ||
| + | |||
| Split the string at the last occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing two empty strings, followed by the string itself. | Split the string at the last occurrence of sep, and return a 3-tuple containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return a 3-tuple containing two empty strings, followed by the string itself. | ||
| From < | From < | ||
| + | </ | ||
| + | ====== 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 555: | Line 602: | ||
| + | </ | ||
| + | |||
| + | ====== Splitting, Concatenating, | ||
| + | |||
| + | <WRAP center round box > | ||
| 2019-05-20 | 2019-05-20 | ||
| Line 562: | Line 614: | ||
| + | </ | ||
| + | |||
| + | ====== Regex Testor ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| Regex Testor | Regex Testor | ||
| Line 567: | Line 624: | ||
| https:// | https:// | ||
| + | </ | ||
| + | |||
| + | ====== processdokuwikifile ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2019-05-15 | 2019-05-15 | ||
| + | < | ||
| def processdokuwikifile(in_file, | def processdokuwikifile(in_file, | ||
| """ | """ | ||
| - | #with open(' | + | #with open(' |
| with open(par_out_file,' | with open(par_out_file,' | ||
| out = csv.writer(out_file) | out = csv.writer(out_file) | ||
| - | #with open(' | + | #with open(' |
| - | #with open(' | + | #with open(' |
| - | with open(in_file,' | + | with open(in_file,' |
| + | </ | ||
| Line 597: | Line 661: | ||
| From < | From < | ||
| + | </ | ||
| + | ====== PASS BY OBJECT REFERENCE (Case in python): ====== | ||
| + | <WRAP center round box > | ||
| 2019-04-08 | 2019-04-08 | ||
| Line 604: | Line 671: | ||
| PASS BY OBJECT REFERENCE (Case in python): | PASS BY OBJECT REFERENCE (Case in python): | ||
| Here, " | Here, " | ||
| + | < | ||
| def append_one(li): | def append_one(li): | ||
| li.append(1) | li.append(1) | ||
| Line 609: | Line 677: | ||
| append_one(x) | append_one(x) | ||
| print x | print x | ||
| + | </ | ||
| + | |||
| Here, the statement x = [0] makes a variable x (box) that points towards the object [0] | Here, the statement x = [0] makes a variable x (box) that points towards the object [0] | ||
| On the function being called, a new box li is created. The contents of li is the SAME as the contents of box x. Both the boxes contain the same object. That is, both the variables point to the same object in memory. Hence, any change to the object pointed at by li will also be reflected by the object pointed at by x. | On the function being called, a new box li is created. The contents of li is the SAME as the contents of box x. Both the boxes contain the same object. That is, both the variables point to the same object in memory. Hence, any change to the object pointed at by li will also be reflected by the object pointed at by x. | ||
| Line 616: | Line 686: | ||
| If the variable li is reassigned in the function, then li will point to a seperate object in memory. x however, will continue pointing to the same object in memory it was pointing to earlier. | If the variable li is reassigned in the function, then li will point to a seperate object in memory. x however, will continue pointing to the same object in memory it was pointing to earlier. | ||
| Example: | Example: | ||
| + | < | ||
| def append_one(li): | def append_one(li): | ||
| li = [0, 1] | li = [0, 1] | ||
| Line 621: | Line 692: | ||
| append_one(x) | append_one(x) | ||
| print x | print x | ||
| + | </ | ||
| The output of the program will be: | The output of the program will be: | ||
| [0] | [0] | ||
| From < | From < | ||
| + | </ | ||
| + | ====== Plotly ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2019-03-31 | 2019-03-31 | ||
| Plotly | Plotly | ||
| + | < | ||
| 1962_2006_walmart_store_openings.csv Update 1962_2006_walmart_store_openings.csv 4 years ago | 1962_2006_walmart_store_openings.csv Update 1962_2006_walmart_store_openings.csv 4 years ago | ||
| 2010_alcohol_consumption_by_country.csv Create 2010_alcohol_consumption_by_country.csv 3 years ago | 2010_alcohol_consumption_by_country.csv Create 2010_alcohol_consumption_by_country.csv 3 years ago | ||
| 2011_february_aa_flight_paths.csv Create 2011_february_aa_flight_paths.csv 4 years ago | 2011_february_aa_flight_paths.csv Create 2011_february_aa_flight_paths.csv 4 years ago | ||
| 2011_february_us_airport_traffic.csv Create 2011_february_us_airport_traffic.csv 4 years ago | 2011_february_us_airport_traffic.csv Create 2011_february_us_airport_traffic.csv 4 years ago | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== Python write to CSV ====== | ||
| + | |||
| + | |||
| + | <WRAP center round box > | ||
| 2019-03-29 | 2019-03-29 | ||
| Line 645: | Line 729: | ||
| Python write to CSV | Python write to CSV | ||
| + | < | ||
| import csv | import csv | ||
| with open(..., ' | with open(..., ' | ||
| wr = csv.writer(myfile, | wr = csv.writer(myfile, | ||
| wr.writerow(mylist) | wr.writerow(mylist) | ||
| + | </ | ||
| From < | From < | ||
| + | < | ||
| with open(iniFile.absolute(), | with open(iniFile.absolute(), | ||
| #spamwriter = csv.writer(iniSettings, | #spamwriter = csv.writer(iniSettings, | ||
| Line 662: | Line 749: | ||
| for val in folder_list: | for val in folder_list: | ||
| spamwriter.writerow(val) | spamwriter.writerow(val) | ||
| + | </ | ||
| you can also use wr.writerows(list) – tovmeod Dec 25 '11 at 22:29 | you can also use wr.writerows(list) – tovmeod Dec 25 '11 at 22:29 | ||
| Line 668: | Line 756: | ||
| From < | From < | ||
| + | </ | ||
| + | ====== 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 | ||
| One of the possible fixes in Python3, as described in @YiboYang' | One of the possible fixes in Python3, as described in @YiboYang' | ||
| + | < | ||
| f = open(path_to_file, | f = open(path_to_file, | ||
| writer = csv.writer(f) | writer = csv.writer(f) | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== Examples of simple type checking in Python: ====== | ||
| + | |||
| + | |||
| + | <WRAP center round box > | ||
| 2019-02-17 | 2019-02-17 | ||
| Examples of simple type checking in Python: | Examples of simple type checking in Python: | ||
| + | < | ||
| assert type(variable_name) == int | assert type(variable_name) == int | ||
| assert type(variable_name) == bool | assert type(variable_name) == bool | ||
| assert type(variable_name) == list | assert type(variable_name) == list | ||
| + | </ | ||
| From < | From < | ||
| Use type | Use type | ||
| + | < | ||
| >>> | >>> | ||
| <type ' | <type ' | ||
| Line 694: | Line 797: | ||
| >>> | >>> | ||
| ' | ' | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== 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 702: | Line 811: | ||
| • Syntax: | • Syntax: | ||
| + | < | ||
| isinstance(object, | isinstance(object, | ||
| + | </ | ||
| The isinstance() takes two parameters: | The isinstance() takes two parameters: | ||
| + | < | ||
| object : object to be checked | object : object to be checked | ||
| classinfo : class, type, or tuple of classes and types | classinfo : class, type, or tuple of classes and types | ||
| + | </ | ||
| From < | From < | ||
| - | |||
| - | |||
| - | |||
| </ | </ | ||
| - | <WRAP center round box 60%> | + | ====== graph-cli ====== |
| + | |||
| + | <WRAP center round box > | ||
| 2019-01-05 | 2019-01-05 | ||
| Line 726: | Line 838: | ||
| + | </ | ||
| + | |||
| + | ====== copy2 ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2018-12-25 | 2018-12-25 | ||
| Line 732: | Line 849: | ||
| As with the previous methods, | As with the previous methods, | ||
| The syntax is as follows: | The syntax is as follows: | ||
| + | < | ||
| shutil.copy2(src_file, | shutil.copy2(src_file, | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== Start of String Only: \A ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| Start of String Only: \A | Start of String Only: \A | ||
| Line 741: | Line 865: | ||
| From < | From < | ||
| + | |||
| + | </ | ||
| + | |||
| + | ====== 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 747: | Line 877: | ||
| Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem: | Unlike hardware based binary floating point, the decimal module has a user alterable precision (defaulting to 28 places) which can be as large as needed for a given problem: | ||
| + | < | ||
| >>> | >>> | ||
| >>> | >>> | ||
| Line 754: | Line 885: | ||
| >>> | >>> | ||
| Decimal(' | Decimal(' | ||
| + | </ | ||
| From < | From < | ||
| Decimals interact well with much of the rest of Python. Here is a small decimal floating point flying circus: | Decimals interact well with much of the rest of Python. Here is a small decimal floating point flying circus: | ||
| + | < | ||
| >>> | >>> | ||
| >>> | >>> | ||
| Line 766: | Line 899: | ||
| [Decimal(' | [Decimal(' | ||
| | | ||
| + | </ | ||
| From < | From < | ||
| + | |||
| + | </ | ||
| + | |||
| + | ====== 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 778: | Line 920: | ||
| 147.0 | 147.0 | ||
| >>> | >>> | ||
| + | </ | ||
| If you want the integer part as an integer and not a float, use int(a// | If you want the integer part as an integer and not a float, use int(a// | ||
| EDIT: Remember that the decimal part of a float number is approximate, | EDIT: Remember that the decimal part of a float number is approximate, | ||
| Line 783: | Line 926: | ||
| From < | From < | ||
| + | < | ||
| import math | import math | ||
| x = 1234.5678 | x = 1234.5678 | ||
| math.modf(x) # (0.5678000000000338, | math.modf(x) # (0.5678000000000338, | ||
| + | </ | ||
| From < | From < | ||
| Line 791: | Line 936: | ||
| Create a date object: | Create a date object: | ||
| + | < | ||
| import datetime | import datetime | ||
| x = datetime.datetime(2020, | x = datetime.datetime(2020, | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== 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. | ||
| + | < | ||
| import datetime; | import datetime; | ||
| ts = datetime.datetime.now().timestamp() | ts = datetime.datetime.now().timestamp() | ||
| print(ts) | print(ts) | ||
| # 1545665588.52 | # 1545665588.52 | ||
| + | </ | ||
| + | |||
| From < | From < | ||
| + | < | ||
| x = int(datetime.datetime(2070, | x = int(datetime.datetime(2070, | ||
| print(x) | print(x) | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | ====== 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 | ||
| + | < | ||
| # example string | # example string | ||
| string = ' | string = ' | ||
| Line 820: | Line 983: | ||
| # print right justified string | # print right justified string | ||
| print(string.rjust(width, | print(string.rjust(width, | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | ====== Practical Business Python ====== | ||
| + | <WRAP center round box > | ||
| 2018-12-24 | 2018-12-24 | ||
| Practical Business Python | Practical Business Python | ||
| - | |||
| pbpython/ | pbpython/ | ||
| Line 836: | Line 1001: | ||
| + | </ | ||
| + | ====== The divmod() returns ====== | ||
| + | <WRAP center round box > | ||
| Line 847: | Line 1015: | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== numpy ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2018-11-18 | 2018-11-18 | ||
| + | < | ||
| pip install numpy | pip install numpy | ||
| + | </ | ||
| From < | From < | ||
| + | < | ||
| pip3.6 install numpy | pip3.6 install numpy | ||
| pip3.6 install scipy | pip3.6 install scipy | ||
| Line 860: | Line 1036: | ||
| Install opencv-python instead of cv2. | Install opencv-python instead of cv2. | ||
| pip install opencv-python | pip install opencv-python | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== compare the use of lambda ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| Line 870: | Line 1052: | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== Key Functions ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| Key Functions | Key Functions | ||
| Line 885: | Line 1072: | ||
| This image was created with the following code. | This image was created with the following code. | ||
| + | < | ||
| 1 import operator | 1 import operator | ||
| 2 import pylab | 2 import pylab | ||
| Line 912: | Line 1100: | ||
| 26 pylab.grid() | 26 pylab.grid() | ||
| 27 pylab.title(" | 27 pylab.title(" | ||
| + | </ | ||
| From < | From < | ||
| Line 917: | Line 1106: | ||
| As already said, | As already said, | ||
| Change: | Change: | ||
| + | < | ||
| key=lambda(k, | key=lambda(k, | ||
| + | </ | ||
| To: | To: | ||
| + | < | ||
| key=lambda k, v: sort_order.index(k) | key=lambda k, v: sort_order.index(k) | ||
| + | </ | ||
| From < | From < | ||
| Line 926: | Line 1119: | ||
| </ | </ | ||
| - | <WRAP center round box 60%> | + | ====== What problem does pandas solve? ====== |
| + | |||
| + | <WRAP center round box > | ||
| 2018-11-15 | 2018-11-15 | ||
| Line 936: | Line 1131: | ||
| NumPy | NumPy | ||
| + | < | ||
| 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 941: | 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 | ||
| + | </ | ||
| From < | From < | ||
| Line 947: | Line 1144: | ||
| From < | From < | ||
| + | |||
| + | </ | ||
| + | |||
| + | ====== scikit-learn ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| scikit-learn | scikit-learn | ||
| Line 962: | Line 1165: | ||
| From < | From < | ||
| + | </ | ||
| + | ====== python read fails on special characters ====== | ||
| + | <WRAP center round box > | ||
| 2018-11-06 | 2018-11-06 | ||
| Line 977: | Line 1183: | ||
| From < | From < | ||
| + | </ | ||
| + | ====== idle args ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2018-10-31 | 2018-10-31 | ||
| Line 992: | 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. | ||
| + | < | ||
| import sys | import sys | ||
| # ... | # ... | ||
| Line 1006: | Line 1217: | ||
| except: | except: | ||
| sys.argv = [sys.argv[0], | sys.argv = [sys.argv[0], | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | ====== Auto detect IDLE and prompt for command-line argument values ====== | ||
| + | |||
| + | |||
| + | <WRAP center round box > | ||
| 2018-10-31 | 2018-10-31 | ||
| Line 1015: | Line 1232: | ||
| Auto detect IDLE and prompt for command-line argument values | Auto detect IDLE and prompt for command-line argument values | ||
| - | #! / | + | < |
| + | c#! / | ||
| import sys | import sys | ||
| def ok(x=None): | def ok(x=None): | ||
| Line 1031: | Line 1249: | ||
| root.bind("< | root.bind("< | ||
| e.focus() | e.focus() | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== print the files deleted ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| Line 1039: | Line 1263: | ||
| Python Script | Python Script | ||
| Here's a Python script that will also print the files deleted | Here's a Python script that will also print the files deleted | ||
| + | < | ||
| import os | import os | ||
| for line in open(" | for line in open(" | ||
| Line 1050: | Line 1275: | ||
| except OSError: | except OSError: | ||
| pass | pass | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | ====== 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 | ||
| + | < | ||
| import os | import os | ||
| import shutil | import shutil | ||
| Line 1075: | Line 1308: | ||
| # | # | ||
| pass | pass | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== checkpoints ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2018-10-06 | 2018-10-06 | ||
| GLOB | GLOB | ||
| + | < | ||
| def delete_previous_checkpoints(self, | def delete_previous_checkpoints(self, | ||
| """ | """ | ||
| Line 1099: | Line 1339: | ||
| ckpt_file_nm = self.get_checkpoint_location() + '/ | ckpt_file_nm = self.get_checkpoint_location() + '/ | ||
| os.remove(ckpt_file_nm) | os.remove(ckpt_file_nm) | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | ====== argparse ====== | ||
| + | <WRAP center round box > | ||
| 2018-10-06 | 2018-10-06 | ||
| Line 1110: | Line 1354: | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== Argparse Tutorial ====== | ||
| + | |||
| + | |||
| + | <WRAP center round box > | ||
| Argparse Tutorial | Argparse Tutorial | ||
| Line 1117: | Line 1367: | ||
| From < | From < | ||
| + | < | ||
| *args and **kwargs in Python | *args and **kwargs in Python | ||
| *args | *args | ||
| + | </ | ||
| The special syntax *args in function definitions in python is used to pass a variable number of arguments to a function. It is used to pass a non-keyworded, | The special syntax *args in function definitions in python is used to pass a variable number of arguments to a function. It is used to pass a non-keyworded, | ||
| Line 1124: | Line 1376: | ||
| + | </ | ||
| + | |||
| + | ====== recursive ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2018-10-03 | 2018-10-03 | ||
| Line 1133: | Line 1390: | ||
| From < | From < | ||
| + | I have successfully used | ||
| + | < | ||
| + | for i in d.rglob(' | ||
| + | </ | ||
| + | |||
| + | < | ||
| for i in d.iglob(' | for i in d.iglob(' | ||
| + | </ | ||
| The “**” pattern means “this directory and all subdirectories, | The “**” pattern means “this directory and all subdirectories, | ||
| Line 1139: | Line 1403: | ||
| From < | From < | ||
| + | < | ||
| errno.ENOTEMPTY | errno.ENOTEMPTY | ||
| Directory not empty | Directory not empty | ||
| + | </ | ||
| From < | From < | ||
| + | < | ||
| errno.EACCES¶ | errno.EACCES¶ | ||
| Permission denied | Permission denied | ||
| + | </ | ||
| From < | From < | ||
| + | < | ||
| except OSError as e: | except OSError as e: | ||
| if e.errno not in _IGNORED_ERROS: | if e.errno not in _IGNORED_ERROS: | ||
| raise | raise | ||
| return False | return False | ||
| + | </ | ||
| From < | From < | ||
| + | < | ||
| except OSError as e: | except OSError as e: | ||
| if e.errno != EINVAL and strict: | if e.errno != EINVAL and strict: | ||
| raise | raise | ||
| + | </ | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== walktree ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| 2018-10-01 | 2018-10-01 | ||
| Line 1189: | Line 1466: | ||
| + | </ | ||
| + | |||
| + | ====== Dropbox in python ====== | ||
| + | |||
| + | |||
| + | |||
| + | <WRAP center round box > | ||
| 2018-09-29 | 2018-09-29 | ||
| Dropbox in python | Dropbox in python | ||
| + | < | ||
| from pathlib import Path | from pathlib import Path | ||
| import arrow | import arrow | ||
| Line 1205: | Line 1489: | ||
| #remove it | #remove it | ||
| pass | pass | ||
| + | </ | ||
| From < | From < | ||
| Line 1213: | Line 1497: | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== CSV Toolkit Overview ====== | ||
| + | |||
| + | |||
| + | <WRAP center round box > | ||
| 2018-09-04 | 2018-09-04 | ||
| Line 1221: | Line 1511: | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== What is Bonobo? ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| What is Bonobo? | What is Bonobo? | ||
| Bonobo is a lightweight Extract-Transform-Load (ETL) framework for Python 3.5+. | Bonobo is a lightweight Extract-Transform-Load (ETL) framework for Python 3.5+. | ||
| Line 1232: | Line 1527: | ||
| From < | From < | ||
| + | </ | ||
| + | |||
| + | ====== Awesome Python ====== | ||
| + | |||
| + | <WRAP center round box > | ||
| Awesome Python | Awesome Python | ||
| A curated list of awesome Python frameworks, libraries, software and resources. | A curated list of awesome Python frameworks, libraries, software and resources. | ||
| Line 1247: | Line 1547: | ||
| From < | From < | ||
| + | </ | ||
| + | ====== Python data visualization: | ||
| + | |||
| + | <WRAP center round box > | ||
| 2018-09-04 | 2018-09-04 | ||
| Line 1256: | Line 1560: | ||
| From < | From < | ||
| + | </ | ||
| + | ====== Best way to sort txt file using csv tools in python ====== | ||
| + | |||
| + | |||
| + | <WRAP center round box > | ||
| 2018-09-04 | 2018-09-04 | ||
| Line 1264: | Line 1573: | ||
| From < | From < | ||
| + | < | ||
| import csv | import csv | ||
| import operator | import operator | ||
| Line 1280: | Line 1590: | ||
| sortedlist=sorted(f, | sortedlist=sorted(f, | ||
| print(sortedlist) | print(sortedlist) | ||
| + | </ | ||
| From < | From < | ||
| Line 1287: | Line 1598: | ||
| 2018-08-10 | 2018-08-10 | ||
| The sys.path list contains the list of directories which will be searched for modules at runtime: | The sys.path list contains the list of directories which will be searched for modules at runtime: | ||
| + | < | ||
| python -v | python -v | ||
| >>> | >>> | ||
| >>> | >>> | ||
| ['', | ['', | ||
| + | |||
| + | </ | ||
| From < | From < | ||
| For speedtest - / | For speedtest - / | ||
| - | |||
| </ | </ | ||
software/python.1609013146.txt.gz · Last modified: by superwizard
