[Tutor] Help with file editing
lie.1296 at gmail.com
Thu Jun 11 20:19:15 CEST 2009
tanner barnes wrote:
> Ok, so i am creating a program for my school's football team and in one
> part i need to store a list of variables (their name, height, weight,
> and grade) in a txt file to bring up later. i know how to create and
> read from files ( file = open("file_name", ''w/r/a") ). But what i need
> to do is create a individual file for each member on the roster as they
> add them in. here is my code:
> name = self.name.GetValue() < gets their name from the text box
> stats = str(self.name.GetValue()) + "\n" < gets their name
> to put into the file
> stats += str(self.height.GetValue()) + "\n" < gets their height
> stats += str(self.weight.GetValue()) + "\n" < gets their weight
> stats += str(self.grade.GetValue()) + "\n" < gets their grade
> info = open(name + ".txt", "r") < this creates the file for it
> to all go into using the name we get from above to name it.
> But when a try and write into the file wright after that last line it
> wont let me so is there anything i'am missing or should change?
You opened the file with mode "r"ead-only. Use mode "w"rite or "a"ppend.
More information about the Tutor