Q : TypeError : '_csv.reader'개체를 호출 할 수 없습니다.

밥 틴

이 오류가 계속 발생합니다. 누구든지 해결할 수 있습니까? 아래에서 문제가되는 코드 줄을 강조 표시했습니다. 독자 변수를 reader1로 변경하려고 시도했지만 문제가 지속됩니다.

에러 메시지

역 추적 (가장 최근 호출 마지막) :

파일 "dna.py", 20 행, in

독자 = 독자 (peoplefile)

TypeError : '_csv.reader'개체를 호출 할 수 없습니다.

**

  • 내 코드

**

from sys import argv

from csv import reader, DictReader



if len(argv) < 3:

print("Wrong number of arguments")

exit()



#read the database file into memory

with open(argv[2]) as file:

reader = reader(file)

for row in reader:

dnalist = row



#create a variable containing the sample DNA

dna = dnalist[0]

#create a dictionary that holds the STR and the highest rep count

sequences = {}



with open(argv[1]) as peoplefile:

reader = reader(peoplefile) **<------ ERROR IS HERE**

for row in reader:

dnasequences = row

dnasequences.pop(0)

break

#set the STRs as keys in sequences dictionary

for i in dnasequences:

sequences[i] = 1



#Obtain the highest number of reps of each STR in the given DNA sequence

for key in sequences:

l = len(i)

tmp = 0

tmpmax = 0

#check

for i in dna:

if dna[i: i + l] == key:

tmp = 1

while dna[i:i+l] == dna[ i+l : i+2*l ]:

tmp += 1

i += l

if tmp > tmpmax:

tmpmax = tmp

sequences[key] = tmpmax



#Read database file into a dictionary

with open(argv[1]) as peoplefile:

reader = DictReader(peoplefile)

#loop through STR counts, comparing it to each person's STR counts

for person in reader:

match = 0

for i in sequences:

if sequences[i] == int(person(i)):

match += 1

#if all the highest STR reps match the person, print that person's name

if match == len(sequences):

print(row['name'])

exit()


print("Does not match any person")
앤드류 스톤

실행하려고 할 때 reader = reader(peoplefile)실제로 reader이전 코드 줄에서 가져 옵니다 reader = reader(file).

즉, 오류 줄이 다음과 같이 실행하려고합니다.

reader = reader(file)(reader(peoplefile))

같은 이름의 함수를 변수로 사용하지 마십시오. csv_reader대신 변수로 사용 reader하면 문제가 해결됩니다.

...
# read the file into memory
with open(argv[2]) as file:    
    csv_reader = reader(file)    
    for row in csv_reader:    
        dnalist = row
...
with open(argv[1]) as peoplefile:
    csv_reader = reader(peoplefile)

편집하다

나는 무슨 일이 일어나고 있는지 더 잘 설명하기 위해 예를 생각해 냈습니다.

문자열로 변환하려는 숫자가 있고이를 str이라는 새 변수로 설정 한 다음 인쇄한다고 가정 해 보겠습니다.

x = 279
str = str(x)
print(str)

이 코드는 구문 상 정확하지만 다른 숫자가 있고이를 문자열로 변환하여 인쇄하려는 경우와 같이 코드의 뒷부분에서 벗어날 수 있습니다.

x = 279
str = str(x)
print(str)

y = 441
str = str(y)
print(str)    # TypeError here

함수와 이름이 같은 변수 이름을 사용하면 해당 함수를 덮어 쓰고 다음에 함수를 호출하려고 할 때 실제로 변수를 호출합니다.

2 부

그리고 그것을 보는 또 다른 방법으로, 더 많은 예가 더 나은 것으로 생각합니다.

사용 하면 함수를 호출하는 import csv데 사용해야 csv.reader()합니다.

import csv

with open('example.txt') as file:
    reader = csv.reader(file)
    for line in file:
        print(line)
    
with open('second_example_text.txt') as file:
    reader = csv.reader(file)
    for line in file:
        print(line)

이 경우 reader함수를 덮어 쓰지 않기 때문에 원하는만큼 사용할 수 있습니다.csv.reader

도움이 되었기를 바랍니다.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

TypeError : '_IncompatibleKeys'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'CurrencyConverter'개체를 호출 할 수 없습니다.

분류에서Dev

firebase = firebase (config) TypeError : 'module'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

