저는 현재 첫 번째 Python 노력을하고 있습니다. 친구가 작성한 일부 코드가 수정되었습니다. 파이썬 2.6.6을 사용하고 있습니다. 작동하는 원래 코드 조각은 신용 카드로 만든 비영리 단체의 기부금 데이터 로그 파일에서 정보를 추출합니다. 언젠가는 나의 새로운 버전이 페이팔에 의해 만들어진 기부금에 대해 동일한 작업을 수행 할 것입니다. 로그 파일은 비슷하지만 필드 이름과 다른 점이 다릅니다. 내가 갖는신비 "str '객체가 호출 가능하지 않습니다."python 오류
오류 메시지는 다음과 같습니다
역 추적 (가장 최근 통화 최종) : 파일 "../logparse-paypal-1.py", 라인 (196), convert_log에서 ( 파일 "../logparse-paypal-1.py", convert_log의 170 행 output = [output_fns에서 f에 대한 f (record, access_ids) 출력 = sys.argv [1], sys.argv [2], access_ids) ] TypeError : 'str'개체를 호출 할 수 없습니다.
이 오류와 관련된이 포럼의 게시물을 읽었습니다 메시지, 그러나 지금까지 나는 아직도 바다에있다. 문제가되는 객체 (access_ids)와 관련된 코드와 시작한 코드 사이에 필연적 인 차이점을 찾을 수 없습니다. access_ids 테이블과 관련된 모든 것은 스크립트가 일부 데이터를 무시하게 만든 테이블에서 발견 된 문제를 인쇄 한 줄을 제거하는 것이 었습니다. 아마도 나는 그 일을하는 동안 인물이나 무언가를 바꿨지 만, 나는 보았고 지금까지 아무 것도 찾을 수 없습니다.
출력 = output_fns에서 F에 대한 F (기록 access_ids)] 가 # Use the output functions configured above to convert the
# transaction record into a list of outputs to be emitted to
# the CSV output file.
print "Converting %s at %s to CSV" % (record["type"], record["time"])
output = [f(record, access_ids) for f in output_fns]
j = 0
while j < len(output):
os.write(csv_fd, output[j])
if j < len(output) - 1:
os.write(csv_fd, ",")
else:
os.write(csv_fd, "\n")
j += 1
convert_count += 1
print "Converted %d approved transactions to CSV format, skipped %d non-approved transactions" % (convert_count, skip_count)
if __name__ == '__main__':
if len(sys.argv) < 3:
print "Usage: logparse.py INPUT_FILE OUTPUT_FILE [ACCESS_IDS_FILE]"
print
print " INPUT_FILE Silent post log containing transaction records (must exist)"
print " OUTPUT_FILE Filename for the CSV file to be created (must not exist, will be created)"
print " ACCESS_IDS_FILE List of Access IDs and email addresses (optional, must exist if specified)"
sys.exit(-1)
access_ids = {}
if len(sys.argv) > 3:
access_ids = load_access_ids(sys.argv[3])
convert_log(sys.argv[1], sys.argv[2], access_ids)
라인 (170)이 하나 :
이러한 에러 메시지를 생성하는 코드의 일부는 다음과 같다 convert_log (sys.argv에 [1] sys.argv에 [2] access_ids)
access_ids 정의, possib :
라인 (196)이 하나 인 이 어떤 조언을 사전에
def access_id_fn(record, access_ids):
if "payer_email" in record and len(record["payer_email"]) > 0:
if record["payer_email"] in access_ids:
return '"' + access_ids[record["payer_email"]] + '"'
else:
return ""
else:
return ""
및
def load_access_ids(filename):
print "Loading Access IDs from %s..." % filename
access_ids = {}
for line in open(filename, "r"):
line = line.rstrip()
access_id, email = [s.strip() for s in line.split(None, 1)]
if not email_address.match(email):
continue
if email in access_ids:
access_ids[string.strip(email)] = string.strip(access_id)
return access_ids
감사 : 문제와 관련된 만민이있다.
- 데이브
문제를 보여주는 [* complete *] (http://sscce.org/#selfcon) 테스트 프로그램을 게시 할 수 있습니까? 대부분의 경우,'output_fn'의 값이 문제입니다. – phihag
문제는 output_fns가 문자열 목록이라는 것입니다.따라서 목록 이해 문장의 맥락에서 f()는 함수가 아니고 대신 문자열입니다. 170 줄 "print '% s'% output_fns" – user590028
@ user590028 바로 앞에 다음 print 문을 추가해보십시오. 그 줄을 추가했습니다. 여기에 내가 지금받는 메시지가 있습니다 : 파일 "../logparse-paypal-1.py", 줄 170, convert_log에 인쇄 '% s'% output_fns TypeError : 문자열 서식 지정 중에 모든 인수가 변환되지 않았습니다. –