0

I'm a noob right now with pygame and I was wondering how to load a textfile, then strip that into a a single line. I believe that i would need to use the .rstrip('/n') function on my variable with the openned text file. But now, how do I turn this into a list? If I intentionally used two colons (::) to separate between my relevant pieces of information in the text file, how do I make it into a list with each list index being the contents in between two sets of ::? The purpose is to create save files in a menu GUI when closed, so is there a simpler way to save and open the contents of variables from one instance of the program to the next?

om-nom-nom
  • 62,329
  • 13
  • 183
  • 228

1 Answers1

1
>>> "foo::bar::baz".split("::")
['foo', 'bar', 'baz']

If you just want to save structured data, however, you might want to look at either the pickle or json libraries. Both of them give ways to dump Python objects to files and then load them back out again.

Amber
  • 507,862
  • 82
  • 626
  • 550