Kent Johnson | 1 Sep 01:19 2006
Picon

Re: logging module, how to print line numbers?

Hans Fangohr wrote:
> Hi,
>
> I have some trouble with the logging module.
>
> When I run this program with python2.3:
>
> #------------
> import logging,sys
> formatter = logging.Formatter('%(name)s :%(asctime)s %(filename)s
> %(lineno)s %(levelname)s  %(message)s')
> stdout_handler = logging.StreamHandler(sys.stdout)
> stdout_handler.setFormatter(formatter)
> logger=logging.getLogger('')
> logger.addHandler(stdout_handler)
> logger.setLevel(logging.DEBUG)
> logging.debug('A debug message')
> logging.info('Some information')
> logging.warning('A shot across the bows')
> #------------
>
> I get the following output:
>
> root :2006-08-31 20:20:15,085 __init__.py 988 DEBUG  A debug message
> root :2006-08-31 20:20:15,085 __init__.py 988 INFO  Some information
> root :2006-08-31 20:20:15,085 __init__.py 988 WARNING  A shot across thebows
>
> Note that the line number always appears as 988. I'd like it to be the
> line number where the logging command has been executed. The documentation
> says that %(lineno)d should work 'if available'.
(Continue reading)

ralf.steckel | 1 Sep 03:24 2006

Re: logging module, how to print line numbers?

Dear Hans,

i haven't worked with the logging module yet but as a guess from what you write in your message:

according to the documentation the format statement for lineno should be %(lineno)d, but you use %(lineno)s.

Best regards,

Ralf

> Hi,
> 
> I have some trouble with the logging module.
> 
> When I run this program with python2.3:
> 
> #------------
> import logging,sys
> formatter = logging.Formatter('%(name)s :%(asctime)s %(filename)s
> %(lineno)s %(levelname)s  %(message)s')
> stdout_handler = logging.StreamHandler(sys.stdout)
> stdout_handler.setFormatter(formatter)
> logger=logging.getLogger('')
> logger.addHandler(stdout_handler)
> logger.setLevel(logging.DEBUG)
> logging.debug('A debug message')
> logging.info('Some information')
> logging.warning('A shot across the bows')
> #------------
> 
(Continue reading)

Sean Perry | 1 Sep 05:52 2006
Picon

Re: Python decorator

János Juhász wrote:
> Hi,
> 
> I have just started to play with TurboGears - it is really nice - and I 
> couldn't understand the decorators used by it.
> I have tried to interpret the http://wiki.python.org/moin/PythonDecorators 
> about decorators, but it is too difficult for me.
> 
> May someone explain decorators in very sortly, what is it for and why ?
> Do I need it anyway ?
> 

A decorator is a function that takes a function and returns a new, 
modified function.

In Django (a similar framework) there are a few places where decorators 
are used.

 <at> login_required
def foo_view(args):
   # a view that must be authenticated
   # more code here

This means that before foo_view() is ran the function login_required is 
run. Which in this case will redirect to a login screen if the user is 
not currently authenticated.

here's the Django code:
def user_passes_test(test_func, login_url=LOGIN_URL):
     """
(Continue reading)

Hans Fangohr | 1 Sep 08:18 2006
Picon

Re: logging module, how to print line numbers?

Hi Kent,

> > I have some trouble with the logging module.
> >
> > When I run this program with python2.3:
> >
> > #------------
> > import logging,sys
> > formatter = logging.Formatter('%(name)s :%(asctime)s %(filename)s
> > %(lineno)s %(levelname)s  %(message)s')
> > stdout_handler = logging.StreamHandler(sys.stdout)
> > stdout_handler.setFormatter(formatter)
> > logger=logging.getLogger('')
> > logger.addHandler(stdout_handler)
> > logger.setLevel(logging.DEBUG)
> > logging.debug('A debug message')
> > logging.info('Some information')
> > logging.warning('A shot across the bows')
> > #------------
> >
> > I get the following output:
> >
> > root :2006-08-31 20:20:15,085 __init__.py 988 DEBUG  A debug message
> > root :2006-08-31 20:20:15,085 __init__.py 988 INFO  Some information
> > root :2006-08-31 20:20:15,085 __init__.py 988 WARNING  A shot across thebows
> >
> > Note that the line number always appears as 988. I'd like it to be the
> > line number where the logging command has been executed. The documentation
> > says that %(lineno)d should work 'if available'.
> >
(Continue reading)

learner404 | 1 Sep 11:58 2006
Picon

Tkinter: 'explanation text' when the mouse is over an image button ?

Hello,

With a Tkinter app I have buttons with an image filling each button like this,

bu10=Button(frame2, image=picPlay, bg="white", command=play)

I want to give a small explanation of each button when the user puts the mouse over the picture (something like the title tag in a hyperlink).
I thougth I saw this in Tkinter but can't find it here:
http://effbot.org/tkinterbook/button.htm

Thanks for any suggestions to achieve this.

learner404

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor
Kent Johnson | 1 Sep 13:49 2006
Picon

Re: Tkinter: 'explanation text' when the mouse is over an image button ?

learner404 wrote:
> Hello,
>
> With a Tkinter app I have buttons with an image filling each button like
> this,
>
> bu10=Button(frame2, image=picPlay, bg="white", command=play)
>
> I want to give a small explanation of each button when the user puts the
> mouse over the picture (something like the title tag in a hyperlink).
> I thougth I saw this in Tkinter but can't find it here:
> http://effbot.org/tkinterbook/button.htm

You want a tooltip for the button. There is nothing built-in to Tkinter 
to do this. Here are a couple of possibilities:
http://www.voidspace.org.uk/python/weblog/arch_d7_2006_07_01.shtml#e387
http://tkinter.unpythonic.net/wiki/ToolTip

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Kent Johnson | 1 Sep 13:58 2006
Picon

Re: logging module, how to print line numbers?

Hans Fangohr wrote:
> Hi Kent (and others),
>
> On 01/09/06, Kent Johnson <kent37 <at> tds.net> wrote:
>   
>> How are you running the program? What OS? What Python (2.3.??)
>>     
> This is python 2.3.5 on Debian etch. Same results with python 2.4.4 on
> Debian etch (although 'the linenumber' is 1072 instead of 988).
>   
Running from the command line or in IDLE or ??
>   
>> Looking at the source (Python23\Lib\logging\__init__.py), the line
>> number is pulled out of the stack by walking up the stack looking for a
>> frame whose filename is different from _srcfile. What do you get if you
>> print logging._srcfile and logging.__file__?
>>     
> /usr/lib/python2.4/logging/__init__.py
> /usr/lib/python2.4/logging/__init__.pyc
>
> I guess these files should rather be my source file(?). But they aren't.
>   
No, they seem correct, they are the source file of the logging module.

I'm perplexed, the values above seem correct.

The way the logging module finds the line number is, it walks up through 
the stack looking for a stack frame that references a file different 
from the file containing the module itself. It uses the file and line 
number from that stack frame for the log.

For some reason your stack frame has something different. One thing you 
could do is add a print to the logging module itself to see what it is 
seeing. In Python 2.3, there is a findCaller() method at lin 961 of 
logging/__init__.py. You could add
  print filename
just after the line
  filename = os.path.normcase(co.co_filename)

Then run your program again and see what it prints out.

Kent

_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Danny Yoo | 1 Sep 16:33 2006
Picon

Re: Securing a Computer...

>> I just got into high school, and the network and all the computers 
>> aren't secure at all...I'm trying to make a program that password 
>> protects the computer after an inactivity time, but there are some 
>> specific things I can't find how I'm supposed to do it.
>
> Windoze has this feature built in.  It's called 'locking' the computer. 
> Look into it.

Just as another non-Python comment: you should be using Control-Alt-Delete 
when logging into a Windows machine.  It's the only key combination that's 
untrappable by other programs besdies the Windows kernel.  See:

     http://en.wikipedia.org/wiki/Control-Alt-Delete#Windows_NT
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Lanky Nibs | 1 Sep 18:26 2006
Picon

SUPER NEWB: basic search and replace

I have a large volume of files to change so I need to
automate the search and replace. I'll be replacing
bits of text with other bits of text. This is working
for now but I'd like to know how a real programmer
would do it. The hard coded strings will eventually
come from a list. All sugestions welcome and
appreciated.

    #read all file lines into list and close
    allLines = fh.readlines()
    fh.close()

    #use split and join to replace a unique item
    chunk = allLines[0]
    splitChunk = chunk.split('xVAR1x')
    newChunk = 'my shoes fell off'.join(splitChunk)

	#write to a file
    file = open('test.html', 'w')
    for eachLine in newChunk:
    	print 'writing  line in text file'
    	file.write(eachLine)
    file.close()

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor

Dave Kuhlman | 1 Sep 18:55 2006

Re: SUPER NEWB: basic search and replace

On Fri, Sep 01, 2006 at 09:26:36AM -0700, Lanky Nibs wrote:
> I have a large volume of files to change so I need to
> automate the search and replace. I'll be replacing
> bits of text with other bits of text. This is working
> for now but I'd like to know how a real programmer
> would do it. The hard coded strings will eventually
> come from a list. All sugestions welcome and
> appreciated.
> 
>     #read all file lines into list and close
>     allLines = fh.readlines()
>     fh.close()
>     
>     #use split and join to replace a unique item
>     chunk = allLines[0]
>     splitChunk = chunk.split('xVAR1x')
>     newChunk = 'my shoes fell off'.join(splitChunk)

Instead, consider the following:

    for line in allLines:
        line = line.replace('xVAR1x', 'my shoes fell off')
        outfile.write(line)

Dave

> 
> 	#write to a file
>     file = open('test.html', 'w')
>     for eachLine in newChunk:
>     	print 'writing  line in text file'
>     	file.write(eachLine)
>     file.close()
> 

--

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
_______________________________________________
Tutor maillist  -  Tutor <at> python.org
http://mail.python.org/mailman/listinfo/tutor


Gmane