어제이 코드의 다른 부분을 게시했지만 다른 문제가 발생했습니다. RPG 용 캐릭터 생성기를 만들었고 .txt 파일에 문자 시트 함수의 출력을 얻으려고 시도했지만, 무슨 일이 일어 났는지는 함수가 통계의 일부에 대해 None
값을 반환 할 수 있다고 생각합니다. 완전히 정상적입니다.) 그리고 .txt 파일에 쓰려고 할 때 오류가 발생합니다. 나는 완전히 엉망이되어 도움을 크게 받았다.대부분이 파일에 인쇄하는이 함수를 어떻게 작성합니까?
# Character Sheet Function.
def char_shee():
print "Name:", name
print "Class:", character_class
print "Class Powers:", class_power
print "Alignment:", alignment
print "Power:", pow, pow_mod()
print "Intelligence:", iq, iq_mod()
print "Agility:", agi, agi_mod()
print "Constitution:", con, con_mod()
print "Cynicism:", cyn, cyn_mod()
print "Charisma:", cha, cha_mod()
print "All Characters Start With 3 Hit Dice"
print"""
\t\t{0}'s History
\t\t------------------
\t\tAge:{1}
\t\t{2}
\t\t{3}
\t\t{4}
\t\t{5}
\t\t{6}
\t\t{7}
\t\t{8}
\t\t{9}
\t\tGeneral Disposition: {10}
\t\tMost important thing is: {11}
\t\tWho is to blame for worlds problems: {12}
\t\tHow to solve the worlds problems: {13}
""".format(name, age, gender_id, ethnic_pr, fcd, wg, fogo_fuck, cur_fam,fam_fuk, nat_nur, gen_dis, wha_wor, who_pro, how_pro)
char_shee()
print "Press enter to continue"
raw_input()
# Export to text file?
print """Just because I like you, let me know if you want this character
saved to a text file. Please remember if you save your character not to
name it after something important, or you might lose it.
"""
text_file = raw_input("Please type 'y' or 'n', if you want a .txt file")
if text_file == "y":
filename = raw_input("\nWhat are we calling your file, include .txt")
target = open(filename, 'w')
target.write(char_shee()
target.close
print "\nOk I created your file."
print """
Thanks so much for using the Cyberpanky N.O.W Character Generator
By Ray Weiss
Goodbye
"""
else:
print """
Thanks so much for using the Cyberpanky N.O.W Character Generator
By Ray Weiss
Goodbye
"""
편집 : 다음은 출력 내가 얻을 :
> Please type 'y' or 'n', if you want a .txt filey
>
> What are we calling your file, include .txt123.txt <function char_shee
> at 0x2ba470> Traceback (most recent call last): File "cncg.py", line
> 595, in <module>
> target.write(pprint(char_shee)) TypeError: must be string or read-only character buffer, not None
실제 오류 추적을 제시해주십시오. – geoffspear
또한'target.close'는 아무 것도하지 않습니다. 'target.close()'는 무언가를합니다. – mgilson
그냥 충고 만 해보자. 포맷 할 항목이 두 개 이상 있다면 '... {blah} {foo} {bar} ...'형식을 사용하라. (blah = ..., foo = ... , bar = ...)'구문을 사용하면 나중에 감사 할 것입니다. –