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

2008-06-12 Thread Dick Moores


At 06:50 AM 6/11/2008, John Chandler wrote:
Why not have python copy the
text to the clipboard for you? You will need the win32 packages, which is
hardly a turnoff since they are so useful. 

import win32clipboard
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()

win32clipboard.SetClipboardText(text)
win32clipboard.CloseClipboard()


Python puts it on the
clipboard for use for you! I trump the above '5 steps' and even '1 step'
with 0 steps! I hope this helps. (Remember to close the clipboard, I
forgot when I was first trying to come up with this and it does not work
if the clipboard remains open. Thanks goes to Bob Gailer and his 2003
post for the syntax reminder)
Very interesting! Thank you.
Dick



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2008-06-11 Thread John Chandler
Why not have python copy the text to the clipboard for you? You will need
the win32 packages, which is hardly a turnoff since they are so useful.

import win32clipboard
win32clipboard.OpenClipboard()
win32clipboard.EmptyClipboard()
win32clipboard.SetClipboardText(text)
win32clipboard.CloseClipboard()


Python puts it on the clipboard for use for you! I trump the above '5 steps'
and even '1 step' with 0 steps! I hope this helps. (Remember to close the
clipboard, I forgot when I was first trying to come up with this and it does
not work if the clipboard remains open. Thanks goes to Bob Gailer and his
2003 post for the syntax reminder)



On Tue, Jun 10, 2008 at 11:26 PM, Alan Gauld [EMAIL PROTECTED]
wrote:


 Terry Carroll [EMAIL PROTECTED] wrote

  If TextPad is your default txt editor just use
 os.system(foo.txt)


 or os.startfile(foo.txt); sounds like the equivalent, but for some
 reason, I prefer it.


 Actually os.startfile was what I meant for the default case!
 Thanks for pointing it out. system() may work if the preference is
 already set but startfile is specifically intended for that scnario.

 Alan G

 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor




-- 
-John Chandler
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2008-06-10 Thread Dick Moores


I have a script, fcn_double_phone_grep.py, that does a good job of
searching my text file of phone numbers, phone.txt. The script is at

http://py77.python.pastebin.com/f3a8c1f87
The script prints into the Windows command line window (I don't know the
official term), from which copying is a PITA. 
Now, the script writes into temp.txt, so I thought if I could also have
Textpad open temp.txt, I could copy easily.
But I don't know how to have a script get Textpad to open a file. Please
tell me.
Thanks,
Dick Moores



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2008-06-10 Thread Alan Gauld


Dick Moores [EMAIL PROTECTED] 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 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2008-06-10 Thread Dick Moores

At 03:44 PM 6/10/2008, Alan Gauld wrote:


Dick Moores [EMAIL PROTECTED] 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?


1. Click on the little black icon in the upper left corner.
2. Select Edit.
3. Select Mark
4. Select text to copy
5. Hit Enter

5 steps!


Just grab with the mouse and it's selected automatically
(assuming you have QuickEdit mode turned on in the
preferences obviously!)


Big assumption! I've been doing the above 5-step dance for years 
because I didn't know about QuickEdit. Thanks, Alan.


How about pasting INTO the command prompt. Ctrl+V doesn't work, even 
with QuickEdit..



 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?


Looking at the script now, I think I could.



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)


Thanks for this.


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


Nah. Or I don't think I do. Why is it the correct way? Is there a 
problem with yours?


Dick


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2008-06-10 Thread John Fouhy
On 11/06/2008, Dick Moores [EMAIL PROTECTED] wrote:
 At 03:44 PM 6/10/2008, Alan Gauld wrote:
[on Windows cmd.exe]
  (assuming you have QuickEdit mode turned on in the
  preferences obviously!)
  How about pasting INTO the command prompt. Ctrl+V doesn't work, even with
 QuickEdit..

Single right-click to paste.

User interface consistency would be a wonderful thing :-)

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2008-06-10 Thread Dick Moores

At 05:17 PM 6/10/2008, John Fouhy wrote:

On 11/06/2008, Dick Moores [EMAIL PROTECTED] wrote:
 At 03:44 PM 6/10/2008, Alan Gauld wrote:
[on Windows cmd.exe]
  (assuming you have QuickEdit mode turned on in the
  preferences obviously!)
  How about pasting INTO the command prompt. Ctrl+V doesn't work, even with
 QuickEdit..

Single right-click to paste.


That's weird! Thanks!


User interface consistency would be a wonderful thing :-)


Yeah. Up to now I thought that other than in dragging, right-clicking 
(in a Windows OS) NEVER did anything. It only presented choices for 
things you could do.


Dick


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2008-06-10 Thread Terry Carroll
On Tue, 10 Jun 2008, Alan Gauld wrote:

 If TextPad is your default txt editor just use
 os.system(foo.txt)

or os.startfile(foo.txt); sounds like the equivalent, but for some 
reason, I prefer it.


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


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

2008-06-10 Thread Alan Gauld


Terry Carroll [EMAIL PROTECTED] wrote


If TextPad is your default txt editor just use
os.system(foo.txt)


or os.startfile(foo.txt); sounds like the equivalent, but for some
reason, I prefer it.


Actually os.startfile was what I meant for the default case!
Thanks for pointing it out. system() may work if the preference is
already set but startfile is specifically intended for that scnario.

Alan G 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor