[CentralOH] Filenames For Pipes?
wam at cisco.com
Thu Aug 23 01:07:29 CEST 2012
On Wed, 2012-08-22 at 18:39 -0400, jep200404 at columbus.rr.com wrote:
> I'm using the following smelly code:
> fd_name = '/dev/fd/%d' % file.fileno()
> There have to be better ways. What are they?
I don't exactly understand what you're trying to do in terms of your
python program. The example you gave at the start of the thread showed
the bash syntax for dealing with open descriptors as filenames. This
makes sense for bash, which has to be able to convert its file handle
redirection to binaries which generally prefer to handle filenames. But
in python, operations are rarely done with either file descriptors or
even filenames (beyond initial program setup) and it is much more common
to process arbitrary iterators (or at least things that behave like file
objects). Mapping from an open file to a file descriptor to a filename
seems like an exceptionally obtuse way to accomplish most tasks within
python (and as you've pointed out, the code smells because this is a
very platform specific capability found in only some linux/unix
kernels). You apparently have open file objects within your python code.
Are these generic file objects (e.g. just as likely to be sys.stdout or
StringIO objects) or files that previously were opened from disk and now
you're trying to find the original filename (in which case, the .name
attribute of the file object might suffice). Again though, it'd help if
we knew what you were trying to do within your python code.
More information about the CentralOH