I have a folder in my VM’s c:\ drive that is called “Smartwin” and inside of that folder there is a file called “Smartwin.ini” I am simply trying to append another line at the bottom of this file that reads “IsNewPrintLogic=1” I’ve tried figuring out for a while but every time I try, it either overwrites the entire file or leaves it blank. Can someone give me a small simple code that would perform this task? I’ve been using config.parser but I’m not sure if this is the right way to go about this.
What code are you running to append the line? Can you put the screenshot of the code here?
I’ve tried a few different codes now. None of them work. This is the last one I’ve tried.
from configparser import ConfigParser
smart = ConfigParser
#Get the Options section
options = smart[‘Options’]
#Create new key
options[‘IsNewPrintLogic’] = “1”
#Write changes back to file
with open(‘c:\Smartwin\Smartwin.ini’, ‘w’) as conf:
While opening the file you are putting ‘w’ which means open file in write mode. This will always delete whatever you have in the file and write new lines instead of updating the file. You have to use ‘a’ for it to open in append mode.
I’ve tried with ‘a’ and with ‘a+’ for reading purposes. It still doesn’t work. I’m not sure what else to do.