[Python] A memo of frequently used phrases (by myself) in Python scripts

Contents of this time

A note of phrases that you often use (yourself) in Python scripts.

Description at the beginning of the script

#!/usr/bin/env python3

It can be executed directly in a Unix-like environment.

[Additional correction] #coding: utf-8 It seems that it is not necessary to specify the character code.

Get arguments as a list

import sys

argv_list = [sys.argv[i] for i in range(1,len(sys.argv))]

Run only when run as a script

if __name__ == '__main__':

Get filename without extension

import os

basename_without_ext = os.path.splitext(os.path.basename(filepath))[0]

Recommended Posts

[Python] A memo of frequently used phrases (by myself) in Python scripts
Summary of frequently used Python arrays (for myself)
A collection of code often used in personal Python
A collection of commands frequently used in server management
Group by consecutive elements of a list in Python
A collection of Excel operations often used in Python
How to develop in a virtual environment of Python [Memo]
A memo of writing a basic function in Python using recursion
8 Frequently Used Commands in Python Django
A simple data analysis of Bitcoin provided by CoinMetrics in Python
Read the standard output of a subprocess line by line in Python
A class that summarizes frequently used methods in twitter api (python)
[Learning memo] Basics of class by python
Summary of frequently used commands in matplotlib
Display a list of alphabets in Python 3
[python] Frequently used techniques in machine learning
A memo organized by renaming the file names in the folder with python
Modules of frequently used functions in Python (such as reading external files)
A memo of a tutorial on running python on heroku
Draw a graph of a quadratic function in Python
A memo that I wrote a quicksort in Python
Get the caller of a function in Python
Make a copy of the list in Python
A memorandum of extraction by python bs4 request
A memo about writing merge sort in Python
[Memo] I tried a pivot table in Python
Rewriting elements in a loop of lists (Python)
Make a joyplot-like plot of R in python
Output in the form of a python array
Get a glimpse of machine learning in Python
[Linux command] A memorandum of frequently used commands
A memo for creating a python environment by a beginner
A well-prepared record of data analysis in Python
Python scikit-learn A collection of predictive model tips often used in the field
A personal memo of Pandas related operations that can be used in practice
Basic data frame operations written by beginners in a week of learning Python
Python scikit-learn A collection of predictive model tips often used in the field
A memo connected to HiveServer2 of EMR with python
Note the frequently used options in Python + Selenium + Chrome
Visualization memo by Python
A memo that implements the job of loading a GCS file into BigQuery in Python
List of Python code used in big data analysis
I want to use a network defined by myself in PPO2 of Stable Baselines
Comparison table of frequently used processes of Python and Clojure
Display a histogram of image brightness values in python
A python regular expression, or a memo of a match object
A reminder about the implementation of recommendations in Python
Display a list of frequently used commands on Zsh
Memo of "Cython-Speeding up Python by fusing with C"
Ssh connection memo using ProxyCommand of ssh_config in Python
Python> Get a list of files in multiple directories> Use glob | Sort by modification time
Can be used with AtCoder! A collection of techniques for drawing short code in Python!
__init__ called by wxPython or Tkinter was a __init__ call of the inheriting class in Python
[Scientific / technical calculation by Python] List of usage of (special) functions used in physics by using scipy
Create an executable file (EXE) by PyInstaller in a hybrid environment (Nimporter) of Python + Nim
Find out the apparent width of a string in python
[Python] How to make a list of character strings character by character
[Memo] The mystery of cumulative assignment statements in Python functions
Make a table of multiplication of each element in a spreadsheet (Python)
Get the number of specific elements in a python list
A memo when creating a directed graph using Graphviz in Python