no longer can set breakpoint on 'pass' statement?

2006-08-16 Thread Mark Winrock
Can someone point me to some documentation as to why pdb breakpoints are 
not working on 'pass' statements (at least on 2.4.1)?

I was used to that working in the 2.2.3 build I was using up to this 
last year. I just cant seem to find anything on it.

Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How do I catch ExpatError exception?

2006-08-16 Thread Mark Winrock
Shuaib wrote:
 Hey!
 
 I am getting this exception.
 
 xml.parsers.expat.ExpatError
 
 But I am not able to catch it with except
 xml.parsers.expat.ExpatError: It says NameError: global name 'xml' is
 not defined.
 
 I am also not able to catch it with except ExpatError: Gives
 NameError: global name 'xml' is not defined
 
 How do I catch it? (I am parsing an xml file)

Have you imported xml.parsers.expat to get it properly scoped?

 
 Also, how do I get the line number where an exception was thrown?
 
Try looking at the 'sys.exc_info' and the 'traceback' module 
documentation. Also see Python Cookbook recipe Recipe 8.6. Getting More 
Information from Tracebacks (Bryn Keller)



 Thanks.
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: text analysis in python

2005-04-03 Thread Mark Winrock
Maurice Ling wrote:
Hi,
I'm a postgraduate and my project deals with a fair bit of text 
analysis. I'm looking for some libraries and tools that is geared 
towards text analysis (and text engineering). So far, the most 
comprehensive toolkit in python for my purpose is NLTK (natural language 
tool kit) by Edward Loper and Steven Bird, followed by mxTextTools. Are 
there any OSS tools out there that is more comprehensive than NLTK?

In the Java world, there is GATE (general architecture for text 
engineering) and it seems very impressive. Are there something like that 
for Python?

Thanks in advance.
Cheers
Maurice

You might try http://web.media.mit.edu/~hugo/montylingua/
Liu, Hugo (2004). MontyLingua: An end-to-end natural
language processor with common sense. Available
at: web.media.mit.edu/~hugo/montylingua.
--
http://mail.python.org/mailman/listinfo/python-list


Re: instance name

2005-04-02 Thread Mark Winrock
max(01)* wrote:
hi.
is there a way to define a class method which prints the instance name?
e.g.:
  class class_1:
...   def myName(self):
... what should i do here
...
  instance_1 = class_1()
  instance_1.myName()
'instance_1'
 
bye
macs
macs,
The object instance doesn't know about the identifier to which you 
assigned it (but see my example below using the inspect module).

If you are just trying to identify different instances, you can get a 
unique instance identifier from hash() function
	hash(instance1)

or
self.__hash__(), or hash(self) from within the object
The default __str__ for a class will normally return something similar 
with more information , so that when you
	print instance_1
you get a string in the following format:
	module.classname object at hashvalue

The following is a very, very, very weak example of how you might use 
inspect to get the information you want. This is not a robust example at 
all, and I imagine it could have many ways it will fail. The init uses 
inspect information to dip into the source file and parse out the info 
-- like I said, this is not a robust parse.
# 
import os,sys

class class_1(object):
def __init__(self):
import inspect
self.lineno = inspect.currentframe().f_back.f_lineno
self.filename = inspect.currentframe().f_back.f_code.co_filename
self.initial_instance = None
try:
# i'm not sure if filename is full path or not at this time
f=open(self.filename,'r')
lines=f.readlines()
s = lines[self.lineno-1]
split = s.split()
try:
# find the assignment if possible
i = split.index('=')
self.initial_instance = split[i-1]
except ValueError:
pass
finally:
f.close()
def myName(self):
print 'my initial instance was \'%s\''%(self.initial_instance)
if __name__ == '__main__':
# two straight up examples
instance_1 = class_1()
instance_2 = class_1()
instance_1.myName()
instance_2.myName()
#
class_1().myName()
c = instance_1
c.myName()
# ---
I got the following results:
my initial instance was 'instance_1'
my initial instance was 'instance_2'
my initial instance was 'None'
my initial instance was 'instance_1'

Best-regards,
Mark
--
http://mail.python.org/mailman/listinfo/python-list