473,599 Members | 3,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Detect PythonWin?

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
Jul 18 '05 #1
7 3009
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
da***@dalkescie ntific.com
Jul 18 '05 #2
[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


Jul 18 '05 #3
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
Jul 18 '05 #4
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...

Jul 18 '05 #5
Martin Bless <m.*****@gmx.de > wrote in message news:<ej******* *************** **********@4ax. com>...
[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.
Jul 18 '05 #6
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
bg*****@alum.rp i.edu
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

Jul 18 '05 #7
Try this:
import win32ui
win32ui.GetComm andLine()
'"C:\\Python23\ \Pythonwin.exe" '
hth
Roger
"Martin Bless" <mb@muenster.de > wrote in message
news:3f******** *****@news.muen ster.de... 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

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1233
by: stephan | last post by:
Hi, I have python 2.2.3 + pythonwin 156 on win2k. The problem is that german chars like äöüÄÖÜß are not handled correctly. Just create a test.py file with the content äöüÄÖÜß and edit it with pythonwin. In the editor you will see only äöüÄ . I had the problem in the past, wrote it to mark and he fixed it.
3
2936
by: Alberto Mantovani | last post by:
hi, how is it possible to run a python script in the pythonwin environment from dos command line? If I use the command "/run scriptname.py" and the pythonwin is already opened I get error, so someone can help me? thanks Alberto
14
2878
by: Jive | last post by:
I've un-installed Python 2.4, re-installed Python 2.3 and PythonWin for 2.3, but it's still broke. When I start PythonWin, sometimes it looks like it is going to be okay. But as soon as I open a .py file, the interactive window grabs the focus and will not let go. I am stumped. Is there something PythonWin uses that I could try re-installing? WxPython maybe?
4
2604
by: Chris P. | last post by:
I've been having a problem with PythonWin that seemed to start completely spontaneously and I don't even know where to START to find the answer. The only thing I can think of that marks the point between "PythonWin works fine" and "PythonWin hardly every works fine" was that I changed the size of my Virtual Paging file, noticing that it was too small (I currently have a P4 with 1G of RAM). I tried returning it to its original (smaller)...
2
7322
by: siggy2 | last post by:
Hi All, (sorry for my bad english) I wrote a __tiny__ and __stupid__ recursive script directly into pythonwin interactive window with a time.sleep(1) and a print before each recursion... I should have taken a closer look at the ending condition (never satisfied!), anyway I was quite confident that a control-C would have stopped the intepreter as it is (incidentally?) when this break sequence is entered
2
2459
by: accolades | last post by:
Does anyone else have a problem with Pythonwin crashing after running a python script with graphics libraries? Whenever I use Pythonwin to run a PyGame or PyOgre script, Pythonwin crashes when the script exits. I know it's probably because the Pythonwin interpreter can't read from the console once the graphics mode has been changed, but has anyone discovered a workaround? I'd like to know if this problem is specific to my machine, or if...
17
1945
by: Dave Benjamin | last post by:
Hey folks, Why is PythonWin (win32all) still a separate download from a third party? Is it legal, technical, or what? I think it's about time it be part of the standard distribution. There are many useful things that you ought to be able to do without downloading third-party libraries. Terminating a process, for example. Communicating with other applications via a standard, common protocol (COM). We demand these things from our UNIX...
3
2973
by: archaegeo | last post by:
I am getting started in Python, and I have looked on both the stackless page and python.org and cannot find the answer to what I think is a simple problem. If I start the python command line or idle, i can If I start pythonwin I get the following error ....No Module named Stackless Any help?
4
3606
by: sterling | last post by:
I'm curious as to why the difference between IDLE and pythonWin when using win32com. opening an excel file, i've attempted to grab the chart information out of the file. commands like co = ChartObjects(1) works in pythonWin but doesn't work in IDLE. however, on both co = chartobjects(1) works just fine.
0
7992
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8398
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8051
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8267
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5850
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5438
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3898
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2414
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1505
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.