Python frequently used code snippets

Write down frequently used code snippets in Python.

Stored in dict array from PowerShell fl format (Format-List) result

PowerShell


PS> Get-Process -Name powershell | Format-List -Property ProcessName,FileVersion
,StartTime,Id

ProcessName : powershell
FileVersion : 1.0.9567.1
StartTime   : 2006-05-24 13:42:00
Id          : 2760

ProcessName : powershell
FileVersion : 1.0.9567.1
StartTime   : 2006-05-24 13:54:28
Id          : 3448

Python


import re

ps_result = '''
ProcessName : powershell
FileVersion : 1.0.9567.1
StartTime   : 2006-05-24 13:42:00
Id          : 2760

ProcessName : powershell
FileVersion : 1.0.9567.1
StartTime   : 2006-05-24 13:54:28
Id          : 3448
'''

lines = ps_result.split('\n')
dics = []
dic = {}
for line in lines:
    ret = line.split(' : ')
    if len(ret) == 2:
        ret[0] = re.sub(r' +$', '', ret[0])
        dic[ret[0]] = ret[1]
    if dic != {} and len(ret) < 2:
        dics.append(dic)
        dic = {}


print dics

Convert a subset of dictionaries to csv with python

http://millfont.blogspot.jp/2011/08/pythoncsv.html

reference

https://technet.microsoft.com/ja-jp/library/dd347677.aspx

Recommended Posts

Python frequently used code snippets
[Python] Frequently used library code
8 Frequently Used Commands in Python Django
Python + Selenium Frequently used operation method summary
[python] Frequently used techniques in machine learning
python character code
[Python] Algorithm-aware code
Summary of frequently used Python arrays (for myself)
Code often used in Python / Django apps [prefectures]
Frequently used tmux commands
Python code acceleration approach
Frequently used Linux commands
Frequently used Linux commands
Rewrite Python2 code to Python3 (2to3)
infomap python draw code
Before writing Python code
Frequently used linux commands
Python Requests status code
OpenCV basic code (python)
Frequently used pip commands
Note the frequently used options in Python + Selenium + Chrome
A collection of code often used in personal Python
List of Python code used in big data analysis
Comparison table of frequently used processes of Python and Clojure
Get country code with python
Frequently used ps command options
Python with VS Code (Windows 10)
Code snippets often used when processing videos with Google Colaboratory
Code snippets often used when using BigQuery with Google Colab
Debug Python with VS Code
2.x, 3.x character code of python
Frequently used subpackages of SciPy
Generate QR code in Python
Frequently used commands in virtualenv
[Python] Sample code for Python grammar
Character code learned in Python
Convert python 3.x code to python 2.x
Document Python code with Doxygen
[Python] A memo of frequently used phrases (by myself) in Python scripts
A class that summarizes frequently used methods in twitter api (python)
Python hand play (argparse minimum code)
That Python code has no classes ...
[Python] Generate QR code in memory
Linux Frequently Used Commands [Personal Memo]
[Golang] Notes on frequently used functions
Automatically format Python code in Vim
VS Code snippets for data analysts
[Python] Basic knowledge used in AtCoder
Classify frequently used file / folder dialogs
Write selenium test code in python
Execute Python code from C # GUI
Frequently used Linux commands (for beginners)
Python parallel / parallel processing sample code summary
Check python code styles using pep8
List of frequently used Linux commands
[Anaconda3] Summary of frequently used commands
[Linux] Frequently used Linux commands (folder operation)
[Python] Read the Flask source code
Python --Symbols used when performing operations
Code tests around time in Python
[VS Code] ~ Tips when using python ~