J'essaie de lire et d'écrire des fichiers cfg en python. J'ai essayé le paquet appelé configparser mais il se plaint d'en-têtes manquants car apparemment il ne comprend pas le format de mon fichier. Je voudrais connaître votre opinion à ce sujet pour accomplir ceci aussi facilement que possible. Note: Je dois m'en tenir à ce format.lire et écrire des fichiers cfg en python
Voici le format de mon fichier:
PROFILE_PERIODS =
( // note that this is not a curly brace
{ //comment
PRIORITY = 1;
},
{ //comment
DESCRIPTION = "drgdfth";
}
)
TIME_SYNCHRONIZATION =
{
INTERVAL = 100;
}
Ce fichier de configuration est également lu par une bibliothèque appelée c libconfig. Merci
Avez-vous regardé [this] (https://github.com/cnangel/python-libconfig)? – mgilson
ou peut-être [this] (http://code.google.com/p/pylibconfig/) – mgilson
Avez-vous le contrôle sur le format de fichier de configuration? Si oui, vous n'avez peut-être pas encore besoin d'inventer-un-autre-format-de-fichier-de-configuration ™ Dans ce cas, puisque votre format est assez proche de [JSON] (http://en.wikipedia.org/wiki/ JSON), avec quelques ajustements mineurs, vous pouvez utiliser la [bibliothèque Python standard correspondante] (http://docs.python.org/2/library/json.html) pour l'analyser. –