Movatterモバイル変換


[0]ホーム

URL:


Newbie programmer needs a little help

Alex Martellialeaxit at yahoo.com
Fri Apr 20 13:03:00 EDT 2001


"Lars Urlich" <wildchild07770 at yahoo.com> wrote in messagenews:mailman.987719961.17028.python-list at python.org...    [snip]> filename = raw_input("Please enter a path/filename: ")> filename = openThe second one of these lines re-binds variable'filename' -- it's now bound to function objectalso called 'open', and whatever the user didenter is forgotten.  Remove the second one ofthese two statements... it serves no purpose!> print "Following are several character options"> playername = raw_input("What is your name? ")> charname = raw_input("Enter your character name: ")> nature = raw_input("What is the nature of your> character? ")> demeanor = raw_input("What is your demeanor? ")> info = [playername, charname, nature, demeanor]> print infoSo far so good. but now:> file = open(filename, list[0:3] "r")the "list[0:3]" part is incomprehensible to me.And the "r" is incorrect if you want to WRITE.file = open(filename, "w")is probably what you want here.> filename, "r"This expression just gets thrown away.  Nothinghas been written.  You need to write the stringsin the list 'info' to the file you've opened!Assuming you want newline characters after eachone of them, for example:for line in info:    file.write(line)    file.write('\n')and now that you're done, you'd better also do:file.close()(The last isn't strictly necessary, but...).Alex


More information about the Python-listmailing list

[8]ページ先頭

©2009-2025 Movatter.jp