Re: sys.stdout.write()'s bug or doc bug?

2008-12-28 Thread Qiangning Hong
On Dec 27, 12:31 am, Martin wrote: > Python 2.4.4 (#2, Oct 22 2008, 19:52:44) > [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> u = u"\u554a" > >>> print u > 啊 > >>> sys.stdout.write(u + "\n") > > Tracebac

sys.stdout.write()'s bug or doc bug?

2008-12-25 Thread Qiangning Hong
>>> u = u'\u554a' >>> print u 啊 >>> sys.stdout.write(u) Traceback (most recent call last): File "", line 1, in UnicodeEncodeError: 'ascii' codec can't encode character u'\u554a' in position 0: ordinal not in range(128) >>> type(sys.stdout) >>> sys.stdout.encoding 'UTF-8' Quote from file object

Re: Prevent self being passed to a function stored as a member variable?

2006-09-04 Thread Qiangning Hong
On 4 Sep 2006 09:39:32 -0700, Sandra-24 <[EMAIL PROTECTED]> wrote: > How can you prevent self from being passed to a function stored as a > member variable? > > class Foo(object): >def __init__(self, callback): > self.func = callback > > f =Foo(lambda x: x) > f.func(1) # TypeError, func e

Re: Is this a good idea or a waste of time?

2006-08-24 Thread Qiangning Hong
On 24 Aug 2006 20:53:49 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > That's bad form. If you insist on doing something like this, at least > use "isinstance(a, str)" instead of typeof. But even that breaks duck > typing; if a is a unicode string, that'll fail when the function may > work

Re: splitting words with brackets

2006-07-26 Thread Qiangning Hong
Tim Chase wrote: > Ah...the picture is becoming a little more clear: > > >>> r = re.compile(r'(?:\([^\)]*\)|\[[^\]]*\]|\S)+') > >>> r.findall(s) > ['(a c)b(c d)', 'e'] > > It also works on my original test data, and is a cleaner regexp > than the original. > > The clearer the problem, the clearer

Re: splitting words with brackets

2006-07-26 Thread Qiangning Hong
Simon Forman wrote: > What are the desired results in cases like this: > > "(a b)[c d]" or "(a b)(c d)" ? ["(a b)[c d]"], ["(a b)(c d)"] -- http://mail.python.org/mailman/listinfo/python-list

Re: splitting words with brackets

2006-07-26 Thread Qiangning Hong
Simon Forman wrote: > def splitup(s): > return re.findall(''' > \S*\( [^\)]* \)\S* | > \S*\[ [^\]]* \]\S* | > \S+ > ''', s, re.VERBOSE) Yours is the same as Tim's, it can't handle a word with two or more brackets pairs, too. I tried to change the "\S*\([^\)]*

Re: splitting words with brackets

2006-07-26 Thread Qiangning Hong
Tim Chase wrote: > >>> import re > >>> s ='a (b c) d [e f g] h ia abcd(b c)xyz d [e f g] h i' > >>> r = re.compile(r'(?:\S*(?:\([^\)]*\)|\[[^\]]*\])\S*)|\S+') > >>> r.findall(s) > ['a', '(b c)', 'd', '[e f g]', 'h', 'ia', 'abcd(b c)xyz', 'd', > '[e f g]', 'h', 'i'] > [...] > However, the above

Re: splitting words with brackets

2006-07-26 Thread Qiangning Hong
faulkner wrote: > re.findall('\([^\)]*\)|\[[^\]]*|\S+', s) sorry i forgot to give a limitation: if a letter is next to a bracket, they should be considered as one word. i.e.: "a(b c) d" becomes ["a(b c)", "d"] because there is no blank between "a" and "(". -- http://mail.python.org/mailman/listi

splitting words with brackets

2006-07-26 Thread Qiangning Hong
I've got some strings to split. They are main words, but some words are inside a pair of brackets and should be considered as one unit. I prefer to use re.split, but haven't written a working one after hours of work. Example: "a (b c) d [e f g] h i" should be splitted to ["a", "(b c)", "d", "[e

Re: hash() yields different results for different platforms

2006-07-11 Thread Qiangning Hong
Grant Edwards wrote: > On 2006-07-11, Qiangning Hong <[EMAIL PROTECTED]> wrote: > > However, when I come to Python's builtin hash() function, I > > found it produces different values in my two computers! In a > > pentium4, hash('a') -> -468864544; in

hash() yields different results for different platforms

2006-07-11 Thread Qiangning Hong
I'm writing a spider. I have millions of urls in a table (mysql) to check if a url has already been fetched. To check fast, I am considering to add a "hash" column in the table, make it a unique key, and use the following sql statement: insert ignore into urls (url, hash) values (newurl, hash_of_

Re: How to build Python modules on windows?

2005-08-12 Thread Qiangning Hong
extensions need to be built with the same version of the compiler, but > it isn't installed. > --- Are you sure you have setup the environment variables before you build? Here is a reference: "Building Python Extensions with the MS Toolkit Compiler" (http://www.vrplumber.co

Re: need help with my append syntax

2005-08-12 Thread Qiangning Hong
has an "append" method). You can use "print addr" or "print repr(addr)" to determine that. > - Original Message - From: "Qiangning Hong" <[EMAIL PROTECTED]> > To: "yaffa" <[EMAIL PROTECTED]> > Cc: > Sent: Friday,

Re: need help with my append syntax

2005-08-12 Thread Qiangning Hong
NextSibling('td') > addr.append('%s;') Is addr is really a string? AFAIK, strings havn't an append methond. use += to extend strings: .>>> addr = 'abc' .>>> addr += '%s;' .>>> addr 'abc%s;' -- Qiangning Hon

what's wrong with my code using subprocess?

2005-07-23 Thread Qiangning Hong
count = 0 for line in p.stdout: data = line.strip() # process(data) count += 1 if count >= 1000: print >>p.stdin, 'exit' print 'waiting subprocess exit' p.wait() if __name__ == '__main_

Re: tuple to string?

2005-07-22 Thread Qiangning Hong
0x6D) (use string formatter): .>>> '%c%c%c%c' % t 'spam' (use struct model): .>>> import struct .>>> struct.pack('', *t) 'spam' -- Qiangning Hong I'm usually annoyed by IDEs because, for instance, they don't

