pickle - Get Python to output a .py file from a dictionary? -


how can python output , save .py file has been generated dictionary?

for example want produce file dynamically:

file.py:

import time  project_name = "your_project_name" user = "test user" 

from following dictionary:

{'project_name': 'your_project_name', 'user': 'test'} 

this have tried:

 open('file.py', 'wb') handle:             pickle.dump(values, handle) 

but gave:

(dp0 s'project_name' p1 s'user' p2 

try this

with open('file.py', 'wb') handle:     handle.write("{")     k,v in your_dict.iteritems():         handle.write("'%s' : '%s'," % (k,v))     handle.write("}\n")     

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -