Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Detect PythonWin?

Reply
Thread Tools

Detect PythonWin?

 
 
Martin Bless
Guest
Posts: n/a
 
      08-01-2003
IMHO PythonWin is great help in developing.

How can I do something like:

if detect("running on PythonWin"):
pass
# fake arguments ...
else:
"proceed normal"

?

Martin
 
Reply With Quote
 
 
 
 
Andrew Dalke
Guest
Posts: n/a
 
      08-01-2003
Martin Bless wants to know how to do:
> if detect("running on PythonWin"):
> pass
> # fake arguments ...
> else:
> "proceed normal"


To see if you're on Windows,

>>> import sys
>>> sys.platform

'win32'
>>>


To see if the win32 extensions are installed

try:
import win32com # or another module in the extension
except ImportError:
print "Not installed"
else:
print "Installed!"

Andrew
http://www.velocityreviews.com/forums/(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Martin Bless
Guest
Posts: n/a
 
      08-01-2003
[Andrew Dalke]:

>To see if you're on Windows,

[...]
>To see if the win32 extensions are installed


Ok,
but how can my script know it its running from inside PythonWin?

I often have the situation that while developing with PythonWin I have
to insert code like

if 1 and "developing in PythonWin":
sys.argv[1:] = ['fake', 'arguments']

Later on or when running the same script from the commandline I need
to disable this if statement. Nasty.

I'm looking for a predicate functions that will let my script know if
it's running from inside PythonWin. And the function shouldn't use
much time or resources if we are not in PythonWin.

Anybody knows?

Martin




 
Reply With Quote
 
Neil Hodgson
Guest
Posts: n/a
 
      08-01-2003
Martin Bless

> but how can my script know it its running from inside PythonWin?


I don't know if it is all that robust but performing 'dir()' from a
PythonWin Interactive Window shows an interesting 'pywin' symbol, so:

if 'pywin' in dir():
print 'PythonWin'

Seems to work.

Neil


 
Reply With Quote
 
Brett g Porter
Guest
Posts: n/a
 
      08-01-2003
Martin Bless wrote:

>
> I often have the situation that while developing with PythonWin I have
> to insert code like
>
> if 1 and "developing in PythonWin":
> sys.argv[1:] = ['fake', 'arguments']
>


Is there a subtle reason that you can't pass the arguments using the
"Arguments" field on the PythonWin "Run Script" dialog?

That's always worked fine for me...

 
Reply With Quote
 
logistix at cathoderaymission.net
Guest
Posts: n/a
 
      08-01-2003
Martin Bless <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>. ..
> [Andrew Dalke]:
>
> >To see if you're on Windows,

> [...]
> >To see if the win32 extensions are installed

>
> Ok,
> but how can my script know it its running from inside PythonWin?
>
> I often have the situation that while developing with PythonWin I have
> to insert code like
>
> if 1 and "developing in PythonWin":
> sys.argv[1:] = ['fake', 'arguments']
>
> Later on or when running the same script from the commandline I need
> to disable this if statement. Nasty.
>
> I'm looking for a predicate functions that will let my script know if
> it's running from inside PythonWin. And the function shouldn't use
> much time or resources if we are not in PythonWin.
>
> Anybody knows?
>
> Martin


>>> import sys
>>> if sys.modules.has_key('pywin'):

.... print "pythonwin running"
.... else:
.... print "pythonwin not running"
....
pythonwin running
>>>



This shouldn't have any overhead. Writing a predicate function is
left as an exercise to the reader.
 
Reply With Quote
 
Bob Gailer
Guest
Posts: n/a
 
      08-01-2003

>how can my script know it its running from inside PythonWin?


I addressed this a few months ago:

import sys
if len(sys.modules) > 200: # running under PythonWin

This is because PythonWin loads a lot of modules beyond what native Python
does. (IDLE also loads some, but a lot less that PyrthonWin).

Bob Gailer
(E-Mail Removed)
303 442 2625


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.500 / Virus Database: 298 - Release Date: 7/10/2003

 
Reply With Quote
 
Roger Upole
Guest
Posts: n/a
 
      08-02-2003
Try this:
>>> import win32ui
>>> win32ui.GetCommandLine()

'"C:\\Python23\\Pythonwin.exe" '
hth
Roger


"Martin Bless" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> IMHO PythonWin is great help in developing.
>
> How can I do something like:
>
> if detect("running on PythonWin"):
> pass
> # fake arguments ...
> else:
> "proceed normal"
>
> ?
>
> Martin



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Network in range... won't detect =?Utf-8?B?Y29vbGtpZGNhcmxzb24=?= Wireless Networking 2 09-24-2005 05:31 AM
does not detect my netgear Wireless Router =?Utf-8?B?UGVhcmw=?= Wireless Networking 4 01-24-2005 06:53 PM
Why perl cannot detect zero value? Hon Seng Phuah Perl 5 06-03-2004 04:34 PM
how to detect broken pipe ? funtoosh Perl 1 12-21-2003 04:08 PM
detect keyboard input without reading it? Scott Shaw Perl 1 11-10-2003 04:33 AM



Advertisments