我写了一些代码:
def ICP(x):
numofrepeat=0
warning=0
while numofrepeat<len(str(x)) or (x[numofrepeat]==2) or (x[numofrepeat]==3) or (x[numofrepeat]==5) or (x[numofrepeat]==7):
if (x[numofrepeat]==0):
warning=warning+1
if warning>1:
numofrepeat=len(x)
我需要些帮助。想弄清楚到底是什么问题。
parse = json.loads(phoneget.text)
phoneNUM = parse["tel"] # gets phone number
phoneID = parse["idNum"] # gets id number
print(sms_config.key) # ignore this
print("Parse complete, here is your result:") # ignore this
既然range对象是可订阅的,为什么itertools.repeat对象不能订阅?
In [10]: range(3, 10)[3]
Out[10]: 6
In [11]: import itertools as it
In [12]: it.repeat(5)[3]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython
嘿,伙计们,我发现了一个错误:
Traceback (most recent call last):
File "/Applications/Wing101.app/Contents/MacOS/src/debug/tserver/_sandbox.py", line 1, in <module>
# Used internally for debug sandbox under external interpreter
File "/Applications/Wing101.app/Contents/MacOS/src/debug/tser
当我运行以下代码时,它显示了一个TypeError
a = int(input("Enter the iteration value:"))
b=[]
for c in range[0,a]:
d=int(input("Enter:"))
b.append(d)
f=0
for e in b:
f = f + e
print f
它显示了以下错误
Enter the iteration value:5
Traceback (most recent call last):
File "/var/app/eclip
注意:我知道python是强类型的,我们不会连接2种不同的类型。但我无意中尝试了,
我得到了不同的结果,
a = []
>>>a=a+1 #it gives me expected concatenate error
TypeError: can only concatenate list (not "int") to list
>>>a+=1 #but this wasn't
TypeError: 'int' object is not iterable
我生成了将数据从数组保存到文件的代码,如下所示:
with open(path + '/data_Sevol.csv', 'w', newline='') as csvfile:
fieldnames = ['Sevol']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for i in range(len(Sevol)):
writer.writerow({'
我在python中试验tuple时,偶然发现了这个问题。 t=tuple("2",) # works 但是 t=tuple(1,) # fails with error TypeError: 'int' object is not iterable 鉴于 t=(1,) # works 有人能解释一下为什么会这样吗?
大家好,我真的是个新手,到python,我只是写了一段代码,打开Whatsapp
你给它一个人的名字和信息,然后发送多少次你想要的。
但是,当我开始调试代码时,它给了我以下内容:
Exception has occurred: TypeError 'WebElement' object is not subscriptable File "E:\Iliya\My Courses\Python\Projects\Whatsapp Robot\Whatsapp_Bot.py", line 15, in <module> msg = driver.find
我试图将数据从CSV文件中获取到Python中的列表中。到目前为止,这就是我所拥有的:
import csv
with open('RawEirgrid2.csv','rb') as csvfile:
M = csv.reader(csvfile, delimiter=',')
print(M[0])
我试图打印列表中的第一项,只需确认代码是否有效(目前没有)。我得到以下错误:
TypeError:“_csv.reader”对象不可订阅
在我看的每一个例子中,它看起来应该是可订阅的,所以我不确定发生了什么。
我执行这段代码时出错了-
for I in len(str_list):TypeError:'int‘对象不是可迭代的
我该怎么解决呢?(Python 3)
def str_avg(str):
str_list=str.split()
str_sum=0
for i in len(str_list):
str_sum += len(str_list[i])
return str_sum/i
我正在做一个小函数,它应该按照姓氏的字母顺序对学位进行排序(“如果两个人的姓氏相同,也可以使用名字),并且我堆叠了错误"TypeError:'NoneType‘对象不可订阅。
我以前从未见过这个错误,所以我不知道它是什么意思。
def degreescheem(listing,x):
printed=False
temporlist=[]
for i in listing:
if i[3] == x :temporlist.append(i)
slist=sorted(temporlist,key=lambda s:(s[4],s[5]))
for j in slist :
因此,我在python中编写了这个简单的程序,它的函数名为num,函数以两个参数作为整数,并检查其中是否存在"20“,如果是,则返回True,否则返回False,您会注意到,在if语句中,我调用了另一个函数sum,它是python中内置的函数,所以当我试图传递函数中的a和b的值而不将它们作为元组传递时,它会给出下面提到的错误。所以我的问题是,当我像这个sum((a,b))而不是这个sum(a,b)传递它们时,它为什么会工作呢?
File "c.py", line 8, in <module>
print(num(220,10))
File
将None传递给Python的list构造函数是一个TypeError
>>> l = list(None)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'NoneType' object is not iterable
但是,使用方括号实例化list是很好的;在内置函数中使用None也很好:
>>> l = [None]
>>> l.append(None)
&
所以问题很简单:如果我们有一个随机类,比方说一个int,我们尝试访问一个未定义的属性:
my_int = 5
my_int.this_is_a_test
我们将得到以下错误:
AttributeError: 'int' object has no attribute 'this_is_a_test'
但是,如果我们尝试访问它的索引(在这种情况下,Python将查找__getitem__属性):
my_int = 5
my_int[0]
我们得到:
TypeError: 'int' object has no attribute '__ge
在python中,我得到了这个错误:
TypeError: 'int' object is unsubscriptable
这发生在代码行上:
sectorcalc[i][2]= ((today[2]/yesterday[2])-1)
我在任何地方都找不到一个好的定义来定义python的不可订阅。
for quote in sector[singlestock]:
i+=1
if i < len(sector):
if i==0:
sectorcalc[i][0]= quote[0]
在处理Python数据时,我遇到了一个很容易再现的奇怪错误。
from __future__ import annotations
import dataclasses as dc
import typing
@dc.dataclass
class Test:
foo: dc.InitVar[int]
print(typing.get_type_hints(Test))
运行此操作将获得以下内容:
Traceback (most recent call last):
File "test.py", line 11, in <module>
我想将JSONEncoder扩展为调用对象的__json__,以将其转换为可序列化的东西。
我试过这个:
import json
class Foo(object):
def __json__(self):
return dict(a=1, b=2)
class MyJSONEncoder(json.JSONEncoder):
"""
Use __json__ attr or callable of object for JSON serialization.
"""
在文件中的列表中,我试图得到两个被划分的新列表:子集A和子集B。这意味着子集A中的元素(整数)应该等于子集B (这个程序使用回溯来解决问题)。然而,我得到了:
Subset A: <map object at 0x311b110>
Subset B: <map object at 0x311b190>
还有一个错误:
line 93, in getSuccessors
cfgA.subA.append(config.input[config.index])
TypeError: 'map' object is not subscript
我不明白为什么我要得到一个TypeError:'int‘对象是不可迭代的
first_age = int(input("Enter your age: "))
second_age = int(input("Enter your age: "))
total = sum(first_age, second_age)
print("Together you're {} years old".format(total))
Enter your age: 1
Enter your age: 1
---------------------
我想用Mockito模拟ConfigParser类来执行一个简单的测试:
from configparser import ConfigParser
from unittest import TestCase
from mockito import when, mock, verify
section = "SETTINGS"
# Here is an example function to test
def get_config():
ini_file = "settings.ini"
parser = ConfigParser()
下面的代码给出了错误Python
TypeError: 'int' object is not iterable:
代码:
hosts = 2
AppendMat = []
Mat = np.zeros((hosts,hosts))
Mat[1][0] = 5
for i in hosts:
for j in hosts:
if Mat[i][j]>0 and Timer[i][j]>=5:
AppendMat.append(i)
我怎么才能修复这个错误-
TypeError: 'int' object
因此,我尝试使用线程模块,以了解它的基础知识,当我运行我的代码时,我得到一个错误,没有清楚地说明我做错了什么。下面是代码,你可以在下面找到错误日志:
import threading
import time
start = time.perf_counter()
def square(y):
print('Starting processing')
for x in range(y):
i = x * x
print(f'Done processing {i}')
threads = []
# creating
当我试图加载我的类别时,我得到了下面的错误。发布的值是“1”,并且存在于DB中,
TypeError at /events/add/
int() argument must be a string or a number, not 'Category'
Request Method: POST
Request URL: http://127.0.0.1:8000/events/new/
Django Version: 1.4
Exception Type: TypeError
Exception Value:
int() argume