Help us understand the problem. What is going on with this article?

MEMO20190911

今日も朝のお勉強をする

ファイル読み込み

point.txt

hogehoge,100,88,81
hugahuga,77,94,85
hagohago,80,52,99  

読み込むやつ

# OPEN SOURCE_FILES
open_file = open('./point.txt')
# READ FILES
raw_data = open_file.read()
# CLOSE SOURCE_FILES
open_file.close()

print(raw_data)

ファイル書き込み(上書きする)

書き込み(上書き)は'w'(write)でやる

# OPEN SOURCE_FILE write-mode
write_file = open('./write.txt', 'w')
# write DATA to SOURCE_FILE UWAGAKI
write_file.write('Hello World!\n')
# CLOSE SOURCE_FILE
write_file.close()

# readfile
read_file = open('./write.txt')
raw_data = read_file.read()
read_file.close()
print(raw_data)

# 変数open_filesにwrite.txtの内容を読み込む
# withの間はopenされる。終わったら自動で閉じる。
with open('./write.txt') as open_files:
    raw_data = open_files.read()

print(raw_data)

ファイル書き込み(追記)

追記は'a'(append)でやる

# Open and write(write-mode)
with open('./append.txt', 'w') as append_file:
    append_file.write('Hello World!\n')

# Open and write(append-mode)
with open('./append.txt', 'a') as tmp1:
    tmp1.write('Good Morning!\n')

# Open and read
with open('./append.txt')as tmp2:
    readfile = tmp2.read()

print(readfile)
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away