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
>>> 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
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
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
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
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
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*\([^\)]*
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
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
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
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
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_
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
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,
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
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_
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
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
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
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
, 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
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
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
math terms...
--
Qiangning Hong
__
( Michael:)
( )
( Hi. I'm Michael Jackson, from The Jacksons. )
( )
( Homer: I&
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
Python?
>
> Thanks for any insights.
>
> cheers,
> Didier.
You should use something like this:
dir = "/home/cypher"
system("ls %s" % dir)
--
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
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
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 &
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
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
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
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
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
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
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
>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
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
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
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
40 matches
Mail list logo