Why Python allows comparison of a callable and a number?

2009-11-22 Thread
I used python to write an assignment last week, here is a code snippet # def departTime(): ''' Calculate the time to depart a packet. ''' if(random.random < 0.8): t = random.expovariate(1.0 / 2.5) else: t = random.expovariate(1.0

"undefined symbol: TLSv1_method" error when import psycopg2

2009-10-13 Thread
I installed psycopg2 by "easy_install psycopg2" on CentOS 5.3, no error was reported, but when I tried "import psycopg2", I got : exceptions.ImportError: /usr/lib/python2.4/site-packages/ psycopg2-2.0.9-py2.4-linux-i686.egg/psycopg2/_psycopg.so: undefined symbol: TLSv1_method What might cause

Less APIs or more encapsulation?

2009-09-09 Thread
2 class, B contains C. When user want to use some service of C, there are two choice: First, more encapsulation: = class B: def newMethod(self): self.c.newMethod() class C: def newMethod(self): #do something pass b.newMethod()

Should we separate business logic and ORM mapping classes?

2009-04-14 Thread
Hi, ( First, this is not a question about if we should use ORM. It's question for these who are already using it. ) Usually, I only use ORM, like sqlalchemy just as an abstraction layer of database. So these mapping objects I wrote only contains data but not behavior. For example, if I have a

Re: Need advise about an application

2009-04-05 Thread
Do you have to show these data on GUI? If so, why not use the event pattern? As far as I know, it's the standard way wxPython works. BTW : If it's not complicated, I think maybe some wysiwyg solution is better. I use python for almost every thing, except these related to GUI. On Apr 5, 8:31 pm,

Re: A design problem I met again and again.

2009-04-04 Thread
might review them many times in my future work. On Apr 4, 12:10 pm, Carl Banks wrote: > On Apr 2, 11:25 pm, 一首诗 wrote: > > > > > Consolidate existing functions? > > > I've thought about it. > > > For example, I have two functions: > > > #===

Re: User or UserManager ? Problems of Observer Pattern

2009-04-04 Thread
improve it. On Apr 4, 1:14 pm, Michele Simionato wrote: > On Apr 3, 7:34 pm, 一首诗 wrote: > > > > > # > > # Choice 2 > > # > > > class UserManager: > > > users = [] > > > @classmethod > >

User or UserManager ? Problems of Observer Pattern

2009-04-03 Thread
#This is a real world problem I met. # #We have a database containing serveral tables, like : user, role, organization. Each 2 of them has m:n relationships. These relations are stored in association tables. # #Not we have to load all these data in memory to gain higher performances. We create 3

Re: A design problem I met again and again.

2009-04-02 Thread
"XXX"): pass else if(type == "YYY"): pass #= But isn't the first style more clear for my code's user? That's one reason why my interfaces grow fast. On Apr 3, 1:51 am, Carl Banks wrote: > On Apr 2, 8:02 am, 一首诗

Re: A design problem I met again and again.

2009-04-02 Thread
rote: > On Apr 1, 12:44 am, 一首诗 wrote: > > > I got the same problem when writing C#/C++ when I have to provide a > > lot of method to my code's user. So I create a big class as the entry > > point of my code. Although these big classes doesn't contains muc

Re: A design problem I met again and again.

2009-04-01 Thread
On Apr 1, 4:55 pm, Lawrence D'Oliveiro wrote: > In message <48506803-a6b9-432b-acef- > > b75f76e90...@v23g2000pro.googlegroups.com>, 一首诗 wrote: > > Until one day I find service has nearly 100 methods and 6000 lines of > > code.   I don't need to read any progr

Re: A design problem I met again and again.

2009-04-01 Thread
I also think that's my best choice. Before I wrote my mail, I already knew that this is not a good question. It lacks details, and it is too big. But I think the first step to resolve a problem is to describe it. In that way, I might find the answer myself On Apr 1, 6:40 pm, "andrew cooke"

A design problem I met again and again.