Re: tuple to string?

2005-07-22 Thread Qiangning Hong
0x73, 0x70, 0x61, 0x6D) (use string formatter): .>>> '%c%c%c%c' % t 'spam' (use struct model): .>>> import struct .>>> struct.pack('', *t) 'spam' -- Qiangning Hong I'm usually annoyed by IDEs because, for in

Re: PyArg_ParseTuple help

2005-07-10 Thread Qiangning Hong
and ``v'' in the wrap function. And even further, the python caller can pass a python string to replace ``in'' and ``inlen''. Then, the prototype of the function is something like: def func(ins, v) which returns a string. [...] -- Qiangning Hong -- http://mail.python.org/mailman/listinfo/python-list

Re: frozenset question

2005-07-06 Thread Qiangning Hong
back (most recent call last): File "", line 1, in ? TypeError: set objects are unhashable .>> {s2:1} {frozenset([2]): 1} -- Qiangning Hong Get Firefox! <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1> -- http://mail.python.org/mailman/listinfo/python-list

Re: Create datetime instance using a tuple.

2005-07-06 Thread Qiangning Hong
, 3) > >>> dt = datetime(t) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: function takes at least 3 arguments (1 given) > > (class datetime(year, month, day[, hour[, minute[, second[, > microsecond[, tzinfo]) Use: dt = date

Re: debugger?

2005-07-03 Thread Qiangning Hong
Detlev Offenbach wrote: > Qiangning Hong wrote: > > >>I have read a lot of posts discussing python IDEs, but most of them >>focus on the editor, GUI builder, project management, customizability, >>etc Some talked about debugging capability, but only on an &g

debugger?

2005-07-03 Thread Qiangning Hong
ill you suggest? Or what more polish feature you want to see in an ideal python debugger? -- hope this thread will help IDE developers to fill their todo list with some shining ideas :) -- Qiangning Hong Get Firefox! <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1> -- h

how to shrink a numarray array?

2005-06-29 Thread Qiangning Hong
math terms... -- Qiangning Hong __ ( Michael:) ( ) ( Hi. I'm Michael Jackson, from The Jacksons. ) ( ) ( Homer: I&

Re: utf8 silly question

2005-06-21 Thread Qiangning Hong
In [2]:u = unicode(c, 'latin-1') In [3]:u8 = u.encode('UTF-8') In [4]:u8 Out[4]:'\xc2\xa9 some text' In [5]:print u8 © some text *NOTE*: At the last statement "print u8" I can print a UTF-8 string directly because my console is UTF-8 encoding. On your mach

Re: Can we pass some arguments to system("cmdline")?

2005-06-19 Thread Qiangning Hong
Python? > > Thanks for any insights. > > cheers, > Didier. You should use something like this: dir = "/home/cypher" system("ls %s" % dir) -- Qiangning Hong __

Re: collect data using threads

2005-06-14 Thread Qiangning Hong
ery sorry to take you too much effort on this weird code. I should make it clear that there is only *one* thread (the main thread in my application) calls the get_data() method, periodically, driven by a timer. And fo

collect data using threads

2005-06-14 Thread Qiangning Hong
t very sure about the get_data() method. Will it cause data lose if there is a thread is appending data to self.data at the same time? Is there a more pythonic/standard recipe to collect thread data? -- Qiangning Hong ___ < Those who c

Re: Show current ip on Linux

2005-06-13 Thread Qiangning Hong
It's important that this will work on a linux. i Have rwite some piece of > code that realy work under Windows XP, but the same script wil not work on > Linux. > > Verry thanks to all vulunteers. > How about use the shell command &

Re: compare two voices

2005-04-30 Thread Qiangning Hong
Jeremy Bowers wrote: > No matter how you slice it, this is not a Python problem, this is an > intense voice recognition algorithm problem that would make a good > PhD thesis. No, my goal is nothing relative to voice recognition. Sorry that I haven't described my question clearly. We are not teac

compare two voices

2005-04-30 Thread Qiangning Hong
I want to make an app to help students study foreign language. I want the following function in it: The student reads a piece of text to the microphone. The software records it and compares it to the wave-file pre-recorded by the teacher, and gives out a score to indicate the similarity between t

distutils question: different projects under same namespace

2005-04-16 Thread Qiangning Hong
To avoid namespace confliction with other Python packages, I want all my projects to be put into a specific namespace, e.g. 'hongqn' package, so that I can use "from hongqn.proj1 import module1", "from hongqn.proj2.subpack1 import module2", etc. These projects are developed and maintained and dist

distutils question: different projects under same namespace

2005-04-15 Thread Qiangning Hong
To avoid namespace confliction with other Python packages, I want all my projects to be put into a specific namespace, e.g. 'hongqn' package, so that I can use "from hongqn.proj1 import module1", "from hongqn.proj2.subpack1 import module2", etc. These projects are developed and maintained and dist

Re: distutils: package data

2005-03-30 Thread Qiangning Hong
ehh.. I did a little more reading and found that this function can be easily done by the new distutils parameter "package_data" in 2.4. However, I am using python2.3 :( So, my question becomes: how to emulate the package_data function in python 2.3? -- http://mail.python.org/mailman/listinfo/p

distutils: package data

2005-03-29 Thread Qiangning Hong
I am writing a setup.py for my package. I have a pre-compiled myextmod.pyd file in my package and I want the distutils to automatically copy it to C:\Python23\Lib\site-packages\mypackage\myextmod.pyd. I try to add the following parameter to setup(): data_file = [('mypackage', ['mypackage/myex

unittest help

2005-03-24 Thread Qiangning Hong
I want to apply TDD (test driven development) on my project. I am working on a class like this (in plan): # file: myclass.py import _extmod class MyClass(object): def __init__(self): self.handle = _extmod.open() def __del__(self): _extmod.close(self.handle) def some

how to absolute import?

2005-03-10 Thread Qiangning Hong
>From Guido's PEP8: - Relative imports for intra-package imports are highly discouraged. Always use the absolute package path for all imports. Does it mean I should put my develop directory into PYTHONPATH (e.g. /home/hongqn/devel/python) and use "import myproj1.package1.module

predict directory write permission under windows?

2004-12-13 Thread Qiangning Hong
I want to know if I can write files into a directory before I actually perferm the write behavor. I found os.access(path, os.W_OK) but it uses real uid/gid to check instead of euid/egid so it doesn't fit my problem. I don't know how to get euid/egid under windows so I cannot use the mode infom

Re: notification for cd insertion

2004-12-04 Thread Qiangning Hong
Qiangning Hong wrote: I want one of my function to execute when a cdrom is inserted. How can I achieve that? Further more, I want to do different things depend on the inserted disc type: if it is a normal cd-rom, read from it; if it is a recordable cd, write data on it. So, how can I get the

notification for cd insertion

2004-12-04 Thread Qiangning Hong
I want one of my function to execute when a cdrom is inserted. How can I achieve that? Further more, I want to do different things depend on the inserted disc type: if it is a normal cd-rom, read from it; if it is a recordable cd, write data on it. So, how can I get the inserted disc type inf