[Tutor] How to get a script to open a text file with Python?

Alan Gauld alan.gauld at btinternet.com
Wed Jun 11 00:44:33 CEST 2008


"Dick Moores" <rdm at rcblue.com> wrote

> The script prints into the Windows command line
> window (I don't know the official term), from which
> copying is a PITA.

Whats the problem copying from a command prompt?
Just grab with the mouse and it's selected automatically
(assuming you have QuickEdit mode turned on in the
preferences obviously!) I copy/paste from a DOS box
into my mail messages regularly.

> Now, the script writes into temp.txt, so I thought if
> I could also have Textpad open temp.txt, I could copy easily.

You could. But why do you need to copy it at all?
Couldn't you get Python to do what you want with the
data directly rather than writing to a file then manually
copying it?

> But I don't know how to have a script get Textpad
> to open a file. Please tell me.

If TextPad is your default txt editor just use
os.system("foo.txt") or if not use os.system("Path/to/textpad.exe 
foo.txt")

Or if you want to be politically correct use the subprocess module
to do the same thing.

Alan G 




More information about the Tutor mailing list