Partial classes
Hi All, Not being able to figure out how are partial classes coded in Python. Example: Suppose I have a code generator which generates part of a business class, where as the custome part is to be written by me. In ruby (or C#), I divide the code into two source files. Like this: GeneratedPerson.rb Class Person . . . End Class HandcraftedPerson.rb Class Person . . . End Class The intrepretor adds the code in both to compose the class Person. What is the equivalent in Python? Inheriting is a way, but is not working in all scenerios. Thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Joachim Durchholz wrote: Marshall schrieb: Chris Smith wrote: Joachim Durchholz [EMAIL PROTECTED] wrote: I *think* I understand Marshall here. When you are saying assignment, you mean assignment to values of attributes within tuples of the cell. When Marshall is saying assignment, he seems to mean assigning a completely new *table* value to a relation; i.e., wiping out the entire contents of the relation and replacing it with a whole new set of tuples. Your assignment is indeed less powerful than DML, whereas Marshall's assignment is more powerful than DML. Exactly. Ah well. I never meant that kind of assignment. Sorry for the confusion. Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: Dispatch with multiple inheritance
Michael J. Fromberger wrote: Is there a better (i.e., more elegant) way to handle the case marked (**) above? You have to call super in each method __init__, if you don't, the call chain break before the end: class A (object): def __init__(self): super(A, self).__init__() print cons A class B (object): def __init__(self): super(B, self).__init__() print cons B class C (A): def __init__(self): super(C, self).__init__() print cons C class D (B): def __init__(self): super(D, self).__init__() print cons D class E (C, D): def __init__(self): super(E, self).__init__() # calls C constructor print cons E -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Sanjay wrote: Not being able to figure out how are partial classes coded in Python. Hi Sanjay, To the best of my knowledge, Python currently has no support for partial classes. However, BOO (http://boo.codehaus.org/) - which is a Python-like language for the .NET CLI)- _does_ support partial classes (http://jira.codehaus.org/browse/BOO-224). While it _isn't_ Python, there could be enough similarities to make this worthwhile for you if you absolutely have to have partial classes. (Disclaimer: I've never used BOO) Hope this helps. -alex23 -- http://mail.python.org/mailman/listinfo/python-list
Re: Python : Event-Driven Paradigm
Were you looking for more specific features? Parallel Processing. Grant, It looks like I have a lot more studying to do, all of the information that I have seems to be screwed up. I will look at event loops in Python to see if that answers my question. I was just looking at the event-driven programming page on wikipedia and it mentioned that TCL had event driven programming built in, go figure and it did not mention python at all. I have made a lot of assumptions, and you know the old saying that assumptions are the mother of all fu**ups. Well I am going to get back to it, interest thing just occurred though. I have a program that actually runs faster with the more user-definedfunctions called than with less, I am trying to track down the reason why. I am ecstatic! I am getting into parallel processing because of a graphics project that I am researching and I have to stay with Python, because I don't want to spend a year recoding what others have already completed and tweaked to max efficiency. What a vicious circle I am caught up in. As always thanks for the response E-mail. I have not even checked out the Google groups yet, but I will very soon. - Steven. - Original Message - From: Grant Olson To: 'Kusanagi' Sent: Tuesday, July 18, 2006 4:34 PM Subject: RE: Python : Event-Driven Paradigm This is weird, but your post didnt show up on Google Groups; looks like it did on python list. I was going to let you know that you can just post to python list, and if I have anything worthwhile to say Ill put it up there, but I always check through google groups. Anyway, I dont really have much worthwhile to say on this question, but I think the general response on python-list would be that it isnt too hard to write a basic event loop with stock python; were you looking for more specific features? -Grant From: Kusanagi [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 18, 2006 5:03 AMTo: Python Mailing List; Grant Olson; Bob IppolitoSubject: Python : Event-Driven Paradigm Hi All, I have been looking through wikipedia at the Event-Driven Page http://en.wikipedia.org/wiki/Event-driven_programming and I noticed that it mentions that TCL has event driven programming built in. I also looked over the Python 3000 proposals and I did not notice any mention of future versions of python that are going to be changed to include this awesome feature. I currently use the Twisted framework in various ways and I was just curious to know if the event-driven paradigm is going to be implemented without the use of 3rd party frameworks. i.e. Twisted. in the future. If this question has already been asked and answered then please accept my apology. - Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Sanjay wrote: Hi All, Not being able to figure out how are partial classes coded in Python. Example: Suppose I have a code generator which generates part of a business class, where as the custome part is to be written by me. In ruby (or C#), I divide the code into two source files. Like this: GeneratedPerson.rb Class Person . . . End Class HandcraftedPerson.rb Class Person . . . End Class The intrepretor adds the code in both to compose the class Person. What is the equivalent in Python? Inheriting is a way, but is not working in all scenerios. Thanks Sanjay Python has no notion of a partial class because it is a pure compile time construct. You might merge different class definitions by means of a meta class that puts everything together but whether or not certain methods in the merged class are available depends on which modules are imported. This might give rise to a virtual or runtime module. It is not a module that refers to a physical file on the disc but is a pure runtime construct. When creating this module all physical modules that define class fragments might be put together by means of the metaclass mechanism. I indeed used this construction to unify different access points before I reimplemented it using partial classes in C# which are very fine IMO. -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto Determine mimetype without the file name extension?
Try this: http://www.demonseed.net/~jp/code/magic.py -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Hi Alex, Thanks for the input. Being new to Python, and after having selected Python in comparison to ruby (Turbogears vs Rails) , is jerks me a bit. In my openion it should be an obvious and easy to implement feature and must be, if not already have been, planned in future releases of Python. Would love to listen to others. Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive function returning a list
Bruno Desthuilliers wrote: Boris Borcic a écrit : Hello Bruno, Bruno Desthuilliers wrote: [...] Or how to *not* address the real problem... Boris, using a generator may be a pretty good idea, but *not* as a way to solve a problem that happens to be a FAQ !-) Sorry, but I don't understand your reasoning. It's quite simple. The OP's problem is well-known (it's a FAQ), and easy to solve. The righ answer to it is obviously to give a link to the FAQ So, why didn't you? (or take time to re-explain it for the zillionth time), not to propose a workaround. Or did I miss something? regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterator protocol changes, was: Coding style
Terry Reedy wrote: Guido has so far vetoed adding .__len__() to the iterator protocol because a) it is not always possible and Be warned that this is a veto after the fact: # (only) python 2.4 len(iter(range(42))) 42 # python 2.5 len(iter(range(42))) Traceback (most recent call last): File stdin, line 1, in module TypeError: len() of unsized object b) he want to keep the protocol as simple as it is. You will be able to write considerably more complex generators in 2.5: http://docs.python.org/dev/whatsnew/pep-342.html Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: question about what lamda does
tac-tics wrote: [EMAIL PROTECTED] wrote: Hey there, i have been learning python for the past few months, but i can seem to get what exactly a lamda is for. What would i use a lamda for that i could not or would not use a def for ? Is there a notable difference ? I only ask because i see it in code samples on the internet and in books. Lambda is just as powerful as a function, but totally useless =-P Lambda used to be handy before the introduction of list comprehensions. Now, though, there primary use is obfuscating your code. I do wish you could hold yourself back and stop muddying the waters. Lambdas and list comprehensions have little or nothing to do with each other. Unless you know something I don't ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
In [EMAIL PROTECTED], Sanjay wrote: Being new to Python, and after having selected Python in comparison to ruby (Turbogears vs Rails) , is jerks me a bit. In my openion it should be an obvious and easy to implement feature and must be, if not already have been, planned in future releases of Python. Can you flesh out your use case a little bit and tell why you can't solve the problem with inheritance or a meta class? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
On Wed, 18 Jul 2006, Sanjay wrote: What is the equivalent in Python? Inheriting is a way, but is not working in all scenerios. Have you tried multiple inheritance? For example: from GeneratedPerson import GeneratedPerson from HandcraftedPerson import HandcraftedPerson class Person(GeneratedPerson, HandcraftedPerson): pass If this doesn't work for you, can you explain why? Dave -- http://mail.python.org/mailman/listinfo/python-list
Text Summarization
Is there a Python library that would allow me to take a paragraph of text, and generate a one or two sentence summary of that paragraph? -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessors in Python (getters and setters)
mystilleef wrote, making me somewhat tired of his/her repeated inability to get what's being said [sigh]: Bruno Desthuilliers wrote: mystilleef wrote: Bruno Desthuilliers wrote: mystilleef wrote: Gerhard Fiedler wrote: On 2006-07-15 06:55:14, mystilleef wrote: In very well designed systems, the state of an object should only be changed by the object. IMO that's not quite true. Ultimately, the state always gets changed by something else (user interaction, physical events); very few objects are completely self-contained in their behavior. Then in those cases the system becomes a victim of high coupling. This makes it somewhat obvious that you don't appear to fully understand the concept of coupling as applied to software systems. Time to burn your book and face reality. ObjA sends message Msg1 to ObjB. Part of the associated behaviour is that in responce to Msg1, objB changes it's own state. Practical result : ObjB's state has been changed by ObjA. Practical question : how do you hope to avoid this hi coupling (lol), apart from making all your objects totally autistic ? Are you serious? Deadly serious. But I'm afraid you're still missing the point. Well, you design an object that serves as a mediator. All objects can then only interact with themselves and the mediator only. Via signals, objects learn to automatically adjust their states and respond to events. signal - message - method call - change state. Spell it how you like, add as many indirection levels you want, it still boils down to the fact that *something* triggers the state change. Right! If you implement an accessor to change a class's instances' states, surely something has to call that accessor. You seem to be implying that such calls can only be made from within other methods of the same object, which (if true, which it isn't) would tend to leave each class in a vacuum where nothing else can affect its instances. Of *course* objects are subject to external influences: since you like the concept of coupling, how else could different components be coupled at all? This is just one of several methods you can dramatically reduce coupling. It's just one of several methods that dramatically increases complexity, without changing anything to the fact that in the end, *practically*, some object ObjA changes its state as a response to a message sent by ObjB. Say that to game/simulation developers. This is a complete non-sequitur as you don't say why game developers specifically benefit from the reduced coupling that you allege the provision of accessor methods introduces. Tight coupling would be (for example) where you provided the argument to a method by storing it in a global variable rather than passing it as an argument. From a coupling point of view it makes no difference whether you call an accessor method or (in Python) read or write a referenced object's attributes directly. You still have to know the required API: whether you call a method (in which case you have to know its name) or read/write an attribute (in which case you have to know its name ...) makes no essential difference. It appears you have seen the term content coupling as defined, for example, in http://en.wikipedia.org/wiki/Coupling_%28computer_science%29 and taken that to mean that any knowledge at all of another object's internals will lead to over-tight coupling and hence low cohesion. The Python point of view is somewhat different, and says that since both methods and data items are attributes of instances there is little difference (except in efficiency) between accessing data via a method (inefficient) and accessing data directly through the attribute containing that data (efficient). It has already been pointed out to you several times that once you have written your code to access attributes you can introduce properties without changing the client (accessing) code should further isolation or additional computation be required. I'm sure glad I didn't burn my book. No comment. In most systems (and you possibly have written some of them) are objects whose state gets changed by other objects -- possibly through the intermediation of setter methods that do nothing else but set the state. There's no conceptual difference between directly setting the state or calling a setter function that does nothing else but directly setting the state -- except for one unnecessary level of indirection in the latter. It depends. If certain conditions need to be met before changing the state of an object, then arbitrarily changing it can be dangerous. Does this imply a 'method call' *syntax* ? That's language dependent. Given the existence of computed attributes (ie: support for 'attribute access' *syntax* with hidden accessors) and the possibility to redefine implementation (from default attribute r/w access to computed/controlled) without touching the interface, why advocate the *systematic* use of computed attributes when
Retrieve ext. variables in python program
Trying to convert TCL code to python. Have a property file from where I read some VAR's. Looks like this: EARPROJECT = sgs-procDist APPNAME = SGSProcedure In my TCL code I confirm the existence of the VAR = f.ex EARPROJECT by using code: if { ([info exists APPNAME] [info exists STAGEDIR] [info exists EARPROJECT] [info exists EARDESTINATION]) } { Does anyone know and equalent way to confirm a Variable from the same property file using PYTHON code ??? -- http://mail.python.org/mailman/listinfo/python-list
Re: No need to close file?
[EMAIL PROTECTED] wrote: T Do I need to close the file in this case? Why or why not? T for line in file('foo', 'r'): T print line No. The magic of reference counting. Though of course we have to remember that not all Python implementations *use* reference counting. It's certainly true, though, that most Python programmers are happy to rely on whatever garbage collector *is* implemented to detect the absence of references to the file and close it automatically. Or have the operating system do so if the interpreter somehow terminates without closing the file. I suspect the real answer is it isn't strictly necessary in modern environments, but it can never hurt. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Fall Python training seminar in Colorado
Mark Lutz's Python Training Services is pleased to announce that our Fall 2006 public Colorado seminar is now open. This 5-day Python training event will be held November 6 through November 10. This year, our Fall seminar will be held at Historic Crag's Lodge, a resort in Estes Park, Colorado. Estes Park is a mountain town 80 miles from Denver's airport, and gateway to Rocky Mountain National Park. This in an all-inclusive event. Come spend 5 days mastering Python in the beautiful Colorado Rockies, and let us handle the details of your visit. We will be providing students with rooms at the resort, three full meals per day, a guided sightseeing tour, shuttle service to and from the Denver airport, and our new Snake Charmers T-shirt. Besides the included amenities, the extended format of this session will allow for in-depth coverage of class topics. Like all our public classes, this seminar will be taught by best-selling Python author and trainer Mark Lutz, and is open to individual enrollments. For more details, please see our web page: http://home.earthlink.net/~python-training/public.html Python Training Services -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Sanjay wrote: Hi All, Not being able to figure out how are partial classes coded in Python. Example: Suppose I have a code generator which generates part of a business class, where as the custome part is to be written by me. In ruby (or C#), I divide the code into two source files. Like this: GeneratedPerson.rb Class Person . . . End Class HandcraftedPerson.rb Class Person . . . End Class The intrepretor adds the code in both to compose the class Person. What is the equivalent in Python? Inheriting is a way, but is not working in all scenerios. # HandcraftedPerson.py import GeneratedPerson class Person: def somemethod (self): pass GeneratedPerson.Person.somemethod = Person.somemethod Using reflection to merge all methods of HandcraftedPerson.Person into GeneratedPerson.Person is left as an exercise. Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Sanjay wrote: Hi All, Not being able to figure out how are partial classes coded in Python. Example: Suppose I have a code generator which generates part of a business class, where as the custome part is to be written by me. In ruby (or C#), I divide the code into two source files. Like this: GeneratedPerson.rb Class Person . . . End Class HandcraftedPerson.rb Class Person . . . End Class The intrepretor adds the code in both to compose the class Person. What is the equivalent in Python? Inheriting is a way, but is not working in all scenerios. I, like everybody else it seems, am interested to know why/when (multiple) inheritance doesn't work. Meanwhile # this is a hack import inspect import textwrap class Generated: def generated(self): print generated def class_body(Class): return textwrap.dedent(inspect.getsource(Class).split(\n, 1)[1]) class Handmade: exec class_body(Generated) def handmade(self): print handmade if __name__ == __main__: print dir(Handmade) Handmade().generated() Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Can you flesh out your use case a little bit and tell why you can't solve the problem with inheritance or a meta class? I have to study about metaclass and see whether this can be handled. It seemed inheritence is not working. PROBLEM: Separating plumbing code and business logic while using SQLAlchemy ORM. Database script: CREATE TABLE person ( id SERIAL, passport VARCHAR(50) NOT NULL, blocked BOOLEAN NOT NULL DEFAULT FALSE, first_name VARCHAR(30) NOT NULL, middle_name VARCHAR(30) NULL, last_name VARCHAR(30) NOT NULL, email VARCHAR(100) NOT NULL, used_bytes INTEGER NOT NULL DEFAULT 0, PRIMARY KEY(id) ); CREATE TABLE contact ( person_id INTEGER NOT NULL REFERENCES person, contact_id INTEGER NOT NULL REFERENCES person, favorite BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY(person_id, contact_id) ); DB definitions and plumbing code goes into one module, say db.py: import sqlalchemy.mods.threadlocal from sqlalchemy import * global_connect('postgres://userid:[EMAIL PROTECTED]:5432/tm') person_tbl = Table('person', default_metadata, autoload = True) class Person(object): pass contact_tbl = Table('contact', default_metadata, autoload = True) class Contact(object): pass assign_mapper(Person, person_tbl, properties = { 'contacts' : relation(Contact, primaryjoin=person_tbl.c.id==contact_tbl.c.person_id, association=Person) }) assign_mapper(Contact, contact_tbl, properties = { 'person' : relation(Person, primaryjoin=person_tbl.c.id==contact_tbl.c.contact_id) }) Business logic in another module, say bo.py Class PersonBO(Person): def Block(): blocked = True While using PersonBO in another module, like this: p1 = PersonBO(passport = [EMAIL PROTECTED], first_name='john', last_name='smith', email = [EMAIL PROTECTED]) p2 = PersonBO(passport = [EMAIL PROTECTED], first_name='ed', last_name='helms', email = [EMAIL PROTECTED]) p3 = PersonBO(passport = [EMAIL PROTECTED], first_name='jonathan', last_name='lacour', email = [EMAIL PROTECTED]) # add a contact p1.contacts.append(Contact(person=p2)) the following error message occurs: AttributeError: 'PersonBO' object has no attribute 'contacts' What I guess, from my limited knowledge of the technologies involved, is that assign_mapper does some magic only on Person class, and things work. But after inheritence, it is not working. The point in general, to my knowledge, about inheritance is that it can't be a substitute for all the usages of partical classes. Metaclass is a new concept for me, which I have to study. As far as my project is concerned, I have found out some other way of doing the things, and it is no more an issue. Thanks a lot, Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: No need to close file?
[EMAIL PROTECTED] wrote: T wrote: Do I need to close the file in this case? Why or why not? for line in file('foo', 'r'): print line I was running a program in IDLE that opened a file for reading and forgot to add the close. The program ran and terminated normally. But when I tried to open it from Windows Explorer, I got the message that it was still in use. Had to close IDLE to release it. That wouldn't have happened if I had closed it from within the program. yes, this invariably happens me (with PythonWin) if I try to get away without a 'finally' Gerard -- http://mail.python.org/mailman/listinfo/python-list
Re: Text Summarization
Jim Jones wrote: Is there a Python library that would allow me to take a paragraph of text, and generate a one or two sentence summary of that paragraph? There is a OTS wrapper. -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
In message [EMAIL PROTECTED], Bruno Desthuilliers wrote: Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Bob Greschke wrote: I'd go even one step further. Turn it into English (or your favorite non-computer language): 1. While list, pop. 2. While the length of the list is greater than 0, pop. Which one makes more sense? Guess which one I like. CPU cycles be damned. :) One of my rules is, always program like the language actually has a Boolean type, even if it doesn't. Python has a boolean type. A _proper_ boolean type would _have_ to be used in conditionals. That means, never assume that arbitrary values can be interpreted as true or false, There's nothing to assume, and nothing arbitrary in it. It's all clearly defined in whole letters in the language references. Not simply enough. always put in an explicit comparison if necessary so it's obvious the expression is a Boolean. The fact that the expression is used in the context of a if statement is clearly enough to denote a boolean expression. Which is an inconsistent use of the term boolean compared to your statement above that Python has a boolean type, is it not? Explicitly testing against a boolean is uselessly redundant... Not sure this has anything with what I was saying. -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Sanjay wrote: Hi Alex, Thanks for the input. Being new to Python, and after having selected Python in comparison to ruby (Turbogears vs Rails) , is jerks me a bit. In my openion it should be an obvious and easy to implement feature and must be, if not already have been, planned in future releases of Python. Would love to listen to others. I've never had a use case for this kind of feature in the past seven years. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Bob Greschke wrote: I'd go even one step further. Turn it into English (or your favorite non-computer language): 1. While list, pop. 2. While the length of the list is greater than 0, pop. Which one makes more sense? Guess which one I like. CPU cycles be damned. :) One of my rules is, always program like the language actually has a Boolean type, even if it doesn't. That means, never assume that arbitrary values can be interpreted as true or false, always put in an explicit comparison if necessary so it's obvious the expression is a Boolean. You can do that, but it's not considered Pythonic. And it might be ineffective. Other than in PHP, Python has clear rules when an object of a builtin type is considered false (i.e. when it's empty). So why not take advantage of this? Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: Text Summarization
Jim Jones wrote: Is there a Python library that would allow me to take a paragraph of text, and generate a one or two sentence summary of that paragraph? If you are on Windows you could use COM to stuff the text into a Word document and then use Word's autosummarize feature to generate the summary. However, even Microsoft admit that Its unlikely that Word will create the exact summary that you need. You will need to do some editing of the summary. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting and Setting Cookies
John J. Lee wrote: Vlad Dogaru [EMAIL PROTECTED] writes: I am trying to use cookies and Python to create a simple login example. But I am very disoriented at the existence of two cookie libraries, namely Cookie and cookielib. I have seen examples of setting cookies [...] From the cookielib docs: http://docs.python.org/lib/module-cookielib.html | The cookielib module defines classes for automatic handling of HTTP | cookies. It is useful for accessing web sites that require small | pieces of data - cookies - to be set on the client machine by an HTTP | response from a web server, and then returned to the server in later | HTTP requests. (note the *accessing* there) [...] | Module Cookie: HTTP cookie classes, principally useful for server-side | code. The cookielib and Cookie modules do not depend on each | other. Module cookielib is for web client code (writing code that works like a browser). Module Cookie is for server-side code (writing code to make a web site work). You don't make it entirely clear which you're doing, but it sounds like the latter. I am trying to write a simple login script. I understand (or rather I think I understand) how to set a cookie with the Cookie module. My problem is getting the cookies that are currently set. How can I do that? -- http://mail.python.org/mailman/listinfo/python-list
Re: New SourceForge project: Diet Python!!!
I was reading an article about the One Laptop Per Child initiative the other day, and being a Python fan I wondered if there are any plans to put Python on it, or at least make it available. A cut-down version of python, preferably with bindings to the Sugar GUI framework they are developing, would be a Very Good Thing. They're planning on manufacturing 100 million of these things! Simon Hibbs -- http://mail.python.org/mailman/listinfo/python-list
TextCtrl focus events in wxWidgets
I have a simple form with some input values and some calculated values in TextCtrl widgets. What I would like to do is have the display update automaticaly when the user changes one of the input fields, without having to click on a 'Calculate' button. I was thinking of having an update triggered when one of the text Controlls loses focus, indicating that the user has finished changing it's value. I don't want to do an update on every character entry, as this would create a lot of bogus/meaningless updates. There doesn't seem to be such an event. Any ideas how I could implement this, or a similarly user friendly behaviour? Best regards, Simon Hibbs -- http://mail.python.org/mailman/listinfo/python-list
Re: Python linker
Simon Brunning wrote: So, they'll download and install the .NET framework at 23 MB, but they won't download and install Python at 9 and half? I think the .NET framework gets thrown down via Windows Update - or at least it did for me - so that doesn't count as a 'separate download' for many purposes. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: New SourceForge project: Diet Python!!!
On 19 Jul 2006 02:34:09 -0700, Simon Hibbs [EMAIL PROTECTED] wrote: I was reading an article about the One Laptop Per Child initiative the other day, and being a Python fan I wondered if there are any plans to put Python on it, or at least make it available. A cut-down version of python, preferably with bindings to the Sugar GUI framework they are developing, would be a Very Good Thing. Sounds like Sugar is built (partially) with Python. http://arstechnica.com/news.ars/post/20060524-6903.html -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: question about what lamda does
Steve Holden wrote: tac-tics wrote: [EMAIL PROTECTED] wrote: Hey there, i have been learning python for the past few months, but i can seem to get what exactly a lamda is for. What would i use a lamda for that i could not or would not use a def for ? Is there a notable difference ? I only ask because i see it in code samples on the internet and in books. Lambda is just as powerful as a function, but totally useless =-P Lambda used to be handy before the introduction of list comprehensions. Now, though, there primary use is obfuscating your code. I do wish you could hold yourself back and stop muddying the waters. Lambdas and list comprehensions have little or nothing to do with each other. Unless you know something I don't ... I think he meant that lambda's main use before was inside map and filter; as stated earlier in the thread, lambda's main use was for passing simple functions as arguments, and of these map and filter must have made up a majority (and then I'd guess TKinter would be next). List comprehensions replace map and filter, so... I wouldn't put it as explosively as he has, but I find a lambda less clear than a def too. Iain regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Simon Hibbs wrote: I have a simple form with some input values and some calculated values in TextCtrl widgets. What I would like to do is have the display update automaticaly when the user changes one of the input fields, without having to click on a 'Calculate' button. I was thinking of having an update triggered when one of the text Controlls loses focus, indicating that the user has finished changing it's value. I don't want to do an update on every character entry, as this would create a lot of bogus/meaningless updates. There doesn't seem to be such an event. Any ideas how I could implement this, or a similarly user friendly behaviour? It should be quite simple: you need to handle EVT_SET_FOCUS and/or EVT_KILL_FOCUS events (documented in the wxPython docs) to know when to recaclulate the values. Sounds like that should be enough of a hint to you. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Python linker
Sion Arrowsmith wrote: Er, what? How are you generating your standalone executables? What size is acceptable? python24.dll is only 1.8M -- surely on any non-embedded platform these days 1.8M isn't worth bothering about. And since you mention wx (all of another 4.8M) I'd guess we're talking about desktop applications. Who's going to notice if your executable is a couple of M slimmer? I've considered making a few lightweight GUI apps in the past but you just can't do it with wxPython. When you have similar products done in Visual C++ weighing in at kilobytes rather than megabytes, it's hard to convince people that it's worth downloading your product. Say I wanted to develop a simple Notepad clone with 1 or 2 extra features: the MS executable is 68Kb, yet to simulate it in wxPython would be over 5MB; nobody would want it. I suppose you can use the msvcrt library directly and cut out wx from the dependencies, but sadly the Python overhead is still a slight deterrent. Not that I see an easy solution to this, of course. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
PTY wrote: Which is better? lst = [1,2,3,4,5] while lst: lst.pop() OR while len(lst) 0: lst.pop() allways that either-or stuff ! And why did you not consider while len(lst) : list.pop() a neat middle ground, wouldn't you say ? Cheers, BB -- 666 ?? - 666 ~ .666 ~ 2/3 ~ 1-1/3 ~ tertium non datur ~ the excluded middle ~ either with us, or against us !! -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Bruno Desthuilliers wrote: Sanjay wrote: Hi Alex, Thanks for the input. Being new to Python, and after having selected Python in comparison to ruby (Turbogears vs Rails) , is jerks me a bit. In my openion it should be an obvious and easy to implement feature and must be, if not already have been, planned in future releases of Python. Would love to listen to others. I've never had a use case for this kind of feature in the past seven years. Interesting. Are there other use cases you did not have too? -- http://mail.python.org/mailman/listinfo/python-list
Re: New SourceForge project: Diet Python!!!
Simon Brunning wrote: On 19 Jul 2006 02:34:09 -0700, Simon Hibbs [EMAIL PROTECTED] wrote: I was reading an article about the One Laptop Per Child initiative the other day, and being a Python fan I wondered if there are any plans to put Python on it, or at least make it available. A cut-down version of python, preferably with bindings to the Sugar GUI framework they are developing, would be a Very Good Thing. Sounds like Sugar is built (partially) with Python. http://arstechnica.com/news.ars/post/20060524-6903.html Great Scott! I don't think this newsgroup can handle another 100 million newbies! Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
Bruno Desthuilliers wrote: empty_list = [] bool(empty_list) is False = True it's just a pity that the symmetric expression list(False) is [] doesn't hold. I guess the problem is that if list(False) was thus defined, it would be difficult not to define list(True). And then the zen of Python clashes In the presence of ambiguity, refuse the temptation to guess. OTOH, my favorite there would be list(True) is [None] together with list(n) == n*[None] for all positive integers n Cheers, BB -- 666 ?? - 666 ~ .666 ~ 2/3 ~ 1-1/3 ~ tertium non datur ~ the excluded middle ~ either with us, or against us !! -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling Python using the Portland Group compiler
On Jul 12, 2006, at 15:57, Konrad Hinsen wrote: I am trying to install Python 2.4.3 on an AMD Opteron system using the Portland Group's compiler (pgcc). Using CC=pgcc -DNCURSES_ENABLE_STDBOOL_H=0 OPT=-O0 LINKFORSHARED=-Wl,- export-dynamic ./configure --without-cxx I finally managed to obtain an executable that would start and work, but it fails a couple of test cases: ... I ended up debugging the first case of failure, and diagnosed faulty code generation. I sent a bug report to Portland Group, who promised to look at it. Konrad. -- - Konrad Hinsen Centre de Biophysique Moléculaire, CNRS Orléans Synchrotron Soleil - Division Expériences Saint Aubin - BP 48 91192 Gif sur Yvette Cedex, France Tel. +33-1 69 35 97 15 E-Mail: [EMAIL PROTECTED] - -- http://mail.python.org/mailman/listinfo/python-list
text representation of HTML
Hi, I am looking for a library that will give me very simple text representation of HTML. For example divh1Title/h1pThis is a br /test/p/div will be transformed to: Title This is a test i want to send plain text alternative of html email, and would prefer to do it automatically from HTML source. Any hints? Thanks! Ksenia. -- http://mail.python.org/mailman/listinfo/python-list
Re: need help getting xml feed from a url
Shan wrote: If i have a list of urls how can I extract or pull their respective xml feeds? from lxml import etree feeds = [] for url in my_url_list: feeds.append( etree.parse(url) ) For the rest, find out about the ElementTree API. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Steve Holden wrote: It should be quite simple: you need to handle EVT_SET_FOCUS and/or EVT_KILL_FOCUS events (documented in the wxPython docs) to know when to recaclulate the values. Sounds like that should be enough of a hint to you. I've tried that, but it doesn't work. Here is the test code: self.PlantCtrl = wx.TextCtrl(self, -1, ) self.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl, self.PlantCtrl) def OnUpdatePlantCtrl(self, event): print set Plant When the control loses focus, I don't get the message in the console. I'm trapping other events successfuly elsewhere using similar code. Simon Hibbs . -- http://mail.python.org/mailman/listinfo/python-list
Re: text representation of HTML
Ksenia Marasanova wrote: Hi, I am looking for a library that will give me very simple text representation of HTML. For example divh1Title/h1pThis is a br /test/p/div will be transformed to: Title This is a test i want to send plain text alternative of html email, and would prefer to do it automatically from HTML source. Any hints? html2text is a commandline tool. You can invoke it from python using subprocess. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Dispatch with multiple inheritance
looping wrote: Michael J. Fromberger wrote: Is there a better (i.e., more elegant) way to handle the case marked (**) above? You have to call super in each method __init__, if you don't, the call chain break before the end: class A (object): def __init__(self): super(A, self).__init__() print cons A class B (object): def __init__(self): super(B, self).__init__() print cons B class C (A): def __init__(self): super(C, self).__init__() print cons C class D (B): def __init__(self): super(D, self).__init__() print cons D class E (C, D): def __init__(self): super(E, self).__init__() # calls C constructor print cons E After a second tought, it's probably better to call __init__ method explicitly in class E: class A (object): def __init__(self): print cons A class B (object): def __init__(self): print cons B class C (A): def __init__(self): super(C, self).__init__() print cons C class D (B): def __init__(self): super(D, self).__init__() print cons D class E (C, D): def __init__(self): D.__init__(self) C.__init__(self) print cons E this way you have to choose which __init__ from class D or class C is calling, and which is calling first. Any Python Guru to give is opinion ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
Patrick Maupin a écrit : The perverse wish, expressed in the specific example, that SOME piece of code SOMEWHERE should PLEASE throw an exception because some idiot passed a generator expression rather than a list into a function, is not apt to be well received by an audience which strives for generality when it makes sense Well then, you haven't beed using enouth generator expressions or else, that kind of mistake would have bitten you badly by now and you would agree with that remark ! confronted with the wished-for exception, would fix the function so that it quite happily accepted generator expressions, rather than changing a conditional to use len() just so that an equivalent exception could happen a bit earlier. Thanks but NO. If that function needs to iterate twice on the expression, then it needs to iterate twice and passing it a generator will only cause strange bugs. -- http://mail.python.org/mailman/listinfo/python-list
Regular expression issue
I'm trying to parse a line of html as follows: td style=width:20% align=left101.120:( KPA (-)/td td style=width:35% align=leftSnow on Ground)0 /td however, sometimes it looks like this: td style=width:20% align=leftN/A/td td style=width:35% align=leftSnow on Ground)0 /td I want to get either the numerical value 101.120 (which could be a different number depending on the data that's been fed into the page, or in terms of the second option, 'N/A'. The regexp I'm using is: .*?Pressure.*?left(?Pbaro\d+?|N/A)/td|\sKPA.*?Snow\son\sGround Can someone help me debug this. It's not picking up the number, and I'm not sure I've got the syntax for '|' right, but can't find a detailed tutorial on how to use |. Any help would be appreciated. Thanks Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieve ext. variables in python program
alfa1234: Does anyone know and equalent way to confirm a Variable from the same property file using PYTHON code ??? Using globals(), locals(), and dir() you can find if your name exists already. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Augument assignment versus regular assignment
On 2006-07-18, Terry Reedy [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 2006-07-17, Terry Reedy [EMAIL PROTECTED] wrote: Or, whether docs (and reasonable interpretation thereof) and implementation match, which I claim they do it this case. The claim, in reference to the CPython implementation, that you refer to below. Well this dispute seems to boil down what is and what is not involved in evaluating a target, Yes, and that is interpreter/implementation dependent. Well I can agree that some things are implemantation dependent. But shouldn't a language reference describe behaviour in terms or implementation independent things? and I have come to doubt that target evaluation is even a meaningfull concept in python, Abstractly, it is whatever the interpreter does before it actually attaches an object to the name or slot. Again, the details are interpreter dependent. Well I can sort of agree with this. IMO there are two possible views here, (not necessarily mutual exclusive) But if you agree with the first IMO the language reference shouldn't make use of the concept to describe behaviour. 1) target evaluation is not a pythonic concept. 2) It is whatever the interpreter does before it actually attaches an object, to a name/slot/... (in a primary). so maybe in order that I can understand how you come to that claim, I looked at the CPython bytecode and saw that for augmented assigment, it saved on the stack the internal information it needed for get and set instead of recalculating it after the operation. This is what I expected and what I think the docs imply. can you explain what a target evaluates to? The internal information the interpreter needs to do the assignment (binding). Yes but that seems to be an entirly internal interpreter affair. If you stay at the level of the byte code, you will not find any opcode that will result in or manipulate a target evaluation. If you look at the language reference for the assignment, you will not find the notion of a target evaluation mentioned there either. That is because as far as I can see, an assignment is essentially a ternary operation in python. An assignment needs a (name)space/scope, an index/key/name and an object and those three are combined into an assignment. Sometimes it looks like only two elements are given, but that is because the space is implicit in cases of a rebinding, (the STORE_GLOBAL and STORE_FAST opcode). Talking about a target evaluation IMO only makes sense if you view an assigment as a binary operation. So in a statement like col['t'] = exp What is the evaluation of col['t']? Try some personal introspection. When you act as a Python interpreter, what do you do? I do the evaluation of the target in the __setitem__ method (or the STORE_SUBSCR opcode). Let as look what the compilor makes of it: [blank lines added for clarity] dis(compile(col['t'] = exp, '', 'single')) 1 0 LOAD_NAME0 (exp) 3 LOAD_NAME1 (col) 6 LOAD_CONST 0 ('t') 9 STORE_SUBSCR The bytecodes at 0, 3 and 6 don't do any evaluation, they just put things on the stack. So what does the STORE_SUBSCR at location 9 do (or __setitem__)? Well it will first do a number of preparations, like searching for a bucket in a dictionary or a node in a tree or list, may be even create one if a suitable wasn't available. And after that is done, the object will be somehow attached. So IMV those preparation before the attachment, belong to whatever the interpreter does before it actually attaches an object to a name/slot. So the evaluation of the target is part of what is done by STORE_SUBSCR or __setitem__. Now you can object to the fact that I have divided the work within an opcode. But if you do that, there seems to be no place left to talk about a target evaluation in this example. So as a conclusion I would say one has two options: 1) View target evaluations as not a pythonic concept 2) Accept that target evaluation is done by STORE_SUBSCR/__setitem__ -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Since the event handler of a textctrl inherits from wxCommandEvent, I would guess that the binding should be to EVT_COMMAND_KILL_FOCUS Not tested... Rony Le Wed, 19 Jul 2006 03:15:36 -0700, Simon Hibbs a écrit : Steve Holden wrote: It should be quite simple: you need to handle EVT_SET_FOCUS and/or EVT_KILL_FOCUS events (documented in the wxPython docs) to know when to recaclulate the values. Sounds like that should be enough of a hint to you. I've tried that, but it doesn't work. Here is the test code: self.PlantCtrl = wx.TextCtrl(self, -1, ) self.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl, self.PlantCtrl) def OnUpdatePlantCtrl(self, event): print set Plant When the control loses focus, I don't get the message in the console. I'm trapping other events successfuly elsewhere using similar code. Simon Hibbs . -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
rony steelandt wrote: Since the event handler of a textctrl inherits from wxCommandEvent, I would guess that the binding should be to EVT_COMMAND_KILL_FOCUS Still not working :( Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Sanjay wrote: Hi All, Not being able to figure out how are partial classes coded in Python. Example: Suppose I have a code generator which generates part of a business class, where as the custome part is to be written by me. In ruby (or C#), I divide the code into two source files. Like this: I would do this by inheritance if really needed - what isn't working? That said, you can get this behaviour fairly easy with a metaclass: class PartialMeta(type): registry = {} def __new__(cls,name,bases,dct): if name in PartialMeta.registry: cls2=PartialMeta.registry[name] for k,v in dct.items(): setattr(cls2, k, v) else: cls2 = type.__new__(cls,name,bases,dct) PartialMeta.registry[name] = cls2 return cls2 class PartialClass(object): __metaclass__=PartialMeta use: #generatedperson.py class Person(PartialClass): def foo(self): print foo #gandcraftedperson.py import generatedperson class Person(PartialClass): def bar(self): print bar and you should get similar behaviour. Caveats: I've used just the name to determine the class involved to be the same as your Ruby example. However, this means that any class in any namespace with the name Person and inheriting from PartialClass will be interpreted as the same - this might not be desirable if some other library code has a different Person object doing the same thing. Its easy to change to checking for some property instead - eg. have your handcrafted class have the line __extends__=generatedperson.Person , and check for it in the metaclass instead of looking in a name registry. Also, if two or more classes define the same name, the last one evaluated will overwrite the previous one. -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
In [EMAIL PROTECTED], Boris Borcic wrote: Bruno Desthuilliers wrote: empty_list = [] bool(empty_list) is False = True it's just a pity that the symmetric expression list(False) is [] doesn't hold. You want the empty list to be a singleton!? And I don't find `list(False)` to return an empty list be very obvious. I guess the problem is that if list(False) was thus defined, it would be difficult not to define list(True). And then the zen of Python clashes In the presence of ambiguity, refuse the temptation to guess. OTOH, my favorite there would be list(True) is [None] Wow it even gets better, the list containing one `None` object should be a singleton too. Argh. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Simon Hibbs wrote: rony steelandt wrote: Since the event handler of a textctrl inherits from wxCommandEvent, I would guess that the binding should be to EVT_COMMAND_KILL_FOCUS Still not working :( I can trap EVT_TEXT_ENTER events successfuly, without using EVT_COMMAND_ENTER. This almost gets me where I want to be. The user must press 'enter' after modifying each value though. If they forget the UI isn't updated, so I'd need some way of visualy distinguishing between modified values that have been ENTER'd and those that haven't which is a pain, and not very user friendly at all. There must be some way of doing this, but blowed if I can figure it out. Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular expression issue
In [EMAIL PROTECTED], dmbkiwi wrote: I'm trying to parse a line of html as follows: td style=width:20% align=left101.120:( KPA (-)/td td style=width:35% align=leftSnow on Ground)0 /td however, sometimes it looks like this: td style=width:20% align=leftN/A/td td style=width:35% align=leftSnow on Ground)0 /td I want to get either the numerical value 101.120 (which could be a different number depending on the data that's been fed into the page, or in terms of the second option, 'N/A'. The regexp I'm using is: .*?Pressure.*?left(?Pbaro\d+?|N/A)/td|\sKPA.*?Snow\son\sGround Can someone help me debug this. It's not picking up the number, and I'm not sure I've got the syntax for '|' right, but can't find a detailed tutorial on how to use |. What about something like align=left((?Pbaro[\d.]+):\(\sKPA)|(?PnaN/A).*Ground\) You need the flags re.MULTILINE and re.DOTALL when compiling the regular expression. You'll have to check the 'baro' and 'na' groups to decide if it matched a numerical value or 'N/A'. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
Christophe wrote: ... you haven't beed using enouth generator expressions ... You should get yourself to the doctors about that cold dude. :-) -- http://mail.python.org/mailman/listinfo/python-list
Simple file writing techiques ...
Hello, I've often found that I am writing little scripts at the interpretor to read a text file, perform some conversion, and then write the converted data back out to a file. I normally accomplish the above task by reading the lines of the entire file into a list, preforming some function to that list and then writing the list back out. I want to write a generic function/module that will free me from repeatedly typing the same thing, perhaps convertFile(filename, covertFunc) and I was wondering what would be a more optimal solution for writing the data, fout = open('somefile','w') for line in convertedData: fout.write(%s\n % line) fout.close() -- or -- fout = open('somefile','w') fout.write(%s % '\n'.join(convertedData)) fout.close() ... or maybe some hybrid of the two which writes chunks of the convertedData list out in one shot ... An issue that I'm probably most concerned with is scalabitiy, what if the file was huge, like some sort of log file. As well, I know from 'import this' that there should only be one obvious way to do something ... however to me it's not so obvious :( Any suggestions, Colin -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Simon Hibbs wrote: Steve Holden wrote: It should be quite simple: you need to handle EVT_SET_FOCUS and/or EVT_KILL_FOCUS events (documented in the wxPython docs) to know when to recaclulate the values. Sounds like that should be enough of a hint to you. I've tried that, but it doesn't work. Here is the test code: self.PlantCtrl = wx.TextCtrl(self, -1, ) self.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl, self.PlantCtrl) def OnUpdatePlantCtrl(self, event): print set Plant When the control loses focus, I don't get the message in the console. I'm trapping other events successfuly elsewhere using similar code. Simon Hibbs Try self.PlantCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl) Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
Marc 'BlackJack' Rintsch wrote: In [EMAIL PROTECTED], Boris Borcic wrote: Bruno Desthuilliers wrote: empty_list = [] bool(empty_list) is False = True it's just a pity that the symmetric expression list(False) is [] doesn't hold. You want the empty list to be a singleton!? Oops, list(False) == [], then. BTW, be careful with 'singleton' when applying to aggregates - it took me a while to figure out you did not mean an obj X s.t. len(X)==1. And I don't find `list(False)` to return an empty list be very obvious. What would be your choice ? -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Simon Hibbs wrote: Steve Holden wrote: It should be quite simple: you need to handle EVT_SET_FOCUS and/or EVT_KILL_FOCUS events (documented in the wxPython docs) to know when to recaclulate the values. Sounds like that should be enough of a hint to you. I've tried that, but it doesn't work. Here is the test code: self.PlantCtrl = wx.TextCtrl(self, -1, ) self.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl, self.PlantCtrl) def OnUpdatePlantCtrl(self, event): print set Plant When the control loses focus, I don't get the message in the console. I'm trapping other events successfuly elsewhere using similar code. This would probably be a good question for the wxPython list then - you are clearly in some little-known area of swamp ;-) regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Kay Schluehr wrote: Bruno Desthuilliers wrote: Sanjay wrote: Hi Alex, Thanks for the input. Being new to Python, and after having selected Python in comparison to ruby (Turbogears vs Rails) , is jerks me a bit. In my openion it should be an obvious and easy to implement feature and must be, if not already have been, planned in future releases of Python. Would love to listen to others. I've never had a use case for this kind of feature in the past seven years. Interesting. Are there other use cases you did not have too? Probably quite a lot, why ?-) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Thanks for the code showing how to implement partial classes. Infact, I was searching for this code pattern. I will have a study on metaclass and then try it. Thanks Sanjay -- http://mail.python.org/mailman/listinfo/python-list
Re: Capturing instant messages
On Jul 18, 2006, at 3:17 PM, Yu-Xi Lim wrote: This is going to be quite off-topic. But helpful nonetheless. I'm not entirely familiar with SOX regulations. Is it necessary to capture it at the gateway? I'm no lawyer either, so I probably know as much about this as you do. It was the client who proposed this type of solution; I'm in the process of figuring out if it's at all possible. The best solution would be to provide logging at the individual chat clients. Piecing together conversation threads from individual packets while filtering out other non-chat junk can be extremely tedious. I got the impression that they want to capture the IM traffic and record it somewhere JIC they are ever audited or subpoenaed, but that most of it would never get looked at again. I understand the standard AIM client doesn't provide logging. Probably won't any time soon, since it wasn't made for enterprise. There are enterprise gateways for AIM, but I'm not sure of the cost or other deployment issues. (Try looking at Jabber) You should consider those. Or a switch to a more enterprise-friendly protocol if that's possible. Other alternatives would be to use a better client. Multi-protocol clients like GAIM, Trillian, Miranda, and Adium X generally provide logging. Most provide the ability to toggle logging for specific sessions, thus reducing privacy issues. Thanks for the suggestions; I'll run them by the client. They don't want to do it at the individual desktop level; they want a central location to ensure that someone doesn't have the capability to disable the logging, so perhaps an enterprise gateway might be a better solution. -- Ed Leafe -- http://leafe.com -- http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
[EMAIL PROTECTED] wrote: Sanjay wrote: Hi All, Not being able to figure out how are partial classes coded in Python. Example: Suppose I have a code generator which generates part of a business class, where as the custome part is to be written by me. In ruby (or C#), I divide the code into two source files. Like this: I would do this by inheritance if really needed - what isn't working? That said, you can get this behaviour fairly easy with a metaclass: class PartialMeta(type): registry = {} def __new__(cls,name,bases,dct): if name in PartialMeta.registry: cls2=PartialMeta.registry[name] for k,v in dct.items(): setattr(cls2, k, v) else: cls2 = type.__new__(cls,name,bases,dct) PartialMeta.registry[name] = cls2 return cls2 class PartialClass(object): __metaclass__=PartialMeta This definition lacks a check for disjointness of the parts. No two partial classes shall contain a method with the same name. -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Frank Millman wrote: Try self.PlantCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl) And Voila! It works. Many, many thanks. Any idea what is going on? Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple file writing techiques ...
cdecarlo wrote: fout = open('somefile','w') for line in convertedData: fout.write(%s\n % line) fout.close() -- or -- fout = open('somefile','w') fout.write(%s % '\n'.join(convertedData)) fout.close() I'd go for something like... fout = open('somefile','w') fout.writelines( line+\n for line in convertedData ) fout.close() Although your first solution should perform about the same. If you have 2.5, you may prefer this... with open('somefile','w') as fout: fout.writelines( line+\n for line in convertedData ) ... or maybe some hybrid of the two which writes chunks of the convertedData list out in one shot ... The OS should buffer it for you. Will McGugan -- http://mail.python.org/mailman/listinfo/python-list
Project organisation
Imagine I have x projects and they all use util.py What would be the best way to organise this 1. c --\project1\*.py | |-\project2\*.py | --\globals\util.py This organisation has the problem that if I have to modify something to util.py that I need in project2, I'll have to retest project1 to make sure it still works (that could be project 1..n). 2. A copy of util.py in each project directory ? The advantage is that I can modify each util.py in function of the need of the project but it looks clutered, having n versions of util.py. What is the best solution ? or is there another even better solution ? Rony -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Simon Hibbs wrote: Frank Millman wrote: Try self.PlantCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl) And Voila! It works. Many, many thanks. Any idea what is going on? AIUI, wx.EVT_KILL_FOCUS is not a Command Event i.e. it doesn't propagate up the hierarchy of widgets until it gets handled, so it has to be bound explicitly to the control itself, as above. Originally you used: self.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl, self.PlantCtrl) which binds the event to self (presumably the containing frame or panel) and adds the condition that it must come from self.PlantCtrl - which never happens. -- Regards David Hughes -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organisation
rony steelandt wrote: Imagine I have x projects and they all use util.py What would be the best way to organise this 1. c --\project1\*.py | |-\project2\*.py | --\globals\util.py This organisation has the problem that if I have to modify something to util.py that I need in project2, I'll have to retest project1 to make sure it still works (that could be project 1..n). Of course it does. And if you genuinely want to share components between projects, how else could you verify that utility changes for one project hadn't broken the other? 2. A copy of util.py in each project directory ? The advantage is that I can modify each util.py in function of the need of the project but it looks clutered, having n versions of util.py. It will aslso give you probems if they get out of step, or if you want to make parallel changes in them all. I certainly wouldn't recommend this. What is the best solution ? or is there another even better solution ? Seems to me that the best solution of all would be to have independent tests for the functionality defined in utils.py, and to run those tests after each change no matter for which project. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
On 19 Jul 2006 04:55:24 -0700, Simon Hibbs [EMAIL PROTECTED] wrote: Frank Millman wrote: Try self.PlantCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl) And Voila! It works. Many, many thanks. Any idea what is going on? Your first attempt used self.Bind, which binds the kill focus event of self to the method. This version binds the kill focus event of the *text control* to the method, which is what you want. I used to get bitten by this a lot, but now I've switched to using the dabo.ui module of Dabo to do my GUI stuff. It has the concept of binding changes in controls to update events, which was needed for database-type apps, but you can bind a control to any property of any object. You should really check it out if you need this sort of interactive updating in your app. http://dabodev.com. -- # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple file writing techiques ...
fout = open('somefile','w') for line in convertedData: fout.write(%s\n % line) fout.close() -- or -- fout = open('somefile','w') fout.write(%s % '\n'.join(convertedData)) fout.close() I shouldn't think it matters too much which of these you use - time them and see what happens. An issue that I'm probably most concerned with is scalabitiy, what if the file was huge, like some sort of log file. Sucking in the entire file into a list won't scale well, as a huge log file could quickly eat all of your available memory. You'd be better off processing each line as you go, and writing it to a temp file, renaming the temp file once you have finished. Something like: in_f = access.log out_f = access.log.tmp infile = open(in_f) outfile = open(out_f) for line in infile: outfile.write(process(line)) infile.close() outfile.close() os.remove(in_f) os.rename(out_f, in_f) (Not tested, but you get the idea...) -- http://mail.python.org/mailman/listinfo/python-list
Using super()
Hello, I have a class called MyConfig, it is based on Python's ConfigParser.ConfigParser. It implements add_section(self, section), which is also implemented on ConfigParser.ConfigParser, which I want to call. So, reducing the problem to the bare minimum, the class (with a useless add_section that shows the problem): class MyConfig(ConfigParser): ... def add_section(self, section): ... super(MyConfig, self).add_section(section) ... Create an object m = MyConfig() and call the problematic method: m.add_section(blah) Traceback (most recent call last): File stdin, line 1, in ? File stdin, line 3, in add_section TypeError: super() argument 1 must be type, not classobj Why is super() requiring a type ? doesn't it work with classes ? Is there a way to achieve what I am trying to do (other than calling the specific class that happens to be the parent today) ? Thanks. -- Pupeno [EMAIL PROTECTED] (http://pupeno.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: text representation of HTML
Hi, I guess stripogram would be more pythonic : http://sourceforge.net/project/showfiles.php?group_id=1083 Regards, Laurent Diez B. Roggisch wrote: Ksenia Marasanova wrote: Hi, I am looking for a library that will give me very simple text representation of HTML. For example divh1Title/h1pThis is a br /test/p/div will be transformed to: Title This is a test i want to send plain text alternative of html email, and would prefer to do it automatically from HTML source. Any hints? html2text is a commandline tool. You can invoke it from python using subprocess. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple file writing techiques ...
cdecarlo [EMAIL PROTECTED] writes: fout = open('somefile','w') for line in convertedData: fout.write(%s\n % line) fout.close() -- or -- fout = open('somefile','w') fout.write(%s % '\n'.join(convertedData)) fout.close() ... or maybe some hybrid of the two which writes chunks of the convertedData list out in one shot ... The second option would be definitely faster. An issue that I'm probably most concerned with is scalabitiy, what if the file was huge, like some sort of log file. Considering that you've already read in the whole file into a list, it's too late to worry about scalability when writing out :-). Have you considered the fileinput module? Ganesan -- Ganesan Rajagopal -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple file writing techiques ...
Whoops: outfile = open(out_f) outfile = open(out_f, 'w') may be better ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Partial classes
Kay Schluehr wrote: This definition lacks a check for disjointness of the parts. No two partial classes shall contain a method with the same name. Yes - I mentioned at the bottom that the last one evaluated will overwrite any existing one. You're right that its probably a better idea to check for it and throw an exception. -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
On 2006-07-19, Georg Brandl [EMAIL PROTECTED] wrote: Lawrence D'Oliveiro wrote: In message [EMAIL PROTECTED], Bob Greschke wrote: I'd go even one step further. Turn it into English (or your favorite non-computer language): 1. While list, pop. 2. While the length of the list is greater than 0, pop. Which one makes more sense? Guess which one I like. CPU cycles be damned. :) One of my rules is, always program like the language actually has a Boolean type, even if it doesn't. That means, never assume that arbitrary values can be interpreted as true or false, always put in an explicit comparison if necessary so it's obvious the expression is a Boolean. You can do that, but it's not considered Pythonic. And it might be ineffective. Other than in PHP, Python has clear rules when an object of a builtin type is considered false (i.e. when it's empty). So why not take advantage of this? Because it doesn't always do what I want. I once had a producer consumer code. When the client asked whether new items were available the function could return three different values 1) a list with items, to be consumed 2) an empty list (meaning there were no items available for the moment but there could be in the future 3) None (meaning the producer was done) Just testing for the truth value of the returned result in order to see whether the client should continue or not would often have made the client exit prematurely. IME such cases where testing for the truth value of an object don't give the expected result, happen often enough to make me carefully think about what I want to test for and then explicitly do so. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Recursive function returning a list
Bruno Desthuilliers wrote: Boris Borcic a écrit : Hello Bruno, Bruno Desthuilliers wrote: Boris Borcic wrote: Do you have any ideas? you could use a recursive generator, like def genAllChildren(self) : for child in self.children : yield child for childchild in child.genAllChildren() : yield childchild Or how to *not* address the real problem... Boris, using a generator may be a pretty good idea, but *not* as a way to solve a problem that happens to be a FAQ !-) Sorry, but I don't understand your reasoning. It's quite simple. The OP's problem is well-known (it's a FAQ), This is really an oversimplification. What's the case is that his showstopper was covered by the FAQ list. The OP's problem is actually a stack of problems/subproblems and was presented as such. and easy to solve. I did consider a couple distinct ways to solve it while passing lists around - did you notice that the OP's code made no clear choice as to whether it wanted to pass them by reference or as return values ? That's how a generator struck me as most pythonic if you want (In the face of ambiguity, refuse the temptation to guess). The righ answer to it is obviously to give a link to the FAQ (or take time to re-explain it for the zillionth time), not to propose a workaround. Given your usage of code simplicity in another thread as (roughly) a measure of pythonic virtue, I feel it warranted to ask why should one recognize simpler code as the workaround (assuming it fits the bill) ? Because it doesn't cross the FAQ, seems to be your answer... How can you exclude that the OP /may/ find that a generator neatly solves his problem ? I don't exclude it, and explicitly mentioned in whole letters that, I quote, it may be a pretty good idea. And actually, the OP's problem is really with default values evaluation scheme - something that every Python programmer should know, because there are cases where you cannot solve it with a generator-based solution !-) ... - and the quirks of default values being FAQ stuff don't change that. Sure if nobody had covered that aspect, but a couple other posters did... Yes, but you forgot to mention that - and I would not have post any comment on your solution if you had explicitly mentioned the FAQ or these other answers. At this point I recognize that our difference may very well have deep roots relating to cognitive style, educational policy, etc. Generally speaking I welcome debate on such premisses as an occasion to learn more (not so much from my contradictor than from the debate itself), but a precondition is that the partner/contradictor understands my motive (what I can't count on since the idea of learning from the debate itself is pretty typical such cognitive style divides). Besides, I don't quite have the time right now. The short form is : I strongly disagree with you. Best, BB -- On naît tous les mètres du même monde -- http://mail.python.org/mailman/listinfo/python-list
Re: Using super()
Pupeno írta: Hello, I have a class called MyConfig, it is based on Python's ConfigParser.ConfigParser. It implements add_section(self, section), which is also implemented on ConfigParser.ConfigParser, which I want to call. So, reducing the problem to the bare minimum, the class (with a useless add_section that shows the problem): The problem is that ConfigParser.ConfigParser is an old style class. It is in the standard library, so I have no clue why. For old style classes, you should directly call the ancestor class method. For new style classes it works just fine: class ConfigParser(object): def add_section(self, section): print section, in ,self.__class__.__name__ class MyConfig(ConfigParser): def add_section(self, section): super(MyConfig, self).add_section(section) m = MyConfig() m.add_section(blah) The output: blah in MyConfig -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
Simon Hibbs wrote: Frank Millman wrote: Try self.PlantCtrl.Bind(wx.EVT_KILL_FOCUS, self.OnUpdatePlantCtrl) And Voila! It works. Many, many thanks. My pleasure Any idea what is going on? I only understand it in simple terms, though it can get complex. Here is my simple explanation. Events are received by objects. There are default event handlers that are called to deal with the events. If you want your own event handler to be called, you use Bind(), which brings together three elements - the window receiving the event (in wxPython, all objects derive from wx.Window), the event itself, and the event handler to be called. In pseudo code, you call Bind() like this - w = the window receiving the event e = the event h = the handler to be called w.Bind(e,h) You bound EVT_KILL_FOCUS to self, which I assume in your case is a panel, but the panel does not receive the KILL_FOCUS event, the text control does. For more information, type help(wx.Window.Bind) at the interpreter prompt. If you want an authoritative answer, post a question to the wxPython mailing list. Robin Dunn, the creator of wxPython and the resident guru, is always happy to explain in detail exactly what is going on. You can also get Robin's book, wxPython In Action. Frank -- http://mail.python.org/mailman/listinfo/python-list
problem in Trying to include new address family in socketmodule.c
i am trying to include a new Address family (PF_CAN) in the extension module of socket - socketmodule.c... At first i am just trying to create a socket. When I use s=socket.socket(socket.AF_INET, socket.SOCK_STREAM), a socket is created at a address but s=socket.socket(socket.PF_CAN, socket.SOCK_RAW), it gives an errror ( 97: Address family not supported) The PF_CAN is a family from the CAN family and the test cases made in C language are currently working fine. like the statement works absolutely fine -- s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) But I would like to design test cases with Python. What are the changes required to add this address family also in the socket extension module ?? Regards Vikas -- http://mail.python.org/mailman/listinfo/python-list
Converting a web to pdf or ..
Hi , I have a web site and i want to write a perogram with python that my users can convert custom web page of site to pdf (or other type :jpeg, doc,odt,or...) and download it . i dont want only convert text . it is be very good to i can don it for both text and images ... similar to web page ... can i do it with ReportLab ?? --- Iranian Python Community -- www.python.ir -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessors in Python (getters and setters)
Then why do you advise (making) all attributes of a class private/protected and systematically using properties ? Because you don't want third parties illegimately tampering with an object's internal data and thus crashing your system? Ah, you mean like in JAVA where the compiler prevents you from accessing private variables, but the runtime allows access to these very variables via reflection? Or in C++, where the malevolent programmer just removes the private declarations in his compile run, and accesses the private data from your object as if it was never declared that way? You better forget thinking about these hilarious mechanisms of access control as something that enforces security, and start thinking about them as a convention that states I told you not to tamper with this, you've been warned - which is done in python using a leading underscore. Or two. Unless setting or getting a property implies code being run beside the actual state change, there is absolutely no reason to use accessors. But I fear this horse has been beaten to death in front of you so many times, yet still you refuse to see it that way - so, go and use accessors if you like. Nobody cares Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessors in Python (getters and setters)
What I'm saying here is that it's totally useless to duplicate default behaviour. And who's doing that? Somebody who uses setters that only set a property? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organisation
rony steelandt wrote: Imagine I have x projects and they all use util.py What would be the best way to organise this 1. c --\project1\*.py | |-\project2\*.py | --\globals\util.py This organisation has the problem that if I have to modify something to util.py that I need in project2, I'll have to retest project1 to make sure it still works (that could be project 1..n). 2. A copy of util.py in each project directory ? The advantage is that I can modify each util.py in function of the need of the project but it looks clutered, having n versions of util.py. What is the best solution ? or is there another even better solution ? Extensive automated regression tests certainly helps! Take a look at e.g. http://www.texttest.org/ This is really not a Python issue at all, it would be the same thing with a util.dll written in C++... -- http://mail.python.org/mailman/listinfo/python-list
Re: Track keyboard and mouse usage
Lars wrote: Diez B. Roggisch wrote: will make the devices world readable. While I haven't thought about any security implications that might have (and am not especially knowledgeable in such things to be honest), I'm convinced it is way less likely to introduce any exploitable holes than suid root would. Depending on what kind of info these devices produce, couldn't they be used to spy on someone typing in a password? (I can't check, I'm on FreeBSD.) I guess so. Good point. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Using super()
Laszlo Nagy wrote: Pupeno írta: Hello, I have a class called MyConfig, it is based on Python's ConfigParser.ConfigParser. It implements add_section(self, section), which is also implemented on ConfigParser.ConfigParser, which I want to call. So, reducing the problem to the bare minimum, the class (with a useless add_section that shows the problem): The problem is that ConfigParser.ConfigParser is an old style class. It is in the standard library, so I have no clue why. For old style classes, you should directly call the ancestor class method. For new style classes it works just fine: class ConfigParser(object): def add_section(self, section): print section, in ,self.__class__.__name__ class MyConfig(ConfigParser): def add_section(self, section): super(MyConfig, self).add_section(section) m = MyConfig() m.add_section(blah) I see, thank you. class MyConfig(ConfigParser, object): def add_section(self, section) super(MyConfig, self).add_section(section) seems to work and as expected. Is there anything wrong with it ? -- Pupeno [EMAIL PROTECTED] (http://pupeno.com) -- http://mail.python.org/mailman/listinfo/python-list
Re: Using super()
I see, thank you. class MyConfig(ConfigParser, object): def add_section(self, section) super(MyConfig, self).add_section(section) seems to work and as expected. Is there anything wrong with it ? I have never seen this before. :) I don't know the answer, but I'm interested too. Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: Augument assignment versus regular assignment
Antoon Pardon wrote: The language reference doesn't talk about objects. And IMO you should be carefull if you want to use the word object here. In the line: foo += 1, you can't talk about the object foo, since foo will possibly be bound to a different object after the assignment than it was bound to before. witness class Foo(list) : def __iadd__(self,other) : self.append(other) return self bar = foo = Foo() foo += 1 foo is bar True foo [1] while of course bar = foo = 0 foo += 1 foo is bar False Best, BB -- On naît tous les mètres du même monde -- http://mail.python.org/mailman/listinfo/python-list
Re: TextCtrl focus events in wxWidgets
David Hughes wrote: AIUI, wx.EVT_KILL_FOCUS is not a Command Event i.e. it doesn't propagate up the hierarchy of widgets until it gets handled, so it has to be bound explicitly to the control itself, as above. Right. This is one of the sources of confusion with events - which ones 'propagate up the hierarchy' and which ones do not. This is a quote from the wxWidgets documentation - Typically events that deal with a window as a window (size, motion, paint, mouse, keyboard, etc.) are sent only to the window. Events that have a higher level of meaning and/or are generated by the window itself, (button click, menu select, tree expand, etc.) are command events and are sent up to the parent to see if it is interested in the event. Simon's first attempt would have been correct if EVT_KILL_FOCUS was treated as a Command Event. Unfortunately, it is not, and therefore it was not passed up to 'self' for handling. Frank -- http://mail.python.org/mailman/listinfo/python-list
Re: CSV with comments
Daniel Dittmar [EMAIL PROTECTED] wrote: if line [:1] == '#': What's wrong with line[0] == '#' ? (For one thing, it's fractionally faster than [:1].) -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
access to submodules
hi. This is my first try on modules. I've got : tom/ __init__.py core.py ui.py data.py then, when I'm in my ipython shell : ? from tom import * this works, it loads core, ui and data but when I do this : ? import tom ? tom.core AttributeError: 'module' object has no attribute 'core' Well, i guess I missed something, but I don't see what ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organisation
On Wednesday 19 July 2006 3:12 pm, rony steelandt wrote: Imagine I have x projects and they all use util.py What would be the best way to organise this 1. c --\project1\*.py |-\project2\*.py --\globals\util.py This organisation has the problem that if I have to modify something to util.py that I need in project2, I'll have to retest project1 to make sure it still works (that could be project 1..n). 2. A copy of util.py in each project directory ? The advantage is that I can modify each util.py in function of the need of the project but it looks clutered, having n versions of util.py. What is the best solution ? or is there another even better solution ? You could introduce version numbers to your module hierarchy... --\globals\v1-0\util.py \v1-1\util.py \v2-0\utill.py ...then in your code do something like... from globals.v1-0 import util ...which would allow some sharing without needing to retest. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: access to submodules
I've just found this : If I add : import core, data, ui inside my tom/__init__.py file, it will work. But this line does not seems to exist in other files (after having a look at several files inside /usr/lib/python2.4). -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieve ext. variables in python program
[EMAIL PROTECTED] skrev: alfa1234: Does anyone know and equalent way to confirm a Variable from the same property file using PYTHON code ??? Using globals(), locals(), and dir() you can find if your name exists already. Bye, bearophile Hi bearophile !! Thanks for the answer..Tried to use these methods, but with no luck. What needed is a way for my code to look at the external property file with the lines: earProject = sgs-procDist Appname = SGSProcedure and accept earProject and Appname as a Variable if they exist... Can Y help here..?? Rgds alfa1234 -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organisation
rony steelandt [EMAIL PROTECTED] writes: Imagine I have x projects and they all use util.py What would be the best way to organise this 1. c --\project1\*.py | |-\project2\*.py | --\globals\util.py This organisation has the problem that if I have to modify something to util.py that I need in project2, I'll have to retest project1 to make sure it still works (that could be project 1..n). 2. A copy of util.py in each project directory ? The advantage is that I can modify each util.py in function of the need of the project but it looks clutered, having n versions of util.py. What is the best solution ? or is there another even better solution ? Rony Is util.py supposed to do the same thing wherever it is used? No one can answer that for you. Your comments suggested mostly the same, but some differences. In that is the case, then use one main util.py for the common items, and do a local util.py for the locally-specific items. Given proper attention to paths, there should be no confusion. I wouldn't bury the common util.py in a package called globals. That could get really confusing. You might make it a standalone package, or maybe use utilities or common. -- Harry George PLM Engineering Architecture -- http://mail.python.org/mailman/listinfo/python-list
Re: CSV with comments
Sion Arrowsmith wrote: Daniel Dittmar [EMAIL PROTECTED] wrote: if line [:1] == '#': What's wrong with line[0] == '#' ? (For one thing, it's fractionally faster than [:1].) line[0] assumes that the line isn't blank. If the input iterator is a file then that will hold true, but if you were ever to reuse CommentStripper on a list of strings which didn't have a trailing newline it would break at the first blank string. Personally I would use: if line.startswith('#'): which takes about three times as long to execute but I think reads more clearly. timeit.py -s line=' hello world' line[:1]=='#' 100 loops, best of 3: 0.236 usec per loop timeit.py -s line=' hello world' line[0]=='#' 100 loops, best of 3: 0.218 usec per loop timeit.py -s line=' hello world' line.startswith('#') 100 loops, best of 3: 0.639 usec per loop -- http://mail.python.org/mailman/listinfo/python-list
Re: CSV with comments
Sion Arrowsmith wrote: Daniel Dittmar [EMAIL PROTECTED] wrote: if line [:1] == '#': What's wrong with line[0] == '#' ? (For one thing, it's fractionally faster than [:1].) For that matter, what's wrong with line.startswith('#') which expresses the intent rather better as well. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Coding style
In [EMAIL PROTECTED], Boris Borcic wrote: And I don't find `list(False)` to return an empty list be very obvious. What would be your choice ? ``list()`` or ``[]`` for empty lists and a `TypeError` for ``list(False)``. Just like it is right now. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
mysqldb problem
when I set mysql some fields collate utf8_bin, and then fetch these fields is array.array,not the string I expected -- http://mail.python.org/mailman/listinfo/python-list