2009-04-01 Thread
Hi all, I am a programmer who works with some different kinds of programming languages, like python, C++(in COM), action script, C#, etc. Today, I realized that, what ever language I use, I always meet a same problem and I think I never solve it very well. The problem is : how to break my app in

Is this the right way to use unicode in a user defined Exception?

2009-02-25 Thread
# class MyError(Exception): def __init__(self): self.message = u'Some Chinese:中文' def __str__(self): return self.message.encode('utf8') # This is an exception that I defined.

Re: Is there something easier than ORM?

2009-02-17 Thread
ng another library means more chances of bugs? On Feb 17, 9:24 pm, "Diez B. Roggisch" wrote: > 一首诗 schrieb: > > > > > Hi all, > > > Recently I am studying some python ORM libraries, such as sqlalchemy. > > > These are very powerful technologies to handle d

Is there something easier than ORM?

2009-02-17 Thread
Hi all, Recently I am studying some python ORM libraries, such as sqlalchemy. These are very powerful technologies to handle database. But I think my project are not complicated to enough to benefit from a complete ORM system. What I really want, is some easy ways to load data from database, an

Re: A little comments of ctypes and construct.

2008-11-21 Thread
OK, I was wrong with construct! I wrote to the author and he replied. It works! I am really glad there IS a easy way to handle binary data in python. >>> from construct import * >>> >>> >>> point = Struct("point", ... SNInt32("x"), # Signed, Native byte-order, Int 32 bits ('int' is platfo

Re: A little comments of ctypes and construct.

2008-11-21 Thread
n. On Nov 21, 6:30 pm, Aaron Brady <[EMAIL PROTECTED]> wrote: > On Nov 21, 2:28 am, 一首诗 <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > Recently I asked a question on this group: > > > >> What's your choice when handle complicated C

A little comments of ctypes and construct.

2008-11-21 Thread
Hi all, Recently I asked a question on this group: >> What's your choice when handle complicated C structures. I got these suggestion: 1) try construct 2) try ctypes I spend half a day on construct and here's my conclusion: 1. It really good for parse(unpack) data structur

Have you ever used pydiction?

2008-11-16 Thread
Hi all, Recently I am writing more codes in python with vim so I made some search for python auto completion plugins. Finally I found pydcition: http://www.vim.org/scripts/script.php?script_id=850 Anyway, it works. But I met one problem. After you have set isk+=.,( The dot "." becomes p

Re: parsing non-ascii characters

2008-11-09 Thread
On Nov 10, 10:13 am, Ronn <[EMAIL PROTECTED]> wrote: > Hello all, > > I have a list: >   suffix = ["aĉ", "ad", "aĵ", "an", "ar"] > > and I'm trying to check a word to see if any of the suffixes exist in > the list for example: >   if word in suffix: >       print "A suffix exist in your word" > > w

Re: pysqlite install error on hp ux (ld: Can't find library for -lpython2.5)

2008-11-09 Thread
On Nov 10, 10:29 am, "Geon." <[EMAIL PROTECTED]> wrote: > hi everyone! > > when i install pysqlite i meet bellow error. ( use easy_install and > source code building same problem ) > > ld: Can't find library for -lpython2.5 > > what mean this message? and what i do? > > my system is hp-ux 11i v3. a

Re: Can read() be non-blocking?

2008-11-06 Thread
On Nov 7, 6:54 am, Thomas Christensen <[EMAIL PROTECTED]> wrote: > This issue has been raised a couple of times I am sure.  But I have yet > to find a satisfying answer. > > I am reading from a subprocess and this subprocess sometimes hang, in > which case a call to read() call will block indefinit

Re: convert to XMLRPC

2008-11-06 Thread
On Nov 7, 8:22 am, Michel Perez <[EMAIL PROTECTED]> wrote: > Que vola a todos: >  I have an object abstraction layer that allows me to comunicate and > interact with my DB server without much problems -am thinking in > possibles contributors. > >  In the stdlib xmlrpclib handles this in a common wa

Re: I need a simple windows form handle.

2008-11-06 Thread
On Nov 7, 4:55 am, Aaron Brady <[EMAIL PROTECTED]> wrote: > On Nov 6, 7:50 am, 一首诗 <[EMAIL PROTECTED]> wrote: > > > > > Hi all, > > > Today I was writing a simple test app for a video decoder library. > > > I use python to parse video files and input

I need a simple windows form handle.

2008-11-06 Thread
Hi all, Today I was writing a simple test app for a video decoder library. I use python to parse video files and input data to the library. I got a problem here, I need a windows form, and send the form handle to the library as a parameter, then it can output video on the form. Here is my prob

What's your choice when handle complicated C structures.

2008-11-04 Thread
Hi all, Recently I am writing a small network application with python. The protocol is binary based and defined in c header files. Now I'm using the upack function of 'struct' module, but it's really annoying to write fmt strings for complicated structures. What will be your choice when handlin

Re: Efficient way to remove objects from a list

2008-11-03 Thread
Thanks! That's a more clear way! On Nov 3, 9:38 pm, Peter Otten <[EMAIL PROTECTED]> wrote: > Chris Rebert wrote: > > On Mon, Nov 3, 2008 at 1:40 AM, 一首诗 <[EMAIL PROTECTED]> wrote: > >> Hi all, > > >> Today I wrote some code like this: > > >

Efficient way to remove objects from a list

2008-11-03 Thread
Hi all, Today I wrote some code like this: for m in self.messages: if not m.finished: continue #process the message fini = [m for m in self.messages if m.finished] for m in fini: self.messages.remove(m) As you can, I w

What's your first choice if you have to write a C module for python?

2008-08-26 Thread
Hi all, I read this interesting post comparing Boost.Python with Pyd: http://pyd.dsource.org/vsboost.html What's your opinion about it? What's your first choice when you have write a C/C++ module for Python? -- http://mail.python.org/mailman/listinfo/python-list

Please recommend a RPC system working with twisted.

2008-07-21 Thread
Hi all, I'm looking for an RPC system working with twisted. 1. Binary. I want it run faster than any xml based RPC. 2. Bidirectional. Unlike HTTP, on which the client has to poll the sever for events, the server should "call" the client's method to notify events. 3. C/Python support. Part o

How to make python run faster

2008-04-14 Thread
I read this article on http://kortis.to/radix/python_ext/ And I decided to try if it's true. I write the program in 4 ways: 1. Pure C 2. Python using C extension 3. Python using psycho 4. Pure Python And then I used timeit to test the speed of these 4. Unsurprisingly, the time they cost were:

I am taking a programming performance match!

2006-12-21 Thread
Hi all, The question is like this: = One computer, 2 ethernet adapter. Receving UDP packages and send them out throught another adapter. The one who's program could support the heavies traffic could win a little bonus. = I am considerring tryin

wxPython and activex problem.

2006-12-19 Thread
Hi all! Have u tried genaxmodule.py provided by wxPython to create a wrapper module for an activex control? For me, some times it works, but some times, it doesn't. - Traceback (most recent call last): File "genaxmodule.py", line 42, in ? main(s

Re: How to convert " " in a string to blank space?

2006-10-30 Thread
Oh, I didn't make myself clear. What I mean is how to convert a piece of html to plain text bu keep as much format as possible. Such as convert " " to blank space and convert to "\r\n" Gary Herron wrote: > 一首诗 wrote: > > Is there any simple way to solve th

How to convert " " in a string to blank space?

2006-10-30 Thread
Is there any simple way to solve this problem? -- http://mail.python.org/mailman/listinfo/python-list

My python can not get addr info

2006-04-15 Thread
D:\python24\Lib\idlelib>pyshell.py Traceback (most recent call last): File "D:\python24\Lib\idlelib\PyShell.py", line 1388, in ? main() File "D:\python24\Lib\idlelib\PyShell.py", line 1361, in main if not flist.open_shell(): File "D:\python24\Lib\idlelib\PyShell.py", line 277, in open