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.
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())
#Easy join with join function
"-".join(["foo", "bar", "baz"])
>>> 'foo-bar-baz'
# "%s"Easy to replace with
"%s, %s, %s!" % ("one", "two", "three")
>>> 'one, two, three!'
Recommended Posts