错误“ str”对象没有属性“ isnumeric”“

时间:2019-05-27 23:47:56

标签: python

运行我的python代码时,我得到以下结果。我是python的新手,不知道发生了什么事??

[ec2-user@ip-172-31-34-90 ~]$ vi +11 readodd1.py                                [ec2-user@ip-172-31-34-90 ~]$ cat numberstrin.txt|tr '|' '\t'| python readodd1.py
Traceback (most recent call last):
  File "readodd1.py", line 11, in <module>
    if(i.isnumeric()):
AttributeError: **'str' object has no attribute 'isnumeric'**
[ec2-user@ip-172-31-34-90 ~]
#!/usr/bin/python
import sys

resultNumbers = []

for line in sys.stdin :
    listA = line.split(" ")

    for i in listA:
        **if(i.isnumeric()):**
            **if(int(i)%2!=0):**
                if(i not in resultNumbers):
                    resultNumbers.append(int(i))

# print the odd numbers
print("The odd numbers in input : "+ str(resultNumbers))
#!/usr/bin/python
import sys

    for i in listA:
        if(i.isnumeric()):
            if(int(i)%2!=0):

# print the odd numbers
print("The odd numbers in input : "+ str(resultNumbers))

0 个答案:

没有答案