분류에서Dev

TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

분류에서Dev

TypeError : 'Int64Index'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Player'개체는 Django를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Post'개체를 호출 할 수 없습니다.

분류에서Dev

groupby-TypeError 'DataFrame'개체를 호출 할 수 없습니다.

분류에서Dev

Python Script TypeError : 'int'개체를 호출 할 수 없습니다.

분류에서Dev

Python 오류 : TypeError : 'list'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : '게임'개체를 호출 할 수 없습니다.

분류에서Dev

Python / Pygame : TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

Python-TypeError : 'list'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Weather'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'Aircraft'개체를 호출 할 수 없습니다.

분류에서Dev

Python TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

django-selenium TypeError : 'str'개체를 호출 할 수 없습니다.

분류에서Dev

Python setter TypeError : 'int'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : print를 호출 할 때 'str'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 스크래핑 할 때 'NoneType'개체를 호출 할 수 없습니다.

분류에서Dev

TypeError : 'numpy.float64'개체를 호출 할 수 없습니까?

분류에서Dev

TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

분류에서Dev

'모듈'개체의 TypeError는 호출 할 수 없습니다.

분류에서Dev

TypeError at / 'SimpleLazyObject'개체는 호출 할 수 없습니다.

분류에서Dev

Python timeit-TypeError : '모듈'개체를 호출 할 수 없습니다.

분류에서Dev

Pytorch 1.7.0 | DataLoader 오류-TypeError : '모듈'개체를 호출 할 수 없습니다.

Related 관련 기사

  1. 1

    TypeError : '_IncompatibleKeys'개체를 호출 할 수 없습니다.

  2. 2

    TypeError : 'NoneType'개체는 CircleCI를 호출 할 수 없습니다.

  3. 3

    TypeError : 'CurrencyConverter'개체를 호출 할 수 없습니다.

  4. 4

    firebase = firebase (config) TypeError : 'module'개체를 호출 할 수 없습니다.

  5. 5

    TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

  6. 6

    TypeError : '목록'개체를 호출 할 수 없습니다-assertWarns ()

  7. 7

    TypeError : 'Int64Index'개체를 호출 할 수 없습니다.

  8. 8

    TypeError : 'Player'개체는 Django를 호출 할 수 없습니다.

  9. 9

    TypeError : 'Post'개체를 호출 할 수 없습니다.

  10. 10

    groupby-TypeError 'DataFrame'개체를 호출 할 수 없습니다.

  11. 11

    Python Script TypeError : 'int'개체를 호출 할 수 없습니다.

  12. 12

    Python 오류 : TypeError : 'list'개체를 호출 할 수 없습니다.

  13. 13

    TypeError : '게임'개체를 호출 할 수 없습니다.

  14. 14

    Python / Pygame : TypeError : '모듈'개체를 호출 할 수 없습니다.

  15. 15

    Python-TypeError : 'list'개체를 호출 할 수 없습니다.

  16. 16

    TypeError : 'Weather'개체를 호출 할 수 없습니다.

  17. 17

    TypeError : 'Aircraft'개체를 호출 할 수 없습니다.

  18. 18

    Python TypeError : '모듈'개체를 호출 할 수 없습니다.

  19. 19

    TypeError '모듈'개체를 호출 할 수 없습니다.

  20. 20

    django-selenium TypeError : 'str'개체를 호출 할 수 없습니다.

  21. 21

    Python setter TypeError : 'int'개체를 호출 할 수 없습니다.

  22. 22

    TypeError : print를 호출 할 때 'str'개체를 호출 할 수 없습니다.

  23. 23

    TypeError : 스크래핑 할 때 'NoneType'개체를 호출 할 수 없습니다.

  24. 24

    TypeError : 'numpy.float64'개체를 호출 할 수 없습니까?

  25. 25

    TypeError : 'str'개체는 MySQL에서 호출 할 수 없습니다.

  26. 26

    '모듈'개체의 TypeError는 호출 할 수 없습니다.

  27. 27

    TypeError at / 'SimpleLazyObject'개체는 호출 할 수 없습니다.

  28. 28

    Python timeit-TypeError : '모듈'개체를 호출 할 수 없습니다.

  29. 29

    Pytorch 1.7.0 | DataLoader 오류-TypeError : '모듈'개체를 호출 할 수 없습니다.

뜨겁다태그

보관