小编use*_*343的帖子

AttributeError:'str'对象没有属性'iteritems'

我正在尝试编写一个写入Google Docs Spreadsheet的脚本,当我运行它时,我会在标题中看到错误.进一步来说:

File "/home/pi/Desktop/templog.py", line 44, in <module>
    s.run()
  File "/usr/lib/python2.7/sched.py", line 117, in run
    action(*argument)
  File "/home/pi/Desktop/templog.py", line 35, in do_something
    entry = spr_client.InsertRow(data_str, spreadsheet_key, worksheet_id)
  File "/usr/local/lib/python2.7/dist-packages/gdata/spreadsheet/service.py", line 330, in          InsertRow
for k, v in row_data.iteritems():
AttributeError: 'str' object has no attribute 'iteritems'
Run Code Online (Sandbox Code Playgroud)

造成这种情况的代码是:

entry = spr_client.InsertRow(data_str, spreadsheet_key, worksheet_id)
        if isinstance(entry, gdata.spreadsheet.SpreadsheetsList):
Run Code Online (Sandbox Code Playgroud)

attributeerror

5
推荐指数
1
解决办法
9369
查看次数

如何配对两个列表?

我是一个Python初学者,所以我很抱歉这是一个非常基本的问题.

我有两个数据列表,它们来自:

with filein as f:
        reader=csv.reader(f)
        xs, ys = zip(*reader)
Run Code Online (Sandbox Code Playgroud)

我想创建一个循环,它将取"xs"中的第一项和"ys"中的第一项并打印出来.然后我想循环回来并重复两个列表中的第二个项目等等.

我原以为:

for x in xs and y in ys:
Run Code Online (Sandbox Code Playgroud)

要么

for x in xs:
    for y in ys:
Run Code Online (Sandbox Code Playgroud)

但这些似乎都没有给出预期的结果.

python list

5
推荐指数
2
解决办法
3万
查看次数

如何忽略非浮点值

我有一个USB温度记录器,每隔30秒上传到Cosm.我遇到的问题是,每运行5分钟,当我运行命令时,它会报告文本错误而不是数字.

所以我试图找到一种方法来让它循环,直到它收到一个数字或只是忽略文本并恢复脚本(否则退出,否则).

我非常不优雅的解决方案是这样做:

  # convert regular error message to number
    if temp_C == "temporarily": # "temporarily" is used as it happens to be the 4th word in the error message
            temp_C = 0.0
Run Code Online (Sandbox Code Playgroud)

目前的代码是:

while True:
    # read data from temper usb sensor
    sensor_reading=commands.getoutput('pcsensor')

    #extract single temperature reading from the sensor

    data=sensor_reading.split(' ') #Split the string and define temperature
    temp_only=str(data[4]) #knocks out celcius reading from line
    temp=temp_only.rstrip('C') #Removes the character "C" from the string to allow for plotting

    # calibrate …
Run Code Online (Sandbox Code Playgroud)

python ignore

2
推荐指数
1
解决办法
1834
查看次数

标签 统计

python ×2

attributeerror ×1

ignore ×1

list ×1