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
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
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
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
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
-
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
> "
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
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
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
> 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 -
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
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):
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
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
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
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.
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
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
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
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
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
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
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
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
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
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
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
IE should be able to do that. Install the win32 modules. Then you should
simply embed Python using
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
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
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
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
> 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
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
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
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
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
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.
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
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
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
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
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
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
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
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
46 matches
Mail list logo