ファイルの使用方法について本当に混乱しています。
そもそもなんでやってんのint(open(filename, "w"))?書き込み用にファイルを開くには、次を使用します。
outfile = open(filename, "w")
その場合、ファイルはアイテムの割り当てをサポートしてfileobject[key]いないため、意味がありません。また、 でファイルを開くと、以前の内容"w" が削除されることに注意してください。したがって、ファイルの内容を変更したい場合は、"r+"代わりに"w". 次に、ファイルを読み取り、その内容を解析する必要があります。あなたの場合、最初に内容を読んでから、新しいファイルを作成して新しい内容を書き込む方がおそらく良いでしょう。
数値のリストをファイルに書き込むには、次のようにします。
outfile.write(','.join(str(number) for number in list2))
str(number)整数を文字列表現に「変換」します。コンマをセパレータとして使用してiterable','.join(iterable)の要素を結合し、文字列をファイルに書き込みます。outfile.write(string)
また、インポートを関数の外側 (おそらくファイルの先頭) に配置すると、モジュールを使用するたびにインポートを繰り返す必要がなくなります。
完全なコードは次のようになります。
import tkinter.filedialog
def replace():
    drawfilename = tkinter.filedialog.askopenfilename() 
    # read the contents of the file
    with open(drawfilename, "r") as infile:
        numbers = [int(number) for number in infile.read().split(',')]
        del numbers[-3:]
    # with automatically closes the file after del numbers[-3:]
    input_list = input("Enter three numbers separated by commas: ")
    # you do not have to strip the spaces. int already ignores them
    new_numbers = [int(num) for num in input_list.split(',')]
    numbers = new_numbers + numbers
    #drawfilename = tkinter.filedialog.askopenfilename()  if you want to reask the path
    # delete the old file and write the new content
    with open(drawfilename, "w") as outfile:
        outfile.write(','.join(str(number) for number in numbers))
更新:複数のシーケンスを処理したい場合は、これを行うことができます:
import tkinter.filedialog
def replace():
    drawfilename = tkinter.filedialog.askopenfilename() 
    with open(drawfilename, "r") as infile:
        sequences = infile.read().split(None, 2)[:-1]
        # split(None, 2) splits on any whitespace and splits at most 2 times
        # which means that it returns a list of 3 elements:
        # the two sequences and the remaining line not splitted.
        # sequences = infile.read().split() if you want to "parse" all the line
    input_sequences = []
    for sequence in sequences:
        numbers = [int(number) for number in sequence.split(',')]
        del numbers[-3:]
        input_list = input("Enter three numbers separated by commas: ")
        input_sequences.append([int(num) for num in input_list.split(',')])
    #drawfilename = tkinter.filedialog.askopenfilename()  if you want to reask the path
    with open(drawfilename, "w") as outfile:
        out_sequences = []
        for sequence, in_sequence in zip(sequences, input_sequences):
            out_sequences.append(','.join(str(num) for num in (in_sequence + sequence)))
        outfile.write(' '.join(out_sequences)) 
これは、任意の数のシーケンスで機能するはずです。どこかに余分なスペースがあると、間違った結果が得られることに注意してください。可能であれば、これらのシーケンスを別の行に配置します。