I needed a simpler version of adding a specific suffix to the .txt file in a Python program, i.e. I needed to add -VOC, -TEX, or -RAN to the file names. For example: the file name is -VOC.txt (for the dictionary file), the file name is -TEX.txt (for plain text or utf8 encoded file) or the file name is -RAN.txt (for translating the TEX file), So, I experimented in Jupyter Notebook with the following solution, and it worked, I got the desired result:
filename = 'C:/Users/User/Desktop/test4.txt' type(filename)
More specifically, I applied the above as follows:
def new_file(): """ Creates vocabulary file """ global file_name input_file_name = filedialog.asksaveasfilename(initialdir="/", defaultextension='*.txt', filetypes=(("Text Documents", "*.txt"), ("all files", "*.*"))) if input_file_name: file_name = input_file_name.rsplit('.', 1)[0]+'-VOC.txt'
source share