[ANN] isrealfile function
Peter Hansen
peter at engcorp.com
Fri Jun 18 21:25:07 EDT 2004
Manlio Perillo wrote:
> def isrealfile(file):
> """
> Test if file is on the os filesystem
> """
>
> if not hasattr(file, 'fileno'): return False
>
> try: tmp = os.dup(file.fileno())
> except: return False
> else: os.close(tmp); return True
>
> I have implemented this function for testing if a Python script is
> being executed by Python.exe or Pythonw.exe. In the latter case, in
> fact, Microsoft implementation of stdout/stderr is broken.
I haven't tested this idea, but wouldn't "os.isatty()" be
the right thing for this purpose, instead of the os.dup()
and os.close() stuff?
-Peter
More information about the Python-list
mailing list