- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
为了解决这个错误,我已经做了很多事情,但我已经干涸了。有人知道为什么我总是收到此错误吗?
myList =[n, weather, wind, other, avgscore]
with open("data.txt", 'w') as f:
for s in myList:
f.append(str(s) + '\n')
print("Thank you, your data was logged")
最佳答案
您需要使用 write()
而不是 append()
:
myList =['n', 'weather', 'wind', 'other', 'avgscore']
with open("list.txt", 'w') as f:
for s in myList:
f.write(str(s) + '\n')
print("Thank you, your data was logged")
如果您想将数据 append 到已写入的文件而不是覆盖它:
You need to open the file in append mode, by setting "
a
" or "ab
" as the mode.
myList =['n2', 'weather2', 'wind2', 'other2', 'avgscore2']
with open("list.txt", 'a') as f:
for s in myList:
f.write(str(s) + '\n')
print("Thank you, your data was logged")
输出:
n
weather
wind
other
avgscore
n2
weather2
wind2
other2
avgscore2
关于python - 为什么我会收到此错误? '_io.TextIOWrapper' 对象没有属性 'append',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55161828/
我正在尝试为 SiRF 二进制消息设置换行符,但 IO 包装器似乎不接受换行符。 代码: import serial import io port = serial.Serial(port='/dev
我想从头开始寻找要写入的文件的开头。在 python 3.9 的文档中 io.IOBase.seek它显示 seek 有一个参数“whence”,但显示错误: TypeError: TextIOWra
运行我的代码时,我不断收到错误消息: TypeError: object of type '_io.TextIOWrapper' has no len() function 我如何让它打开/读取文件并
我使用下面的代码阅读文本格式, f = open("document.txt", "r+", encoding='utf-8-sig') f.read() 但是f的类型是 _io.TextIOWrap
我在尝试编译以下程序时收到错误消息。目标是分析非线性摆和一个特定庞加莱截面的行为。我尝试将摆的行为数据打印到一个文件,并将对应于庞加莱部分的输出打印到另一个文件。 Python shell 中列出的错
我对 Python 还很陌生。我正在尝试学习如何创建模块和导入函数,所以这是在两个文件中的原因是因为我在玩弄它。在我看来,这不是问题所在,但我想我应该在其中添加一些背景故事以防相关。 我知道我的格式和
我尝试逐行读取子流程: proc = subprocess.Popen(self.monitor_logcat_cmd, shell=True, stdout=subprocess.PIPE,
所以我尝试创建一个文本 io 包装器,然后我可以使用 readlines() 进行单元测试。这是我的尝试,但是当我运行它时 readlines() 什么也不返回: output = io.BytesI
代码应该做的主要功能是打开文件并获取中位数。这是我的代码: def medianStrat(lst): count = 0 test = [] for line in lst:
如何包装一个开放的二进制流——一个 Python 2 file、一个 Python 3 io.BufferedReader、一个 io.BytesIO——在 io.TextIOWrapper 中? 我
我尝试打开一个dat文件,但遇到UnicodeDecode错误。 请参阅以下我尝试过的代码。 with open(dat_file, 'r') as f: (or) with open(dat_f
为了解决这个错误,我已经做了很多事情,但我已经干涸了。有人知道为什么我总是收到此错误吗? myList =[n, weather, wind, other, avgscore] with op
我收到一个错误 File.open(classname+'.txt','a') AttributeError: '_io.TextIOWrapper' object has no attribute
如果我在 python 3 中运行以下代码 from io import BytesIO import csv from io import TextIOWrapper def fill_into_s
我编写了以下代码来读取压缩目录中的文本文件。因为我不想要以字节为单位的输出,所以我添加了 TextIOWrapper 以将输出显示为字符串。假设这是逐行读取 zip 文件的正确方法(如果不让我知道),
我正在尝试运行堆栈溢出中提供的示例 here . 我又把代码复制过来了: from sklearn.feature_extraction.text import TfidfVectorizer tex
我正在尝试在 this post 之后子类化 io.TextIOWrapper ,虽然我的目标不同。从这个开始(注意:motivation): class MyTextIOFile(io.TextIO
我想使用以下代码 > 打开一个文件 > 读取内容并去除不需要的行 > 然后将数据写入文件并读取文件以供下游分析。 with open("chr2_head25.gtf", 'r') as f,\
我有一个文本文件,我们称它为 goodlines.txt,我想加载它并创建一个包含文本文件中每一行的列表。 我尝试像这样使用 split() 过程: >>> f = open('goodlines.t
完整代码如下: from Crypto.Protocol.KDF import scrypt from Crypto.Cipher import AES from Crypto.Random impo
我是一名优秀的程序员,十分优秀!