Quantcast
Channel: Active questions tagged config - Stack Overflow
Viewing all articles
Browse latest Browse all 5049

Append data to config file on linux

$
0
0

I would like to append data to my file.config. Also I'm using linux, which will request permissions to any kind of configuration to the file. In the terminal I can write sudo nano file.config and make the changes.

Expectation: my file.cofig looks like this

##info ...##[Section]#infoI want to append data right here to the end of the file

I tried using configparser module:

configparser = configparser.ConfigParser()   configparser['Section'] = {'data':'123'}configFilePath = '/etc/file.conf'with open(configFilePath, 'a') as file_conf:  configparser.write(file_conf)

This will add information as a dictionary, instead as the regular file.txt

##info ...##[Section]#info[Section]data = 123

As requested in the comments: sudo python3 file.py was requiered (visual studio was not in su mode)


Viewing all articles
Browse latest Browse all 5049

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>