473,811 Members | 3,057 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is there a way to tell if a script has been run by Pythonw.exe instead of Python.exe?

In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePr esent()

Oct 18 '07 #1
5 1428
On Oct 19, 7:56 am, Metalone <j...@iteris.co mwrote:
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePr esent()
Have you tried:

sys.stdin.isatt y()
sys.stdout.isat ty()

Graham

Oct 18 '07 #2
On Oct 18, 2:56 pm, Metalone <j...@iteris.co mwrote:
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePr esent()
Look at sys.executable to find the name of the binary for the Python
interpreter.

Oct 19 '07 #3
On Oct 18, 11:56 pm, Metalone <j...@iteris.co mwrote:
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePr esent()
For a different problem, I have the following code. It might help:

def isrealfile(file ):
"""
Test if file is on the os filesystem. This is necessary on windows,
when
starting python with pythonw.exe because in that case, the
stdout and stderr
are not real file and will create IOError when being flushed or when
more
than 4096 bytes are written.
"""
if not hasattr(file, 'fileno'): return False
try: tmp = os.dup(file.fil eno())
except: return False
else: os.close(tmp); return True

class NullStream:
"""
A file like class that writes nothing
"""
def close(self): pass
def flush(self): pass
def write(self, str): pass
def writelines(self , sequence): pass

if not isrealfile(sys. stdout):
sys.stdout = NullStream()

if not isrealfile(sys. stderr):
sys.stderr = NullStream()
Oct 19 '07 #4
Thanks to all, I learned something in each post.
When using py2exe to build an executable sys.executable does not
provide the name of the python interpreter but the name of the
executable generated by py2exe.

Oct 19 '07 #5
Metalone schrieb:
Thanks to all, I learned something in each post.
When using py2exe to build an executable sys.executable does not
provide the name of the python interpreter but the name of the
executable generated by py2exe.
When running the executable built with py2exe you might be interested
in the variable sys.frozen; they are set to the string 'console' or 'windows', IIRC.

Thomas

Oct 19 '07 #6

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

Similar topics

3
1562
by: Guyon Morée | last post by:
recently i've visited SARAH, the academic supercomputer in Amsterdam, Holland. this is next to the CWI, where Guido founded Python.... ....Yeah!...
8
4048
by: Thomas Aanensen | last post by:
Python could be located at different paths on computers (e.g. c:\python). How can I find this path? Thomas
2
6663
by: Eric Ching | last post by:
Can I run pythonw with a script that takes command line arguments then launches a GUI? I try pythonw myscript.pyw -option arg (etc.) and nothing happens. Nothing, as in I am immediately returned to the DOS prompt. I just started learning Python a couple of weeks ago, so please bear with me. I have a script that(for now) uses command line arguments then launches a window (Tk). Once I have entered the arguments and the window is...
5
5329
by: Shalen chhabra | last post by:
Hey, Can anyone give me a snippet for running a python program over all the files in the directory. For ex: I have ten files in a directory and I want to run a python program against all of these files, I wish to do the same using another python code instead of running each of these files one by one, which would be cumbersome giving the argv of each file every single time. This can be easily done using a shell script but I just...
0
1051
by: Nicola Larosa | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I find the following excerpt fairly sad... (right before the screenshot): "The first version of Scribus used Python, with the Python bindings for Qt. Schmid says he chose Qt as the GUI toolkit because he felt it was the best one at the time (three years ago), with the most accurate documentation. As he added features, though, he concluded that Python had a few shortcomings.
1
1690
by: Charles Stricklin | last post by:
I'd like to use Planet (http://planetplanet.org/) to aggregate my members blogs into one big blog, and my host (http://www.bodhost.com) says they support Python, but I see nothing anywhere on their web site including my control panel that leads me to believe they do. Is there any way to determine if they do? -- Charles Stricklin
5
4428
by: johnny | last post by:
Anyone know how I can make Machine A python script execute a python script on Machine B ?
3
3625
by: Brainsludge | last post by:
Hello, I am running WinXP SP2 with Python 2.5.1 and encountered the following issue: I wrote a script that logs into my mail server, and checks for new messages every 20 seconds. When a new message is found, it displays a Windows tool tip and prints a line to console indicating a new message.
1
2609
by: Goldfish | last post by:
Spring Python, the python version of the Spring Framework, has just released version 0.8.0. This release contains a refactored IoC container supporting four formats (XMLConfig, PythonConfig/@Object, PyContainerConfig, and SpringJavaConfig); replacement of the term "component" with "object" in all APIs, classnames, etc.; and other bug fixes and API cleanup. This release also includes a new, spring-green web page you can see at...
2
1345
by: giggsteve8 | last post by:
I'm very, very new, and am working with Python 3.1.2. New as in installed last night, and working through a tutorial. I wrote a simple script to aid in learning to break a 'while: True' loop. My question is, why can I NOT run this script from a directory other than the \python31 directory? I have the python31 directory set in my path. I'm running XP, if that helps. I can run other programs just fine from any other directory. Does this...
0
9605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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...
0
10130
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...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7667
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
6887
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
5553
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
4338
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
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.