[Python] How do I make a python script which can insert sections of code into a larger file?

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I have a code file for a game, and various mods of the game have been created (which affect that code file). The previous solution to this running mods is to have a separate full code file for each mod (even if only one line has been changed in the file).

    I want to be able to insert the modified code/sections of code into that main code file, which would thus allow me to apply multiple mods at once (as long as the modifications do not affect the same area of code).

    I have looked a bit into the difflib python library, but the problem is that after the first patch has been applied, the code under that patch could be offset (as the patch could either add lines or remove lines from whatever its replacing). This would defeat the whole purpose of this python script, as the patched being applied after the first one would all be incorrect and break the code.

    I also have looked at putting comments with identifiers in the main script, and the python file can look for them and replace what's between them. This solution does work, but I'm hoping to find a better solution, as this one will be painful to add comments every time a new mod gets added to the options. I am willing to use this solution if there is no good alternative.

    Continue reading...

Compartilhe esta Página