Controlling exception handling of logging module
Suppose the following are part of a long file and executed:
logging.basicConfig(stream = sys.stderr, level=logging.INFO)
logging.info("%d %d", 1, 2, 3)# buggy
Python prints the traceback of the error as follows:
Traceback (most recent call last):
File ".../local/lib/python2.4/logging/__init__.py", line 706, in emit
msg = self.format(record)
File ".../local/lib/python2.4/logging/__init__.py", line 592, in
format
return fmt.format(record)
File ".../local/lib/python2.4/logging/__init__.py", line 382, in
format
record.message = record.getMessage()
File ".../local/lib/python2.4/logging/__init__.py", line 253, in
getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
It tells why error occurred, but the traceback is not helpful to locate
where it occurred. I believe that's because the logging module caught
and ate up the exception. I understand that this is a sensible setting
as logging shouldn't harm the main program, but in the debugging phase,
I really want this exception to propagate up so that I can easily
locate from my code. Is there any way to control this behavior so the
error is not handled by the logging module itself?
--
http://mail.python.org/mailman/listinfo/python-list
Re: Controlling exception handling of logging module
Thanks, but my point wasn't fixing the bug. I'd like the logging module to raise an exception on this occasion (rather than print and consume the error) so that I can find the bug easily. If those two lines were part of 10,000-line code, I'd have to check all logging statements one-by-one. -- http://mail.python.org/mailman/listinfo/python-list
list implementation
I believe the type "list" is implemented as an array of pointers. Thus, random access is an O(1) operation while insertion/deletion is an O(n) operation. That said, I have the following questions: 1. Am I correct in saying the above? 2. Implementing list as an array is part of language specification or implementation-dependent? 3. What if I actually need a doubly-linked list for constant-time insertion/deletion? Is there a built-in type or a standard class? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
list implementation
I believe the type "list" is implemented as an array of pointers. Thus, random access is an O(1) operation while insertion/deletion is an O(n) operation. That said, I have the following questions: 1. Am I correct in saying the above? 2. Implementing list as an array is part of language specification or implementation-dependent? 3. What if I actually need a doubly-linked list for constant-time insertion/deletion? Is there a built-in type or a standard class? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Trouble displaying image with tkinter
I am just learning to use Tkinter and am having problems displaying image
files. I am able to display an image using tutorials (such as
http://www.daniweb.com/code/snippet296.html) But when I try my own code all
I get is an empty widget. What is wrong with the following program?
from Tkinter import *
class Foo(Frame):
def __init__(self,master=None):
Frame.__init__(self,master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.qbutton = Button(self)
self.qbutton["text"] = "Quit"
self.qbutton["command"] = self.quit
self.qbutton.pack(side = "top")
idata =
PhotoImage(file="/home/sj/documents/projects/xaed/images/cat_001.gif")
canvas = Canvas(width=300,height=200)
canvas.pack(side="top",fill=BOTH,expand=YES)
canvas.create_image(50,10,image=idata,anchor=NW)
## lab = Label(self,image=idata)
## lab.pack(side=TOP)
root = Tk()
app = Foo(root)
app.mainloop()
#app.destroy()
--
http://mail.python.org/mailman/listinfo/python-list
pexpect - logging input AND output
i have a script running a few commands on a network device. i can't seem to
figure out how to log both the input and output of what the pexpect script
initiates and responds to.
child = pexpect.spawn ('telnet '+ ip)
child.expect ('.*:*')
child.sendline (user)
child.expect ('.*:*')
child.sendline (password)
child.expect(['.*#*', '.*>*'])
child.sendline ('enable')
child.expect (['Password:', '.*#*'])
child.sendline (password)
child.expect ('.*#*')
child.sendline ('conf t')
child.expect ('.*#*')
child.sendline ('line vty 0 4')
i have tried both these logging commands:
child.logfile = open('log.txt', 'w')
child.logfile=sys.stdout
all i get is the input i send with expect/sendline combinations, i don't get
any of what the device sends, only what i send the device:
user
password
enable
password
conf t
line vty 0 4
any ideas of what is the correct way to go about this? just can't get the
output!
--
https://mail.python.org/mailman/listinfo/python-list
using globals
Hi,
I have got a problem with importing global variables. For instance I have
got two files:
# t1.py #t2.py
counter = 1
def counter_adder(filenr): def show_adder():
global counter import t1
counter+= 1 print("adder
is %d" % t1.counter)
if filenr == 1:
show_adder()
else:
import t2
t2.show_adder()
def show_adder():
print("adder is %d" % counter)
>>counter_adder(1)
adder is 2
>>counter_adder(2)
adder is 1
When I look at the outcome of two function calls I expected no differences
but much to my surprise it goes wrong when the global variable is imported.
It doesn't give the updated value but the value it get when instantiated.
Who come? What should I do to get the updated value
greetings,
Sjaak van Werkhoven
--
http://mail.python.org/mailman/listinfo/python-list
Re: Perl Template Toolkit: Now in spicy new Python flavor
Congrats. This will no doubt prove valuable to any Python programmer. -- http://mail.python.org/mailman/listinfo/python-list
