Is there some more convenient way to write into python files than using read/write for any file (like txt files etc).
I mean python knows what actually is the structure of python file, so if I need to write into it, maybe there is some more convenient way to do it?
If there is no such way (or it is too complicated), then what would best way to normally modify python file just using normal write
(example below)?
I have lots of these files in my subdirectories called:
__config__.py
These files are used as configuration. And they have unassigned python dictionary, like this:
{
'name': 'Hello',
'version': '0.4.1'
}
So what I need to do, is write to all those __config__.py
files new version (for example 'version': '1.0.0'
).
Update
To be more specific, given that there is a python file with a content like this:
# Some important comment
# Some other important comment
{
'name': 'Hello',
'version': '0.4.1'
}
# Some yet another important comment
Now running some python script, it should write into python file modifying given dictionary and after writing, output should be like this:
# Some important comment
# Some other important comment
{
'name': 'Hello',
'version': '1.0.0'
}
# Some yet another important comment
So in other words, write should only modify version
key value, and everything else should be kept like it was before writing.