Dec-28-2019, 07:17 AM
Hello everyone, hope you are all well these holidays.
I'm having problems updating and writing to a config.ini file using filedialog.askopenfilename in Tkinter.
Example of my config file:
C:\Users\Stryker\Desktop\py\31K_verbs.txt
C:/Users/Stryker/Desktop/py/31K_verbs.txt
C://Users//Stryker//Desktop//py//31K_verbs.txt
But I still get the error that the section 'Keyword Files' is missing, when it clearly is there on my config file.
I even tried many variations of .split(os.path.sep).os.path.join(os.path.sep) but nothing. Any ideas?
I can read from config file no problem, I've gotten reading from config file just fine, it's writing the file name into the my config file that has me stumped.
Any help is greatly appreciated. Thanks for reading.
I'm having problems updating and writing to a config.ini file using filedialog.askopenfilename in Tkinter.
Example of my config file:
[Keyword Files] kwA = 100_questions.txt kwB = 91K_nouns.txt kwC = 31K_verbs.txt kwD = 28K_adjectives.txt kwE = 6K_adverbs.txtHere is the bit of code, it's assigned already to a tkinter button:
def kw_txt1(self): kwTXT1 = filedialog.askopenfilename(filetypes =[('Text File', '*.txt')]) config = configparser() x = re.sub("/", "\\\\", kwTXT1) y = re.sub("/", "//", kwTXT1) print(x) print(y) print(kwTXT1) config.set('Keyword Files', 'kwA', 'kwTXT1') config.write('C:/Users/Stryker/Desktop/py/config.ini')As you can see, there is a lot there but it's because I've been trying many different solution for this error here.:
Error: File "C:\Users\Stryker\AppData\Local\Programs\Python\Python38\lib\configparser.py", line 902, in set
raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'Keyword Files'
I've been reading up everwhere and I got to thinking it's the way the filepath was set, but I tried using different 'experimental ways' to see if I can get it in. I've been able to generate all these filepaths:C:\Users\Stryker\Desktop\py\31K_verbs.txt
C:/Users/Stryker/Desktop/py/31K_verbs.txt
C://Users//Stryker//Desktop//py//31K_verbs.txt
But I still get the error that the section 'Keyword Files' is missing, when it clearly is there on my config file.
I even tried many variations of .split(os.path.sep).os.path.join(os.path.sep) but nothing. Any ideas?
I can read from config file no problem, I've gotten reading from config file just fine, it's writing the file name into the my config file that has me stumped.
Any help is greatly appreciated. Thanks for reading.