Hi all,

In the never-ending quest to master Tkinter, I wrote a small version of Notepad.

Here is my "SaveAs" function:

def save_as():
    if not mainw.filename:
        mainw.filename = tkFileDialog.asksaveasfilename(title="Save As...", filetypes=[("All Files","*.*"),("Text Files","*.txt")])
        if not mainw.filename:
            return
    f = open(mainw.filename, "w")
    s = mainw.frame.edit.get("1.0",END)
    f.write(s)
    f.close()

As you can see, it dumps the entire contents of the text widget 'mainw.frame.edit' into a single string, and then writes it en masse to the file.

But suppose for some reason that the text file were War and Peace, or the OLE file documentation. Would that break Python?

In other words, should I manually manage memory here by getting smallish blocks and writing them, or can Python 'be smart' about my code?

Thanks,
Jeff

From what I understand the limit is the memory on your computer, not Python. How many megs can the text in 'War and Peace' take up?

There are 4,017,010 characters in the authorized version of the Bible. War and Peace shouldn't be much larger.

Can you put the entire text of the Bible in one string and save it?
You can test it with this simple program, gives no problems on my PC:

# create a 5M character string
large_string = 'a' * 5000000

# open the file for writing
fout = open( 'String5M.txt', 'w' )
# write 5M character text
fout.write(large_string)
# close the file
fout.close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.