프로그래밍에 익숙하지 않고 사용자 데이터 파일을 만들려고합니다. 데이터를 수집하여 텍스트 파일에 쓰는 방법을 알고 있지만 각 파일의 이름을 사용자의성에 독립적으로 지정하고 싶습니다. 다음은 내가 지금까지 가지고있는 것입니다 :Python에서 사용자 입력 파일의 이름을 지정하는 방법
fname=raw_input('Competitor forename : ')
sname=raw_input('Competitor surname : ')
email=raw_input('Email address : ')
phone=int(raw_input('Phone : '))
enter=raw_input('Have you already completed any games? (Yes/No) : ')
if enter=='yes':
dcurrent=raw_input('Please tell us your current division : ')
pcurrent=int(raw_input('Please tell us your current points : '))
print'Thank you'
else:
print'Welcome to the staff and postgraduate squash league'
d=open(fname,'w')
d.write(fname)
d.write(sname)
d.write(email)
d.close()
이 코드는 파일을 만들 때 오류 메시지를 반환합니다. 다른 모든 시도는 단순히 txt 파일 (sname)이라는 결과를 낳았습니다.
도와주세요!
안녕하세요! 오류가 무엇입니까? – msturdy
붙여 넣을 때이 코드를 실행해도 오류가 발생하지 않습니다 (문자가 들어있는 전화 번호를 선택하는 것 말고는). 이 코드가 실행중인 실제 코드입니까? – ikanobori