Search code examples
python-2.7modulepy2exerewriting

how to use py2exe when rewriting an imported module (and using the rewritten version)


i got some problems using py2exe and didn't find an answeryet. i wrote a little quizz programm and i'm importing a module questions.py with all my questions and answers in it.
Before the quizzing start, you can press a button and define new questions and answers. Doing this i rewrite my questions.py file and i also reload it at the end (not using classes, so no problems with that).
when i use py2exe on my program, he can't rewrite questions.py.
ofcourse the program uses now another file.

Is it possible to rwrite this new file of the imported questions.py and if so, can i still use python language to rewrite it?

extra information about my program you may (or may not) need to know:
using Tkinter as GUI for my program and getting the new questions from an Entry box.
using python 2.7
if you need a piece of code, ask and i'll post it.

thanks to everyone already, if i didn't put enough information at all, srry it's my first time asking a Q at a forum myself


Solution

  • While there will be some way of repackaging the exe file to include your new questions.py, it will most certainly be very complex, so I suggest that you rethink your strategy entirely.

    Although python allows a great deal of self-modification and makes code generation easy, this kind of task is generally accomplished by including a external file with questions stored in some serialized format, such as XML, JSON or YAML.

    You can read this file when you start your program, and write to it when you save the new questions. If you're not familiar with any of these formats, you should probably use JSON, as it's the most similar to the usual python syntax for data-structures. Here's a good tutorial for the json module