Re: Unicode question : turn "José" into u"José"

2006-04-05 Thread aurora
First of all, if you run this on the console, find out your console's encoding. In my case it is English Windows XP. It uses 'cp437'. C:\>chcp Active code page: 437 Then >>> s = "José" >>> u = u"Jos\u00e9" # same thing in unicode escape >>> s.decode('cp437') == u # use encoding that

Re: Design mini-lanugage for data input

2006-03-21 Thread aurora
P.S. Also it is a 'mini-language' because it is an ad-hoc design that is good enough and can be easily implemented for a given problem. This is oppose to a general purpose solution like XML that is one translation from the original data format and carries too much baggages. > Just consider y

Re: Design mini-lanugage for data input

2006-03-21 Thread aurora
Yes. But they have different motivations. The mini-language concept is to design an input format that is convenient for human editor and that is close to the semi-structured data source. I think the benefit from ease of editing and flexibility would justify writing a little parsing code. JS

Re: datetime iso8601 string input

2006-03-20 Thread aurora
I agree. I just keep rewriting the parse method again and again. wy def parse_iso8601_date(s): """ Parse date in iso8601 format e.g. 2003-09-15T10:34:54 and returns a datetime object. """ y=m=d=hh=mm=ss=0 if len(s) not in [10,19,20]: raise ValueError('Invalid

Design mini-lanugage for data input

2006-03-20 Thread aurora
This is an entry I just added to ASPN. It is a somewhat novel technique I have employed quite successfully in my code. I repost it here for more explosure and discussions. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/475158 wy -

Re: HTMLTestRunner - generates HTML test report for unittest

2006-01-27 Thread aurora
On Fri, 27 Jan 2006 06:35:46 -0800, Paul McGuire <[EMAIL PROTECTED]> wrote: > Nice! I just adapted my pyparsing unit tests to use this tool - took me > about 3 minutes, and now it's much easier to run and review my unit test > results. I especially like the pass/fail color coding, and the > "

ANN: HTMLTestRunner - generates HTML test report for unittest

2006-01-26 Thread aurora
Greeting, HTMLTestRunner is an extension to the Python standard library's unittest module. It generates easy to use HTML test reports. See a sample report at http://tungwaiyip.info/software/sample_test_report.html. Check more information and download from http://tungwaiyip.info/software/#html

Re: decode unicode string using 'unicode_escape' codecs

2006-01-13 Thread aurora
Cool, it works! I have also done some due diligence that the utf-8 encoding would not introduce any Python escape accidentially. I have written a recipe in the Python cookbook: Efficient character escapes decoding http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/466293 wy > Does this

decode unicode string using 'unicode_escape' codecs

2006-01-12 Thread aurora
I have some unicode string with some characters encode using python notation like '\n' for LF. I need to convert that to the actual LF character. There is a 'unicode_escape' codec that seems to suit my purpose. >>> encoded = u'A\\nA' >>> decoded = encoded.decode('unicode_escape') >>> print len

Re: performance of recursive generator

2005-08-11 Thread aurora
> You seem to be assuming that a yield statement and a function call are > equivalent. I'm not sure that's a valid assumption. I don't know. I was hoping the compiler can optimize away the chain of yields. > Anyway, here's some data to consider: > > test.py -

Re: performance of recursive generator

2005-08-11 Thread aurora
On Thu, 11 Aug 2005 01:18:11 -0700, Matt Hammond <[EMAIL PROTECTED]> wrote: > >> Is it an inherent issue in the use of recursive generator? Is there any >> compiler optimization possible? > > Hi, I could be misunderstanding it myself, but I think the short answer > to your question is that i

performance of recursive generator

2005-08-10 Thread aurora
I love generator and I use it a lot. Lately I've been writing some recursive generator to traverse tree structures. After taking closer look I have some concern on its performance. Let's take the inorder traversal from http://www.python.org/peps/pep-0255.html as an example. def inorder(t):

win32clipboard.GetClipboardData() return string with null characters

2005-05-25 Thread aurora
there after the null character. It is easy enough to truncate them. But why does it get there in the first place? Is the data length somehow calculated wrong? I'm using Windows XP SP2 with Python 2.4 and pywin32-203. aurora -- http://mail.python.org/mailman/listinfo/python-list

Problem redirecting stdin on Windows

2005-05-25 Thread aurora
On Windows (XP) with win32 extension installed, a Python script can be launched from the command line directly since the .py extension is associated with python. However it fails if the stdin is piped or redirected. Assume there is an echo.py that read from stdin and echo the input. Launc

Re: Unit testing - one test class/method, or test class/class

2005-02-25 Thread aurora
I do something more or less like your option b. I don't think there is any orthodox structure to follow. You should use a style that fit your taste. What I really want to bring up is your might want to look at refactoring your module in the first place. 348 test cases for one module sounds lik

Re: Python and "Ajax technology collaboration"

2005-02-23 Thread aurora
It was discussed in the last Bay Area Python Interest Group meeting. Thursday, February 10, 2005 Agenda: Developing Responsive GUI Applications Using HTML and HTTP Speakers: Donovan Preston http://www.baypiggies.net/ The author has a component LivePage for this. You may find it from http://nevow.

Re: running a shell command from a python program

2005-02-23 Thread aurora
In Python 2.4, use the new subprocess module for this. It subsume the popen* methods. Hi, I'm a newbie, so please be gentle :-) How would I run a shell command in Python? Here is what I want to do: I want to run a shell command that outputs some stuff, save it into a list and do stuff with th

Re: unicode encoding usablilty problem

2005-02-20 Thread aurora
On Sun, 20 Feb 2005 15:01:09 +0100, Martin v. Löwis <[EMAIL PROTECTED]> wrote: Nick Coghlan wrote: Having "", u"", and r"" be immutable, while b"" was mutable would seem rather inconsistent. Yes. However, this inconsistency might be desirable. It would, of course, mean that the literal canno

Re: unicode encoding usablilty problem

2005-02-20 Thread aurora
On Sat, 19 Feb 2005 18:44:27 +0100, Fredrik Lundh <[EMAIL PROTECTED]> wrote: "aurora" <[EMAIL PROTECTED]> wrote: I don't want to mix them. But how could I find them? How do I know this statement can be potential problem if a==b: where a and b can be instantiated

Re: unicode and socket

2005-02-19 Thread aurora
On 18 Feb 2005 19:10:36 -0800, <[EMAIL PROTECTED]> wrote: It's really funny, I cannot send a unicode stream throuth socket with python while all the other languages as perl,c and java can do it. then, how about converting the unicode string to a binary stream? It is possible to send a binary throug

Re: unicode encoding usablilty problem

2005-02-18 Thread aurora
On Fri, 18 Feb 2005 21:16:01 +0100, Martin v. Löwis <[EMAIL PROTECTED]> wrote: I'd like to point out the historical reason: Python predates Unicode, so the byte string type has many convenience operations that you would only expect of a character string. We have come up with a transition strateg

Re: unicode encoding usablilty problem

2005-02-18 Thread aurora
On Fri, 18 Feb 2005 20:18:28 +0100, Walter Dörwald <[EMAIL PROTECTED]> wrote: aurora wrote: > [...] In Java they are distinct data type and the compiler would catch all incorrect usage. In Python, the interpreter seems to 'help' us to promote binary string to unicode

Re: unicode and socket

2005-02-18 Thread aurora
You could not. Unicode is an abstract data type. It must be encoded into octets in order to send via socket. And the other end must decode the octets to retrieve the unicode string. Needless to say the encoding scheme must be consistent and understood by both ends. On 18 Feb 2005 11:03:46 -0

Re: unicode encoding usablilty problem

2005-02-18 Thread aurora
On Fri, 18 Feb 2005 19:24:10 +0100, Fredrik Lundh <[EMAIL PROTECTED]> wrote: that's how you should do things in Python too, of course. a unicode string uses unicode internally. decode on the way in, encode on the way out, and things just work. the fact that you can mess things up by mixing u

Re: Newbie CGI problem

2005-02-18 Thread aurora
On Fri, 18 Feb 2005 18:36:10 +0100, Peter Otten <[EMAIL PROTECTED]> wrote: Rory Campbell-Lange wrote: #!/usr/bin/python import cgi print "Content-type: text/html\n\n" print "hi" Gives me the following in my browser: ''' hi Content-type: text/html hi ''' Why are there two 'hi's? You have chosen a ba

Re: Newbie CGI problem

2005-02-18 Thread aurora
Not sure about the repeated hi. But you are supposed to use \r\n\r\n, not just \n\n according to the HTTP specification. #!/usr/bin/python import cgi print "Content-type: text/html\n\n" print "hi" Gives me the following in my browser: ''' hi Content-type: text/html hi ''' Why are there two 'hi's

unicode encoding usablilty problem

2005-02-18 Thread aurora
I have long find the Python default encoding of strict ASCII frustrating. For one thing I prefer to get garbage character than an exception. But the biggest issue is Unicode exception often pop up in unexpected places and only when a non-ASCII or unicode character first found its way into the

Re: DHTML control from Python?

2005-02-14 Thread aurora
IE should be able to do that. Install the win32 modules. Then you should simply embed Python using

Re: Python Binary and Windows

2005-02-07 Thread aurora
Thanks for making me aware of the difflib module. I don't know there is such cool module exists. You can make it available to other Windows program as a COM object. The win32 api should be all you need. It might be slightly challenging because some parameters are list of strings which might

Re: executing VBScript from Python and vice versa

2005-02-04 Thread aurora
Go to the bookstore and get a copy of Python Programming on Win32 by Mark Hammond, Andy Robinson today. http://www.oreilly.com/catalog/pythonwin32/ It has everything you need. Is there a way to make programs written in these two languages communicate with each other? I am pretty sure that VBScr

Re: OT: why are LAMP sites slow?

2005-02-03 Thread aurora
aurora <[EMAIL PROTECTED]> writes: Slow compares to what? For a large commerical site with bigger budget, better infrastructure, better implementation, it is not surprising that they come out ahead compares to hobbyist sites. Hmm, as mentioned, I'm not sure what the commercial site

Re: OT: why are LAMP sites slow?

2005-02-03 Thread aurora
Slow compares to what? For a large commerical site with bigger budget, better infrastructure, better implementation, it is not surprising that they come out ahead compares to hobbyist sites. Putting implementation aside, is LAMP inherently performing worst than commerical alternatives like I

Re: Printing Filenames with non-Ascii-Characters

2005-02-02 Thread aurora
> print d.encode('cp437') So I would have to specify the encoding on every call to print? I am sure to forget and I don't like the program dying, in my case garbled output would be much more acceptable. Marian I'm with you. You never known you have put enough encode in all the right places a

Re: hotspot profiler experience and accuracy?

2005-02-02 Thread aurora
file from it subsequencely. In anycase the number of function call seems to make sense and it should give some insight to the runtime behaviour. The CPU time is just so misleading. aurora wrote: But the numbers look skeptical. Hotspot claim 71.166 CPU seconds but the actual elapsed ti

hotspot profiler experience and accuracy?

2005-02-01 Thread aurora
I have a parser I need to optimize. It has some disk IO and a lot of looping over characters. I used the hotspot profiler to gain insight on optimization options. The methods show up on on the top of this list seems fairly trivial and does not look like CPU hogger. Nevertheless I optimized i

Re: Printing Filenames with non-Ascii-Characters

2005-02-01 Thread aurora
On Tue, 01 Feb 2005 20:28:11 +0100, Marian Aldenhövel <[EMAIL PROTECTED]> wrote: Hi, I am very new to Python and have run into the following problem. If I do something like dir = os.listdir(somepath) for d in dir: print d The program fails for filenames that contain

Re: Next step after pychecker

2005-02-01 Thread aurora
A frequent error I encounter try: ...do something... except IOError: log('encounter an error %s line %d' % filename) Here in the string interpolation I should supply (filename,lineno). Usually I have a lot of unittesting to catch syntax error in the main code. But it is very difficu

Go visit Xah Lee's home page

2005-01-31 Thread aurora
Let's stop discussing about the perl-python non-sense. It is so boring. For a break, just visit Mr Xah Lee's personal page (http://xahlee.org/PageTwo_dir/Personal_dir/xah.html). You'll find lot of funny information and quotes from this queer personality. Thankfully no perl-python stuff there.

Re: Transparent (redirecting) proxy with BaseHTTPServer

2005-01-28 Thread aurora
a client strip the host name and not sending the host header either the web server wouldn't what address it is really looking for. If you caught some request that doesn't have host header it is a good idea to redirect them to a browser upgrade page. Thanks, aurora ;), aurora wr

Re: Transparent (redirecting) proxy with BaseHTTPServer

2005-01-27 Thread aurora
If you actually want the IP, resolve the host header would give you that. In the redirect case you should get a host header like Host: www.python.org From that you can reconstruct the original URL as http://www.python.org/ftp/python/contrib/. With that you can open it using urllib and proxy the

Re: limited python virtual machine (WAS: Another scripting language implemented into Python itself?)

2005-01-26 Thread aurora
It is really necessary to build a VM from the ground up that includes OS ability? What about JavaScript? On Wed, Jan 26, 2005 at 05:18:59PM +0100, Alexander Schremmer wrote: On Tue, 25 Jan 2005 22:08:01 +0100, I wrote: sys.safecall(func, maxcycles=1000) > could enter the safe mode and call

Re: list unpack trick?

2005-01-23 Thread aurora
On Sat, 22 Jan 2005 10:03:27 -0800, aurora <[EMAIL PROTECTED]> wrote: I am think more in the line of string.ljust(). So if we have a list.ljust(length, filler), we can do something like name, value = s.split('=',1).ljust(2,'') I can always break it down into mult

Re: list unpack trick?

2005-01-22 Thread aurora
Thanks. I'm just trying to see if there is some concise syntax available without getting into obscurity. As for my purpose Siegmund's suggestion works quite well. The few forms you have suggested works. But as they refer to list multiple times, it need a separate assignment statement like

list unpack trick?

2005-01-21 Thread aurora
I find that I use some list unpacking construct very often: name, value = s.split('=',1) So that 'a=1' unpack as name='a' and value='1' and 'a=b=c' unpack as name='a' and value='b=c'. The only issue is when s does not contain the character '=', let's say it is 'xyz', the result list ha

Re: "A Fundamental Turn Toward Concurrency in Software"

2005-01-08 Thread aurora
A lot of these ideas may not work or does not seems to matter much today. But in 10 years we might be really glad that we have tried. aurora <[EMAIL PROTECTED]> writes: Just gone though an article via Slashdot titled "The Free Lunch Is Over: A Fundamental Turn Toward Concurrency i

"A Fundamental Turn Toward Concurrency in Software"

2005-01-07 Thread aurora
Hello! Just gone though an article via Slashdot titled "The Free Lunch Is Over: A Fundamental Turn Toward Concurrency in Software" [http://www.gotw.ca/publications/concurrency-ddj.htm]. It argues that the continous CPU performance gain we've seen is finally over. And that future gain would