It's a hassle to write "coding: utf-8" in Python, so I'll do something with Shellscript

Basically, the flow is like opening touch-> file with an editor in Python, but at that time, at the beginning of each line

python


# -*- coding:utf-8 -*-

It's extremely troublesome to write, and in most cases I write this, so I wrote a shell script for it.

python


#!/bin/bash

#Argument check
if [ $# -ne 1 ]; then
    echo "usage: pytouch TOUCHFILE.py"
    exit 1
fi

#Exit if the file exists (because it will not be overwritten)
if [ -e $1 ]; then
    exit 0
fi

touch $1
#to echo-You can use line breaks by passing the e option
echo -e "# -*- coding:utf-8 -*-\n" > $1
exit 0

After that, save it with a name like pytouch in the place where the path passes, and complete it with chmod + x.

Depending on the type

python


if __name__ == "__main__":
    main()

It seems convenient to make a version that includes.

Recommended Posts

It's a hassle to write "coding: utf-8" in Python, so I'll do something with Shellscript
It's Halloween so I'll try to hide it with Python
Throw something to Kinesis with python and make sure it's in
I want to write to a file with Python
Searching for an efficient way to write a Dockerfile in Python with poetry
How to do hash calculation with salt in Python
I want to write in Python! (2) Let's write a test
I want to work with a robot in python.
[Python] A memo to write CSV vertically with Pandas
A program to write Lattice Hinge with Rhinoceros with Python
I want to do something in Python when I finish
It's hard to write a very simple algorithm in php
I want to do something like sort uniq in Python
Recursively get the Excel list in a specific folder with python and write it to Excel.
Do something like a Python interpreter in Visual Studio Code
Write to csv with Python
What I was addicted to in Collective Intelligence Chaprter 3. It's not a typo, so I think something is wrong with my code.
Expand a Python nested dictionary to do something like Pandas' MultiIndex
What to do if you get a minus zero in Python
How to create a heatmap with an arbitrary domain in Python
I wanted to do something like an Elixir pipe in Python
Homework was a pain, so I do management accounting with Python
How to write a Python class
[Python] How to do PCA in Python
[Python] Write to csv file with Python
Write A * (A-star) algorithm in Python
What to do with PYTHON release?
Write a pie chart in Python
Write a vim plugin in Python
Write a depth-first search in Python
Write a batch script with Python3.5 ~
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
How to write what to do when an application is first displayed in Qt for Python with Designer
I want to improve efficiency with Python even in an experimental system (3) I want to do something like Excel with Pandas
What to do if there is a decimal in python json .dumps
It's a hassle, so I'll automate it! ~ Image automatic loading failure edition ~
I tried to make a calculator with Tkinter so I will write it
It's more recent, but I wanted to do BMI calculation with python.
Write a basic headless web scraping "bot" in Python with Beautiful Soup 4
How to write a string when there are multiple lines in python
[Introduction to Python] How to write a character string with the format function
I want to do a monkey patch only partially safely in Python
Write documentation in Sphinx with Python Livereload
Spiral book in Python! Python with a spiral book! (Chapter 14 ~)
Try logging in to qiita with Python
Do a non-recursive Euler Tour in Python
How to do R chartr () in Python
Write the test in a python docstring
How to work with BigQuery in Python
How to get a stacktrace in python
Write a Caesar cipher program in Python
How to do portmanteau test with python
Write a simple greedy algorithm in Python
Write a TCP client with Python Twisted
Do something like Redis transactions in Python
Write a simple Vim Plugin in Python 3
To work with timestamp stations in Python
How to write Ruby to_s in Python
Feel free to write a test with nose (in the case of + gevent)
[Python] Created a class to play sin waves in the background with pyaudio
How to drop Google Docs in one folder in a .txt file with python