Re: How can I create customized classes that have similar properties as 'str'?

2007-11-27 Thread Licheng Fang
On Nov 27, 10:45 am, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sun, 25 Nov 2007 02:42:36 -0800, Licheng Fang wrote: I mentioned trigram counting as an illustrative case. In fact, you'll often need to define patterns more complex than that, and tens of megabytes of text may generate

Re: How can I create customized classes that have similar properties as 'str'?

2007-11-25 Thread Licheng Fang
On Nov 25, 5:59 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sat, 24 Nov 2007 03:44:59 -0800, Licheng Fang wrote: On Nov 24, 7:05 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: Licheng Fang wrote: I find myself frequently in need of classes like

How can I create customized classes that have similar properties as 'str'?

2007-11-24 Thread Licheng Fang
I mean, all the class instances that equal to each other should be reduced into only one instance, which means for instances of this class there's no difference between a is b and a==b. Thank you. -- http://mail.python.org/mailman/listinfo/python-list

Re: How can I create customized classes that have similar properties as 'str'?

2007-11-24 Thread Licheng Fang
I find myself frequently in need of classes like this for two reasons. First, it's efficient in memory. Second, when two instances are compared for equality only their pointers are compared. (I think that's how Python compares 'str's. On Nov 24, 6:31 pm, Licheng Fang [EMAIL PROTECTED] wrote: I

Re: How can I create customized classes that have similar properties as 'str'?

2007-11-24 Thread Licheng Fang
On Nov 24, 7:05 pm, Bjoern Schliessmann usenet- [EMAIL PROTECTED] wrote: Licheng Fang wrote: I find myself frequently in need of classes like this for two reasons. First, it's efficient in memory. Are you using millions of objects, or MB size objects? Otherwise, this is no argument. Yes

Re: How can I create customized classes that have similar properties as 'str'?

2007-11-24 Thread Licheng Fang
On Nov 24, 9:42 pm, Marc 'BlackJack' Rintsch [EMAIL PROTECTED] wrote: On Sat, 24 Nov 2007 13:40:40 +0100, Bjoern Schliessmann wrote: Licheng Fang wrote: On Nov 24, 7:05 pm, Bjoern Schliessmann usenet- Wow, I didn't know this. But exactly how Python manage these strings? I don't know

Accessing Function Variables from Sub-functions

2007-10-11 Thread Licheng Fang
On Apr 14 2003, 10:30 pm, Alex Martelli [EMAIL PROTECTED] wrote: Sebastian Wilhelmi wrote: Hi, I would like to do the following: ---8---8---8---8--- def test (): count = 0 def inc_count (): count += 1 inc_count () inc_count ()

Re: Problem of Readability of Python

2007-10-10 Thread Licheng Fang
On Oct 8, 4:24 am, [EMAIL PROTECTED] (Alex Martelli) wrote: Licheng Fang [EMAIL PROTECTED] wrote: ... Python Tutorial says an empty class can be used to do this. But if namespaces are implemented as dicts, wouldn't it incur much overhead if one defines empty classes as such for some

Problem of Readability of Python

2007-10-07 Thread Licheng Fang
Python is supposed to be readable, but after programming in Python for a while I find my Python programs can be more obfuscated than their C/C ++ counterparts sometimes. Part of the reason is that with heterogeneous lists/tuples at hand, I tend to stuff many things into the list and *assume* a

Re: How to get the longest possible match with Python's RE module?

2006-09-14 Thread Licheng Fang
Thank you guys. I've written a CYK parser and realized this is the right direction. It gives every possible interpretation of the string and I can retrieve whatever I want. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get the longest possible match with Python's RE module?

2006-09-12 Thread Licheng Fang
Thank you very much, Tim and Monkee. In fact, what I'm doing is handle a lot of regular expressions. I wanted to build VERY LONG regexps part by part and put them all into a file for easy modification and maintenance. The idea is like this: (*INT) = \d+ (*DECIMAL) = (*INT)\.(*INT) (*FACTION) =

Re: How to get the longest possible match with Python's RE module?

