Notes for Python file input / output

I'm going to write csv processing processing in business, so I created a competition "φ (・ e ・ o) ~ I'm sorry if 3 series are mixed with the intention of 2 series.

open function

file = open("read.txt", "r", "UTF-8")
argument Mandatory Description
$1 file name
$2 - mode
$3 - Character code

Multiple mode options can be specified.

type Description
r Read-only
a Addition, generate if there is no file
t Text mode(default)
b Binary mode

You can use the with statement to automatically close ().

with open('text_file.txt') as file:
    print(file.read())

Linking

#Easy join with join function
"-".join(["foo", "bar", "baz"])
>>> 'foo-bar-baz'

conversion

# "%s"Easy to replace with
"%s, %s, %s!" % ("one", "two", "three")
>>> 'one, two, three!'

Recommended Posts

Notes for Python file input / output
Tips on Python file input / output
python input and output
Python audio input / output
Python Tkinter notes (for myself)
Python3 standard input for competitive programming
Python logging standard library for file output by log level
Minimum grammar notes for writing Python
Output to csv file with Python
Personal notes for python image processing
Python application: Data handling Part 1: Data formatting and file input / output
Notes for me python csv graph
Notes for using OpenCV on Windows10 Python 3.8.3.
Data input / output in Python (CSV, JSON)
WEB scraping with Python (for personal notes)
Data handling 1 Data formatting and file input / output
Notes on standard input / output of Go
Python> Output numbers from 1 to 100, 501 to 600> For csv
Notes for using python (pydev) in eclipse
Atcoder standard input set for beginners (python)
Overwrite download file for python selenium Chrome
[Python] Chapter 02-03 Basics of Python programs (input / output)
2016-10-30 else for Python3> for:
python [for myself]
Python scraping notes
Script python file
Python study notes _000
Python learning notes
Python beginner notes
python learning output
Python study notes_006
[Python] Standard input
python C ++ notes
Python study notes _005
Python grammar notes
Python Library notes
python personal notes
python pandas notes
Python study notes_001
python learning notes
Python3.4 installation notes
I made a python dictionary file for Neocomplete
Output python log to both console and file
Notes for implementing simple collaborative filtering in Python
2017-02-19 Python> Link> Redirect to output file immediately> sys.stdout.flush ()
Speed evaluation of CSV file output in Python
About Python for loops
File operations in Python
Key input in Python
[Python] File / directory operations
missingintegers python personal notes
[Note] File reading ~ Python ~
Python basics ② for statement
File processing in Python
Key input that does not wait for key input in Python
Automatically execute python file
[Python] Output battles and combinations (nesting for statements and if statements)
Reading pyc file (Python 3.5.2)
About Python, for ~ (range)
python decorator usage notes
python textbook for beginners