I have a dictionary that I would like to load from a file into a class variable. The dictionary holds configuration data. I would have different files for different configurations. I was wondering if there is a way to do this? I found pickle but that saves an existing instance as a copy so it can be loaded later.

Recommended Answers

All 3 Replies

Could you give me an example? I think I have an idea what you mean, but I'm not sure.

self.movement = {"run" : {"run1" : (45, 55, 110, 120)
                           "run2" : (45, 55, 110, 130)
                           "run3" : (45, 55, 110, 140)}}

I would like load the dictionary run from a file so I could just change the values in the file. These values will not change during the runtime of the program.

Actually, cPickle does both saving and loading, with cPickle.dump and cPickle.load respectively.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.