2006-09-12 Thread Licheng Fang
Bryan Olson wrote: Licheng Fang wrote: Oh, please do have a look at the second link I've posted. There's a table comparing the regexp engines. The engines you've tested probably all use an NFA implementation. Unfortunately, the stuff about NFA's is wrong. Friedl's awful book

Re: How to get the longest possible match with Python's RE module?

2006-09-12 Thread Licheng Fang
[EMAIL PROTECTED] wrote: kondal wrote: This is the way the regexp works python doesn't has anything to do with it. It starts parsing the data with the pattern given. It returns the matched string acording the pattern and doesn't go back to find the other combinations. I've recently

How to get the longest possible match with Python's RE module?

2006-09-11 Thread Licheng Fang
Basically, the problem is this: p = re.compile(do|dolittle) p.match(dolittle).group() 'do' Python's NFA regexp engine trys only the first option, and happily rests on that. There's another example: p = re.compile(one(self)?(selfsufficient)?) p.match(oneselfsufficient).group() 'oneself' The

Re: How to get the longest possible match with Python's RE module?

2006-09-11 Thread Licheng Fang
MonkeeSage wrote: Licheng Fang wrote: Basically, the problem is this: p = re.compile(do|dolittle) p.match(dolittle).group() 'do' From what I understand, this isn't python specific, it is the expected behavior of that pattern in any implementation. You are using alternation, which

Re: How to get the longest possible match with Python's RE module?

2006-09-11 Thread Licheng Fang
Oh, please do have a look at the second link I've posted. There's a table comparing the regexp engines. The engines you've tested probably all use an NFA implementation. MonkeeSage wrote: Licheng Fang wrote: Hi, according to these regexp engine discussions, it's NOT a behavior true to any

Python and STL efficiency

2006-08-21 Thread Licheng Fang
Hi, I'm learning STL and I wrote some simple code to compare the efficiency of python and STL. //C++ #include iostream #include string #include vector #include set #include algorithm using namespace std; int main(){ vectorstring a; for (long int i=0; i1 ; ++i){

Re: Python and STL efficiency

2006-08-21 Thread Licheng Fang
Marc 'BlackJack' Rintsch wrote: In [EMAIL PROTECTED], Licheng Fang wrote: Hi, I'm learning STL and I wrote some simple code to compare the efficiency of python and STL. //C++ #include iostream #include string #include vector #include set #include algorithm using namespace

Re: Modules... paths... newbie confusion

2006-08-21 Thread Licheng Fang
MrBlueSky wrote: I wonder if someone could clarify how Python knows where modules are - or at least point to some documentation that might help me? Here's what I've been trying: I've installed Python 2.4 Windows, and have also installed tkinter, pmw, cx_Oracle, mssql and pytz (phew!) all

Nested Lists Assignment Problem

2006-04-26 Thread Licheng Fang
I wanna use nested lists as an array, but here's the problem: a = [[0]*3]*3 a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] a[0][0] = 1 a [[1, 0, 0], [1, 0, 0], [1, 0, 0]] Could anybody please explain to me why three values were change? I'm bewildered. Thanks! --

Re: Nested Lists Assignment Problem

2006-04-26 Thread Licheng Fang
Dennis Lee Bieber wrote: On 26 Apr 2006 01:13:20 -0700, Licheng Fang [EMAIL PROTECTED] declaimed the following in comp.lang.python: Could anybody please explain to me why three values were change? I'm bewildered. Thanks! http://www.aifb.uni-karlsruhe.de/Lehrangebot/Winter2000-01/E-Shop

How to configure proxy authentication when using urllib2?

2006-02-19 Thread Licheng Fang
I use a HTTP proxy to connect to Internet. When I run ulropen command I get HTTP Error 407: Proxy authorization required. Could anybody tell me how to resolve this? Thanks! -- http://mail.python.org/mailman/listinfo/python-list

How to get the type of an object?

2005-12-21 Thread Licheng Fang
I wrote a function with a list as its parameter. And the function has to perform different operations based on the datatypes of the elements. How can I decide whether an object is, say, a list or a string? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get the type of an object?

2005-12-21 Thread Licheng Fang
That helps. Thank you guys. -- http://mail.python.org/mailman/listinfo/python-list