Why Python allows comparison of a callable and a number?
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 / 10.5) return t # Can you see the problem? I compare random.random with 0.8, which should be random.random(). Of course this because of my careless, but I don't get it. In my opinion, this kind of comparison should invoke a least a warning in any programming language. So why does python just ignore it? -- http://mail.python.org/mailman/listinfo/python-list
undefined symbol: TLSv1_method error when import psycopg2
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 the problem? -- http://mail.python.org/mailman/listinfo/python-list
Less APIs or more encapsulation?
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() == Sencond : Call seice of f c directly: = class B: pass class C: def newMethod(self): # somethining pass b.c.newMethod() = Generally, what I learned from books told me that 1st choice is better. But when C has many many methods to expose to outer user, 2nd choice seems to be more reasonable I In the first design, B.newMethod did nothing really useful. ctaully, , there are D/E/F, etc. in B we methodhod has to be exposed to user code, which makes encapsulation more tedious. In fact, these classes, C/D/E/F all have different jobs, but they all belongs to a real world object B, B is only a container of C/D/E/F. What do you think about it? -- http://mail.python.org/mailman/listinfo/python-list
Should we separate business logic and ORM mapping classes?
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 class User, I would write another class UserManager which with a methods like addUser, delUser. But recently I am thinking of moving these methods to User. That sounds more OO style. What's your opinion? What's the benefits and problems of this style? -- http://mail.python.org/mailman/listinfo/python-list
Re: Need advise about an application
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, azrael jura.gro...@gmail.com wrote: I am currently working on an application and I need a advise. I am supposed to read data from a device connected to a serial port. I am reading data using pySerial. The devise is sending signals with a time between two signals of one second. The application is supposed to collect the data and put it into a sqlite DB. wxPython GUI. I am worried about this asspect that I have two solutions how to do it but as I never tried it I wanted to ask for advise which one should be easier. solution 1): The GUI is set into a separate thread then the part of collecting and saving data. Well one thread for getting signals and saving data and the other for GUI and data presentation solution 2): create an event which is binded to pySerial read methon. Well when the devise sends a signal the event function is triggered. Or maybe combine the two? -- http://mail.python.org/mailman/listinfo/python-list
Re: User or UserManager ? Problems of Observer Pattern
Thanks for your advice. I studied python from the tutorial and the library manual, and I think I am familiar enough with Python's grammar and API. That's why I never thought I need to read a book of Python. But if Programming Python also explains OO, I would be happy to read it. In fact, I am also planning to read again Head First Object-Oriented Design and Analysis. I thought it's time for me to try again to find what is the *point* of Obejct. Anyway, this time I will be patient enough. I won't touch my code until I am sure find some way to improve it. On Apr 4, 1:14 pm, Michele Simionato michele.simion...@gmail.com wrote: On Apr 3, 7:34 pm, 一首诗 newpt...@gmail.com wrote: # # Choice 2 # class UserManager: users = [] @classmethod def delUser(cls, user): cls.users.remove(user) RoleManager.onUserDel(user) class RoleManager: roles = [] @classmethod def onUserDel(cls, user): for r in cls.roles.items(): r.users.remove(user) Choice #2 is better, but it should not be implemented this way. Using a class as a pure container of methods, a big singleton, makes little sense, since you would be better off with a module and old fashioned procedural programming. You recognize this and are worried about this. You do not need to be worried to much, since there is nothing wrong with procedural design (but you should use modules not classes). If you want to be more object oriented, the first thing is to understand is that you define objects in order to pass them to other objects. For instance, you are using a global list of users as a class attribute, but I would just pass the list in the __init__ method, and make it an instance attribute. I also would make a RoleManager instance and pass it to the UserManager, so that it can be used directly. Or perhaps I would define a single UserRoleManager doing all the job. It depends. But all the point of OOP is to pass objects to other objects. It is not bad to think of a data object as of a record on steroids. Objects which are purely data and not behavior are the simplest and the best objects, start from them. There are also objects which are mostly behavior and nearly no data (the Manager objects here, which just act over collections of other objects). Those are more difficult to write. OTOH, nobody forces you to write the managers as objects. You may find easier to write a set of manager functions. This set of functions can later become methods of a Manager object, if it seems fit, but that must be done a posteriori, not a priori. Perhaps you should read some book like Programming Python by Ludz which has many examples of how to write OO applications in Python (I mean no offense, but indeed from you examples is seems to me that you are missing the point of OOP, as you are the first to recognize). HTH, Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: A design problem I met again and again.
That's clever. I never thought of that. Not only something concrete, like people, could be class, but a procedure, like a Session, could also be a Class. Thanks for you all who replied. I learned a lot from this thread and I even made some notes of all your advices because I think I might review them many times in my future work. On Apr 4, 12:10 pm, Carl Banks pavlovevide...@gmail.com wrote: On Apr 2, 11:25 pm, 一首诗 newpt...@gmail.com wrote: Consolidate existing functions? I've thought about it. For example, I have two functions: #= def startXXX(id): pass def startYYY(id): pass #= I could turn it into one: #= def start(type, id): if(type == XXX): pass else if(type == YYY): pass #= But isn't the first style more clear for my code's user? Not necessarily, especially if the user wants to dynamically choose which start*** function to call. I have one more suggestion. Consider whether there are groups of methods that are used together but aren't used with other groups of functions. For instance, maybe there is a group of methods that can only be called after a call to startXXX. If that's the case, you might want to separate those groups into different classes. The branched-off class would then act as a sort of session handler. A piece of user code that looked like this (where sc is an instance of your enormous class): sc.startX() sc.send_data_via_X() sc.receive_data_via_X() sc.stopX() might look like this after you factor it out: session = sc.startX() # creates and returns a new XSession object session.send_data()# these are methods of the XSession session.receive_data() session.stop() Any methods that are callable any time, you can retain in the big class, or put in a base class of all the sessions. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: A design problem I met again and again.
Consolidate existing functions? I've thought about it. For example, I have two functions: #= def startXXX(id): pass def startYYY(id): pass #= I could turn it into one: #= def start(type, id): if(type == 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 pavlovevide...@gmail.com wrote: On Apr 2, 8:02 am, 一首诗 newpt...@gmail.com wrote: You get it. Sometimes I feel that my head is trained to work in a procedural way. I use a big class just as a container of functions. About the data-based approach, what if these functions all shares a little data, e.g. a socket, but nothing else? Then perhaps your problem is that you are too loose with the interface. Do you write new functions that are very similar to existing functions all the time? Perhaps you should consolidate, or think about how existing functions could do the job. Or perhaps you don't have a problem. There's nothing wrong with large classes per se, it's just a red flag. If you have all these functions that really all operate on only one piece of data, and really all do different things, then a large class is fine. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
User or UserManager ? Problems of Observer Pattern
#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 classes , User, Role, Organization, to hold these data. # #The question is : should I implement add/delete/update as methods of User, or should I add another class UserManager? # # Choice 1 # user_dict = {} role_dict = {} class User: on_del_funcs = [] roles = [] def del(self): user_dict.pop(self.name) for f in self.on_del_funcs: f(self) # Using Observer Pattern to notify this user is deleted. def addUserDelListener(self, on_del_func): on_del_funcs.append(on_del_funcs) def delUserDelListener(self, on_del_func): on_del_funcs.remove(on_del_func) class Role: users = [] def addUsser(self, user): self.users.append(user) user.roles.append(self) users.addUserDelListener(self.onUserDel) def onUserDel(self, user): self.users.remove(user) user.delUserDelListener(self.onUserDel) # # Choice 2 # class UserManager: users = [] @classmethod def delUser(cls, user): cls.users.remove(user) RoleManager.onUserDel(user) class RoleManager: roles = [] @classmethod def onUserDel(cls, user): for r in cls.roles.items(): r.users.remove(user) # These codes are not complete, but that's enough to show my question. # The first choice, which use Observer Pattern, has a very big problem. # When calling addUserDelListener, user got not only a callback function, it # also add reference count of role. So when we want to delete a role. We have # to carefully remove all *listener* hold by other objects, otherwise this role # will never be garbage collected. # Not a big problem for only 2 classes. But when there are 10 *subject* classes which # Role want to *observe*, 10 listeners has to be removed when delete a role. # And if these *subject* have 5 different types of events, then 50 listeners has # to be removed. # Actually I tried this approach once, and it is still a big headache for 10 # programmers. ( The company I worked at that time hate any change to so-called # working code ) # The second choice, which I am using right now, actually has nothing to do with # Object Oriented Designing. The manager classes are not real classes, just # container of methods. These User/Role classes are only container of data, # not behavior. # # For many times, I asked my self, Is it too hard for me to see the power of # OO, or I have just never met a problem suitable for a OO resolution? -- http://mail.python.org/mailman/listinfo/python-list
Re: A design problem I met again and again.
You get it. Sometimes I feel that my head is trained to work in a procedural way. I use a big class just as a container of functions. About the data-based approach, what if these functions all shares a little data, e.g. a socket, but nothing else? On Apr 2, 5:58 am, Carl Banks pavlovevide...@gmail.com wrote: On Apr 1, 12:44 am, 一首诗 newpt...@gmail.com 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 much logic, they do grow bigger and bigger. This seems to be a classic result of code-based organization, that is, you are organizing your code according to how your functions are used. That's appropriate sometimes. Procedural libraries are often organized by grouping functions according to use. The os module is a good example. However, it's usually much better to organize code according to what data it acts upon: data-based organization. In other words, go though your big class and figure out what data belongs together conceptually, make a class for each conceptual set of data, then assign methods to classes based on what data the methods act upon. Consider the os module again. It's a big collection of functions, but there are a group of functions is os that all act on a particular piece of data, namely a file descriptor. This suggests tha all the functions that act upon file descriptors (os.open, os.close, os.seek, etc.) could instead be methods of a single class, with the file descriptor as a class member. (Note: the os library doesn't do that because functions like os.open are supposed to represent low-level operations corresponding to the underlying system calls, but never mind that. Ordinarily a bunch of functions operating on common data should be organized as a class.) Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
A design problem I met again and again.
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 into functional pieces? I know it's important to break an application to lots of pieces to make it flexible. But it's easier said than done. I can split an application to 4 or 5 pieces based on programming functions, for example, logging, socket, string, math, ... When it comes to the business logic, I found I always provide a big class with many methods, and it grow bigger when new functions are added. Recently I use twisted to write a server. It has several protocol classes which decode and encode different kinds of network protocols , and a protocol independent service class which handle request from clients according to business logic. Protocol classes receive message from client, decode it, call method of service, encode result and send it back to client. There are also some utility packages such as logging as I mentioned before. So far so fine, every thing is clear. Until one day I find service has nearly 100 methods and 6000 lines of code. I don't need to read any programming book to know that it's too big. But I can not find an easier way to split it. Here are some solutions I found: 1. add several business classes, and move code in service into them. But this means although service will contains much less code, it still has to keep lots of methods, and the only functions of these methods is call corresponding methods in business classes. The number of methods in service will keep growing for ever. 2. completely move codes in service to business classes containing only classmethods. These protocol classes calls these classmethods directly instead of call service. But this pattern doesn't look that OO. 3. completely move codes in service to business classes. Initialize these classes and pass them to protocol classes. These protocol classes calls these instances of business classes instead of call service. These means whenever I add a new business class. I have to add a parameter to __init__ methods of every protocol class. Not very clear either. == 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 much logic, they do grow bigger and bigger. -- http://mail.python.org/mailman/listinfo/python-list
Re: A design problem I met again and again.
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 and...@acooke.org wrote: Ò»Ê×Ê« wrote: 3. completely move codes in service to business classes. Initialize these classes and pass them to protocol classes. These protocol classes calls these instances of business classes instead of call service. These means whenever I add a new business class. I have to add a parameter to __init__ methods of every protocol class. Not very clear either. i don't fully understand your problem, but i would guess (3) is the correct solution. you can probably avoid adding a new parameter by writing code in a generic way (using lists of arguments, perhaps using introspection to find method names, etc) andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: A design problem I met again and again.
On Apr 1, 4:55 pm, Lawrence D'Oliveiro l...@geek- central.gen.new_zealand 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 programming book to know that it's too big. The question is not how many lines or how many methods, but whether it makes sense to remain as one piece or not. In one previous project, I had one source file with nearly 15,000 lines in it. Did it make sense to split that up? Not really. What are the average size of source files in your project? If it's far lower than 15,000, don't feel it's a little unbalance? -- http://mail.python.org/mailman/listinfo/python-list
Is this the right way to use unicode in a user defined Exception?
# 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. I have to pass it to third party libraries. As many libraries simply use str(e) to log, if I don't encode it in __str___, they will fail. But I am not quite certain if it's the right thing to do. Shouldn't every library expect to use unicode everywhere? Shouldn't they use something like : log(unicode(e)) -- http://mail.python.org/mailman/listinfo/python-list
Is there something easier than ORM?
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, and change rows of data to list of named tuple, then I could send these data to my client application. I don't think I want these subtle behavior such as lazy load, auto update, ect. in ORM. So is there some libraries like that? Or is there some tools that could generate code from database scheme as I want? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there something easier than ORM?
Thanks for your reply. With sqlalchemy, an mapped must living in a session, you have no way to disconnect it with its session. For example : #- user = session.query(User).first() session.expunge(user) print user.name #Error here #- I just want to get an read-only copy of user disconnected with session to avoid unexpected database operation. But after expunge, properties of user is not accessible anymore. BTW : why you choose elixir instead of sqlalchemy's own schema definition style? Doesn't including another library means more chances of bugs? On Feb 17, 9:24 pm, Diez B. Roggisch de...@nospam.web.de wrote: 一首诗 schrieb: 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, and change rows of data to list of named tuple, then I could send these data to my client application. I don't think I want these subtle behavior such as lazy load, auto update, ect. in ORM. So is there some libraries like that? Or is there some tools that could generate code from database scheme as I want? Sqlalchemy. You don't need to use the ORM-layer, and you can use reflection to create schema-objects like tables. Then you can use that to create SQL-queries simple powerful, whilst being DB-agnostic and having a road to start using the ORM if you discover it is useful for you. To be honest: if you can control the schema, I'd still go for an orm. I for example use elixir. It makes the easy things *really* easy, and the complicated ones ar still possible. Diez -- http://mail.python.org/mailman/listinfo/python-list
A little comments of ctypes and construct.
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 structures. But 1. It's not that good for pack. 2. From the documents and example, can not find out how to describe nested struct array. for example: typedef struct _Point { int x; int y; } Point; typedef struct _Shape { int z; Point ap[2]; }Shape; Can not find out how to describe this.. Then I tried ctypes. 1. It works fine for pack BUT: 1. I can not figure out how to unpack. The examples I googled doesn't work on my computer. http://markmail.org/message/44tu6rm4nejxgbdd 2. BigEndianStructure can not be nested. So. If you need bid endian, you got bad luck. So, both of them are not ideal solution to pack and unpack sophisticated C style data structures. BTW: Some one suggested that I should use struct.Struct and namedtuple. I skimmed the document, but can't find a clear way to handle nested structures. -- http://mail.python.org/mailman/listinfo/python-list
Re: A little comments of ctypes and construct.
I didn't try your code. That might be working since it a completely different method. What mean is pack works: = class POINT(Structure): _fields_ = [('x', c_int), ('y', c_int)] p = POINT(1,2) p.x, p.y (1, 2) str(buffer(p)) s = str(buffer(p)) = unpack doesn't = p2 = POINT() ctypes.memmove(p2, s, ctypes.sizeof(POINT)) 14688904 p2.x, p2.y = I am not trying to parse data generated by a dll, but data received from network. That's also why I need Big Endian. 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 structures. snip typedef struct _Point { int x; int y; } Point; typedef struct _Shape { int z; Point ap[2]; }Shape; snip 2. BigEndianStructure can not be nested. So. If you need bid endian, you got bad luck. A bug is filed about this. I have this code working: import ctypes as c class Point( c.LittleEndianStructure ): _fields_= [ ( 'x', c.c_int ), ( 'y', c.c_int ) ] class Shape( c.LittleEndianStructure ): _fields_= [ ( 'z', c.c_int ), ( 'ap', Point* 2 ) ] lib= c.WinDLL( 'ng36ext.pyd' ) lib.make.argtypes= [ ] lib.make.restype= Shape shape= lib.make( ) print shape.z, shape.ap[0].x, shape.ap[0].y, shape.ap[1].x, shape.ap [1].y /Output: 10 20 30 40 50 20 10 20 30 40 50 /Definition for 'make': Shape make( void ) { Shape shape; shape.z= 10; shape.ap[ 0 ].x= 20; shape.ap[ 0 ].y= 30; shape.ap[ 1 ].x= 40; shape.ap[ 1 ].y= 50; printf( %i %i %i %i %i\n, shape.z, shape.ap[0].x, shape.ap[0].y, shape.ap[1].x, shape.ap[1].y ); printf( %i\n, sizeof( shape ) ); return shape; } What is your next step? -- http://mail.python.org/mailman/listinfo/python-list
Re: A little comments of ctypes and construct.
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 platform specific, so your int may be different) ... SNInt32(y), ... ) shape = Struct(shape, ... SNInt32(z), ... Rename(ap, # without the Rename field, the name would be point (Arrays inherit their name from their element) ... Array(2, point) ... ), ... ) c = shape.parse() print c Container: z = 2054847098 ap = [ Container: x = 2021161080 y = 2038004089 Container: x = 1482184792 y = 1499027801 ] -- http://mail.python.org/mailman/listinfo/python-list
Have you ever used pydiction?
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 part of a word for python, so commands like w/ e doesn't behave the same as before... If you have met the same problem, what's your solution? Do not use auto completion at all and check python manual from time to time? Choosing another IDE ? -- http://mail.python.org/mailman/listinfo/python-list
Re: pysqlite install error on hp ux (ld: Can't find library for -lpython2.5)
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. and python2.5 is installed. ld command also avaliable. please help for me~ Hi, as far as I know. 1. you can use module sqlite3 instead. 2. you can use these commands on ubuntu: sudo apt-get install libsqlite3-dev sudo easy_install -Z pysqlite -- http://mail.python.org/mailman/listinfo/python-list
Re: parsing non-ascii characters
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 when I run this it give me an error: SyntaxError: Non-ASCII character '\xc5' in file vortaro.py on line 33, but no encoding declared; is there a way to parse Non-ASCII characters in python? Thanks in advance, Ronn http://www.python.org/dev/peps/pep-0263/ -- http://mail.python.org/mailman/listinfo/python-list
I need a simple windows form handle.
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 problem: What is the simplest way to get a windows form which has a handle? I tried to use win32py but it seems to be to complicate for my purpose. And the form would block the main thread even if I call its DoModal method on another thread. = PS: Finally I decided I can not finish it today so I write a WinForm App in C# in 5 minutes and send video from my python app to it by UDP. That works. -- http://mail.python.org/mailman/listinfo/python-list
Re: I need a simple windows form handle.
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 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 problem: What is the simplest way to get a windows form which has a handle? I tried to use win32py but it seems to be to complicate for my purpose. And the form would block the main thread even if I call its DoModal method on another thread. = PS: Finally I decided I can not finish it today so I write a WinForm App in C# in 5 minutes and send video from my python app to it by UDP. That works. Why don't you write the GUI in Python? Check out 'wxPython' and others. 'wx' programs can get pretty short, something like: app= wx.PySimpleApp() frame= wx.Frame( app ) canvas= wx.Canvas( frame ) canvas.Render( my_picture ) app.MainLoop() Hi, that's because I guess wxpython does not use native windows forms and could not provide a handle property. I will make more study. -- http://mail.python.org/mailman/listinfo/python-list
Re: convert to XMLRPC
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 way, but i use a customized GatewayHandler that give me the posibility to serialize my objects and send them to my clients but my real need is to convert this object to XML -or something like it- to send it in a way i can use them in every presentation a suggest like GUI, WEB or anything i like. There's any thing i can do to convert them. Don't worry about the way i handle the result i only need to convert them to XML or else. -- Michel Perez )\._.,--,'``. Ulrico Software Group /, _.. \ _\ ;`._ ,. Nihil est tam arduo et difficile human `._.-(,_..'--(,_..'`-.;.' mens vincat. Séneca. = --- Red Telematica de Salud - Cuba CNICM - Infomed You really should have a look at one of: * Google protocol buffer * Facebook Thrift * ICE -- http://mail.python.org/mailman/listinfo/python-list
Re: Can read() be non-blocking?
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 indefinite, keeping me from killing it. The folloing sample code illustrates the problem: proc = subprocess.Popen(['/usr/bin/foo', '/path/to/some/file'], stdout=subprocess.PIPE) output = StringIO.StringIO() while True: r = select.select([proc.stdout.fileno()], [], [], 5)[0] if r: # NOTE: This will block since it reads until EOF data = proc.stdout.read() if not data: break # EOF from process has been reached else: output.write(data) else: os.kill(proc.pid, signal.SIGKILL) proc.wait() Process the output... As the NOTE: comment above suggests the call to read() will block here. I see two solutions: 1. Read one byte at a time, meaning call read(1). 2. Read non-blocking. I think reading one byte at a time is a waste of CPU, but I cannot find a way to read non-blocking. Is there a way to read non-blocking? Or maybe event a better way in generel to handle this situation? Thanks Thomas As far as I know, you can use '''fctnl''' to make a file handle non- blocking. But : 1. I don't know if it works on standard io 2. If it works in python -- http://mail.python.org/mailman/listinfo/python-list
What's your choice when handle complicated C structures.
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 handling binary structures? -- http://mail.python.org/mailman/listinfo/python-list
Re: Efficient way to remove objects from a list
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: Build a new list as you go, then overwrite the old list with it. unfinished = [] for m in self.messages: if not m.finished: unfinished.append(m) continue #process the message Remove the following code fini = [m for m in self.messages if m.finished] for m in fini: self.messages.remove(m) self.messages[:] = unfinished Just self.messages = unfinished if also OK unless you have multiple references to the self.messages list. This way you aren't calling .remove() multiple times and only iterate through the list once. -- http://mail.python.org/mailman/listinfo/python-list
Efficient way to remove objects from a list
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 want to find these finished messages in self.messages, process them, and then remove them from the list. Because a list can not be modified while iterating it, I have to use a list fini to accomplish the target. I found a smell of bad performance here. Is there any faster ways? -- http://mail.python.org/mailman/listinfo/python-list
What's your first choice if you have to write a C module for python?
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.
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 of the system shall be written in C. 4. Could easily integrated with twisted. Unfortunately, there seems no such resolution existed. So maybe I have to give up some requirements. --- It would be wonderful if ICE could integrate with twisted! -- http://mail.python.org/mailman/listinfo/python-list
How to make python run faster
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: 4 3 2 1 But I did noticed that 2 is a least 3 times slower than 1, not as fast as the article stated. That's quite weird and I thought maybe it's because I am using Windows. I did the same test on Linux and I found 2 only uses 1.5 times of time of 1. But, it is still not as fast as 1. -- http://mail.python.org/mailman/listinfo/python-list
I am taking a programming performance match!
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 trying twited. Is it suitable for this kind of job? -- http://mail.python.org/mailman/listinfo/python-list
wxPython and activex problem.
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(sys.argv) File genaxmodule.py, line 32, in main axw = wx.activex.ActiveXWindow(f, clsid) File C:\Python23\Lib\site-packages\wx-2.6-msw-ansi\wx\activex.py, line 268, in __init__ newobj = _activex.new_ActiveXWindow(*args, **kwargs) wx._core.PyAssertionError: C++ assertion wxAssertFailure failed in contrib\activex\wxie/wxactivex.cpp(322): m_ActiveX.CreateInstance failed -- For some job, I do need to use activex and I have to choose languages other than python if genaxmodule doesn't work. It's really annoying. -- http://mail.python.org/mailman/listinfo/python-list
How to convert nbsp; in a string to blank space?
Is there any simple way to solve this problem? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to convert nbsp; in a string to blank space?
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 nbsp; to blank space and convert br to \r\n Gary Herron wrote: 一首诗 wrote: Is there any simple way to solve this problem? Yes, strings have a replace method: s = abcnbsp;def s.replace('nbsp;',' ') 'abc def' Also various modules that are meant to deal with web and xml and such have functions to do such operations. Gary Herron -- http://mail.python.org/mailman/listinfo/python-list
My python can not get addr info
D:\python24\Lib\idlelibpyshell.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_shell if not self.pyshell.begin(): File D:\python24\Lib\idlelib\PyShell.py, line 962, in begin client = self.interp.start_subprocess() File D:\python24\Lib\idlelib\PyShell.py, line 389, in start_subprocess self.rpcclt.accept() File D:\python24\lib\idlelib\rpc.py, line 524, in accept working_sock, address = self.listening_sock.accept() File D:\python24\lib\socket.py, line 169, in accept sock, addr = self._sock.accept() socket.gaierror: (10104, 'getaddrinfo failed') D:\python24\Lib\idlelib -- http://mail.python.org/mailman/listinfo/python-list