473,508 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extend file type

I have a class which extends 'file' ....

class MyFile(file):
def __init__(self, fname, mode='r'):
file.__init__(self, fname, mode)

def write(self, str):
print "writing a string"
file.write(self, str)

def writelines(self, lines):
print "writing lines"
file.writelines(self, lines)

I use this with subprocess....

f = MyFile('out.txt', 'w')
p = subprocess.Popen(cmd, stdout=f)

.....and I can see that stuff goes into out.txt.....however, I never see
"writing a string" or "writing lines" from the class MyFile.

Any ideas what methods the stdout (and I guess stderr) of Popen objects
from subprocess call?

Any suggestions on how to find out? I did try adding to MyFile....

def __call__(self, *args):
print "calling:", args
return file.__call__(self, *args)
but I never see that either.

thanks

Sep 26 '06 #1
2 3997
abcd wrote:
Any ideas what methods the stdout (and I guess stderr) of Popen objects
from subprocess call?
the external process only sees OS-level file handles (the number you get
from the fileno() method on your file objects), not Python objects. no
matter how you override things in your process, you cannot make your OS
pretend that the other process is written in Python...

</F>

Sep 26 '06 #2
abcd enlightened us with:
Any suggestions on how to find out? I did try adding to MyFile....

def __call__(self, *args):
print "calling:", args
return file.__call__(self, *args)

but I never see that either.
I don't know the answer to your problem, but I can explain why this
doesn't work. __call__ is used when an instance if MyFile is called as
if it were a function:

mf = MyFile("blabla")
mf()

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Sep 26 '06 #3

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

Similar topics

2
2116
by: Mark | last post by:
I have a windows 2000 PC and it does not know what a hta file is. any ideas. Mark
4
493
by: CLEAR-RCIC | last post by:
In the old days, you could get a file type in ASP by doing: dim fs, fld, f set fs = server.createobject("Scripting.FileSystemObject") set fld = fs.GetFolder(server.mappath(sCurrentDir)) for...
2
8860
by: Brian Henry | last post by:
I want to list out a directory listing along with showing the file type name (like explorer does when it says something like "MyDoc.DOC - Microsoft Word Document" How do I get that file type name...
3
3150
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
2
2551
by: Ames111 | last post by:
Hi i want to be able to determine what type of file is being dragged on to my form, ive got this: private void Form1_DragDrop(object sender, DragEventArgs e) { //tell me the file type please ...
13
13182
by: Hemant Sipahimalani | last post by:
The following piece of code is being used to export HTML to excel. HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"...
5
3779
by: mike | last post by:
Hi, I have been playing with VB.NET/C# for getting some general properties of a fileinfo object. However, FileInfo object does not seem to expose some of the basic properties like TYPE that used...
2
4501
Nepomuk
by: Nepomuk | last post by:
Recently, I found that I had associated a file type to notepad by mistake. This file type (let's just say, it has the extension .xyz) wasn't supposed to be opened by notepad - actually, it wasn't...
1
2849
by: sasimca007 | last post by:
Hai friends, I have a doubt that if we are having a page which having the functionality to upload a file, then if we want to restrict to some types of files only have to be...
0
7125
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...
0
7328
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,...
0
7388
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7049
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...
1
5055
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...
0
3199
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...
0
3186
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1561
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 ...
0
422
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...

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.