KevinFire2030 / Fire2025

0 stars 0 forks source link

TypeError: _IOBase.writelines() takes exactly one argument (3 given) #14

Open KevinFire2030 opened 1 year ago

KevinFire2030 commented 1 year ago
import sys
f = open("buy_list.txt", "wt", encoding='UTF8')
buy_list = [0, 1, 2, 3, 4, 5]
for code in buy_list:
    f.writelines("매수;", code, ";시장가;10;0;매수전")
f.close()
Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2022.3.2\plugins\python-ce\helpers\pydev\pydevconsole.py", line 364, in runcode
    coro = func()
  File "<input>", line 2, in <module>
TypeError: _IOBase.writelines() takes exactly one argument (3 given)
KevinFire2030 commented 1 year ago
from

f.write(info[0], "\t", info[1], "\t\t\t $" + str(info[2]))
to :

f.write(f'{info[0]}\t{info[1]}\t\t\t ${info[2]})
KevinFire2030 commented 1 year ago
buy_list = ['삼성전자', '카카오']
for code in buy_list:
    f.writelines(["매수;", code, ";시장가;10;0;매수전"])
f.close()
KevinFire2030 commented 1 year ago
writelines() 구문

file.writelines(list)

[매개변수]

list
필수. 삽입될 텍스트 (또는 byte 객체)의 List

writelines() 예제 - 파일에 List 요소 줄바꿈 후 쓰기

f = open("hz.txt", "a", encoding='UTF-8')

f.writelines(["\n홈짱닷컴", "\nHomzzang.com"])

f.close()

f = open("hz.txt", "r", encoding='UTF-8')

print(f.read())

결과값: 

홈짱닷컴

Homzzang.com