profig
profig copied to clipboard
the first sync() call erase my config value
Hi @RonaldinhoL. Can you share the code you are using that caused the issue? I need to be able to reproduce the problem in order to fix it.
sync()
will first read config values from the file that you provide. If any values have been set on the Config
object, they will not be overwritten by the value from the file. sync()
will then write the values from the Config
object to the file.
i init by None,dose it matter?
my sence dose not need a default value,for example: username and password and token
@RonaldinhoL Based on your comments, I understand that you are trying to do something like this:
import profig
c = profig.Config('test.cfg')
c.init('username', None)
c.sync()
And what happens is that the value from the config file is being overwritten. Is that correct?
If that is the case, yes this should be considered a bug, or at least unexpected behavior. What is happening is that profig is not able to determine the type of the value you are expecting to read. It is using type()
on your default value, which in this case is NoneType
. So, when it tries to read the value from the config file, it is converting it to None
. That is then written back to the config file.
I will fix this, but I can't say when. In the meantime, everything should work if you set the type that you expect to read from the config file. In your case, something like this should work:
c.init('username', None, str)
# or
c.init('username', '')
Thanks for the report.