Pickle Problem

Sönmez Kartal sonmez_programming at nerdshack.com
Thu Mar 15 11:30:26 EDT 2007


Hi,

You should write your last two lines as ...

	x = DemoClass()
	x.WriteToFile()

Don't miss paranthesis again... :)

Maybe there are still some mistakes too. Does dump method writes list's 
elements?

Sönmez

tonyr1988 wrote:
> I'm a complete python n00b writing my first program (or attempting to,
> anyway). I'm trying to make the transition from Java, so if you could
> help me, it would be greatly appreciated. Here's the code I'm stuck on
> (It's very basic):
> 
> class DemoClass:
> 	def __init__(self):
> 		self.title = ["Hello", "Goodbye"]
> 
> 	def WriteToFile(self, path = "test.txt"):
> 		fw = file(path, "w")
> 		pickle.dump(self.title, fw)
> 		fw.close()
> 
> if __name__=='__main__':
> 	x = DemoClass
> 	x.WriteToFile
> 
> It doesn't do any file I/O at all (that I see). I hope my syntax is
> alright. If I just call WriteToFile, shouldn't it perform with the
> default path? It gives me no errors and pretends to execute just fine.
> 




More information about the Python-list mailing list