473,382 Members | 1,332 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.isConsolePresent()

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

sys.stdin.isatty()
sys.stdout.isatty()

Graham

Oct 18 '07 #2
On Oct 18, 2:56 pm, Metalone <j...@iteris.comwrote:
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePresent()
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.comwrote:
In particular I want to know how to tell if reading and writing to the
console can occur.
Something like
sys.isConsolePresent()
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.fileno())
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
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
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
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...
5
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...
0
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...
1
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...
5
by: johnny | last post by:
Anyone know how I can make Machine A python script execute a python script on Machine B ?
3
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...
1
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,...
2
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. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.