different behaviour for user defined exception with attribute args
Hi all For an exception defined as below class OptionError(Exception): def __init__(self, args): self.args = args def __str__(self): return repr(self.v) an iteration is happening when the exception is raised Meanwhile for almost the same structured exception replacing the attribute 'args' with say 'value' it is not a probs. class OptionError(Exception): def __init__(self, args): self.value = args def __str__(self): return repr(self.value) This was frustrating because for a st. OptionError('Error') for exception 1 output will be OptionError: ('E', 'r', 'r', 'o', 'r') Meanwhile for exception 2 output will be OptionError: 'Error' which is desired..Why this behaviour? Regards Visco -- http://mail.python.org/mailman/listinfo/python-list
"TypeError: 'int' object is not callable"
when I was executing the below code I got "TypeError: 'int' object is not callable" exception. Why is it so? if type(c) == type(ERROR): c can be a string or an integer representing an error -- Thanks & Regards visco -- http://mail.python.org/mailman/listinfo/python-list
Any adv. in importing a module and some objects in the same module, into the same file?
http://docs.python.org/library/logging.html While going thr' the above link i came across import statements "import logging import logging.handlers" What is the use of second import as the first import will be enough(AFAIK) to access anything intended by the second import? Is there any kind of advantage? -- Thanks & Regards visco -- http://mail.python.org/mailman/listinfo/python-list
how to know the importing file name from an imported file?
Hi Is there a way to know the name of the script(say A), which is importing a module(say B), from B? ie in above situation i should be able to get name 'A' through some way in B, when A contains an 'import B' statement. -- Thanks & Regards visco -- http://mail.python.org/mailman/listinfo/python-list
Re: to get name of file opened
First of all Thanks Dave for the reply On Sat, 2009-03-28 at 09:51 -0500, Dave Angel wrote: > First question is why you need os.open(), and not the open() function. > I'll guess that you need some of the access modes (e.g. for file > sharing) that you get from the low level functions. So assuming that: of course access was an issue.. but i opted for it because in the document it is mentioned that os.open(besides sharing b/w processes) is low level resembling unix system call, and i thought may be efficiency is more, even though interpreted by the same python interpreter... But i never found any article regarding any efficiency difference between those.. Can u comment on this > I don't believe there's any way to use a fd ("file descriptor") to > retrieve the file name that was perhaps passed to open. There are ways > to spelunk inside Windows, but they're not advisable. And I don't know > what Unix might offer there. > > So by the time fdopen() is invoked, the name is already gone. > > Here's what I'd do. Create your own open function that has the > parameters of os.open(), but that will return an object derived from the > file object. Your derived object can have its own filename, but close() > will know what to do. Well this is what i am trying now, though i wished if there was any suitable method or attribute built within python > > Alternatively, you could encapsulate the line you showed, and just zap > the name attribute of the existing file object.right when it's being > returned by fdopen() The name attribute appears to be read only as i tried that already though through the interpreter rather than in code -- http://mail.python.org/mailman/listinfo/python-list
difference between os.fdopen and builtin open
Hi I was wondering the difference between os.fdopen()(or os.open() not considering the difference in args) and builtin open(). Can anyone help me? -- Thanks & Regards visco -- http://mail.python.org/mailman/listinfo/python-list
to get name of file opened
Hi Is there any way to get the name of the file opened from the file object 'f' which i get through the code f = os.fdopen(os.open("trial', os.O_WRONLY|os.O_CREAT), "w") The situation will be like i can access only the above variable 'f'. f.name is having '' instead of filename 'trial' Or if not possible can anyone suggest a solution where my requirements are a) i need file access through os module b) i need file object and not file descriptor as its more easy to use -- Thanks & Regards visco -- http://mail.python.org/mailman/listinfo/python-list
subprocess module: execution of standard binaries without shell?
hi all while getting used to with subprocess module i failed in executuing a) but succeeded in running b). Can anyone explain me why as i am providing absolute path? Is this has to do anything with shared library.. which must be accessed based on system variables? a) pipe = subprocess.Popen("/bin/ls /", stdout=subprocess.PIPE, close_fds=True) ==>OSError: [Errno 2] No such file or directory b) pipe = subprocess.Popen("/bin/ls /", stdout=subprocess.PIPE, close_fds=True, shell=True) -- Thanks & Regards visco -- http://mail.python.org/mailman/listinfo/python-list