On Jan 15, 7:40 pm, "W. eWatson" <wolftra...@invalid.com> wrote: > I am writing a txt file. It's up to the user to print > it using Notepad or some other tool.
In another response, Tim Chase suggested creating an RTF file instead of plain text. I think this is your best bet if your goal is to get page breaks with the least amount of additional effort. The package he's probably referring to is PyRTF. I took a quick look at it and in my opinion it's overkill for your purposes. Since RTF is actually just a markup language, and the only features of it that you absolutely need are (1) a way to ensure a fixed-width font is used and (2) a way to insert page breaks, it's probably quickest and simplest to just throw the markup into the document yourself (well, with Python) and naming the result with the .rtf suffix instead of .txt. So, how do you find out what markup to use? Open WordPad, select the font you want, type a bit of text, save the file as RTF (this should be the default), and open up the file in Notepad. At the top will be a bunch of setup codes, including the font selection. Make your Python program put that whole spiel (including a trailing space or newline, to separate your text from the last RTF tag) at the top of your output. There will be one unmatched curly brace, which you should close at the end of the document. On my computer, it looks like this: {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fmodern \fprq1\fcharset0 Courier New;}} {\*\generator Msftedit 5.41.15.1515;}\viewkind4\uc1\pard\f0\fs20 That takes care of the font (and other stuff, but you are interested in the font). The only other things you need to do are put r'\par' (the end-paragraph tag) at the end of each line and r'\page' at the end of each page. Again, remember to make sure these tags don't collide with your actual text. (I'd use '\\par\n' in place of '\n' and '\\page\n' in place of chr(12).) Finally, make sure to end with a closing curly brace as previously mentioned. The RTF solution is probably more robust than embedding chr(12) and telling the user to use WordPad, especially since I saw someone report on another forum that chr(12) doesn't always work even in WordPad (it might be dependent on the version of WordPad, or the printer, or whatever). I am too lazy to have actually read any documentation on RTF, but it's freely available on the Web should you need to reference it. John -- http://mail.python.org/mailman/listinfo/python-list