Re: any ways to judge whether an object is initilized or not in a class
momobear schrieb: > hi, I am puzzled about how to determine whether an object is > initilized in one class, anyone could give me any instructions? > here is an example code: > > class coffee: > def boil(self): >self.temp = 80 > > a = coffer() > if a.temp > 60: > print "it's boiled" > > in C++ language we must initilized a variable first, so there is no > such problem, but in python if we don't invoke a.boil(), we will not > get self.temp to be initilized, any way to determine if it's initilzed > before self.temp be used. You want boil to be called __init__, which is python's constructor name. Then it will be called in a statement like a = coffee() automatically. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
On Mar 19, 4:19 pm, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > momobear schrieb: > > > > > hi, I am puzzled about how to determine whether an object is > > initilized in one class, anyone could give me any instructions? > > here is an example code: > > > class coffee: > > def boil(self): > >self.temp = 80 > > > a = coffer() > > if a.temp > 60: > > print "it's boiled" > > > in C++ language we must initilized a variable first, so there is no > > such problem, but in python if we don't invoke a.boil(), we will not > > get self.temp to be initilized, any way to determine if it's initilzed > > before self.temp be used. > > You want boil to be called __init__, which is python's constructor name. > Then it will be called in a statement like > > a = coffee() > > automatically. > > Diez sorry, I should add more code to implement my ideas. class coffee: def __init__(self): ''' do something here ''' def boil(self): self.temp = 80 a = coffer() if a.temp > 60: print "it's boiled" -- http://mail.python.org/mailman/listinfo/python-list
Re: 911 was a RACIST crime by YANK BASTARDS against all other NATIONS Re: *POLL* How many sheeple believe in the 911 fairy tale and willing to accept an Orwellian doublespeak and enslavement world ?
911's primary utility was that, inadvertently, it sparked off the formation of the global brain: The Social Superorganism and its Global Brain http://pespmc1.vub.ac.be/SUPORGLI.html Have a nice Monday, all. - Don -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
"momobear" <[EMAIL PROTECTED]> writes: > class coffee: > def __init__(self): > ''' > do something here > ''' > def boil(self): >self.temp = 80 > > a = coffer() > if a.temp > 60: > print "it's boiled" class Coffee(object): def __init__(self): self.temp = 20 def boil(self): self.temp = 80 a = coffee() if a.temp > 60: print "it's boiled" In Python, it's conventional to name classes in TitleCase, and instances in lower_case. It's also best to inherit every class from another class, leading to a single hierarchy for all classes and types. 'object' is the one to choose if you don't want the behaviour of any other class. As for the original question: the __init__ method of a class is called immediately after the constructor, so that's the place to initialise any instance attributes. -- \ "At my lemonade stand I used to give the first glass away free | `\ and charge five dollars for the second glass. The refill | _o__) contained the antidote." -- Emo Philips | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
"momobear" <[EMAIL PROTECTED]> wrote: > in C++ language we must initilized a variable first, so there is no > such problem, but in python if we don't invoke a.boil(), we will not > get self.temp to be initilized, any way to determine if it's initilzed > before self.temp be used. > The simplest thing is simply never to attempt to use a variable or an attribute until you know that is has been initialized, so initialize all variables before using them, and initialize all attributes in the class's __init__ method. If you don't have a suitable value for the attribute until later then just start off with None and then you can check for 'a.boil is not None': if you forget to check then Python's strong type checking will stop you from using the None value in an expression expecting a number (or a string). For cases where you aren't sure whether an object has a specific attribute you can use getattr with 3 arguments: if getattr(a, 'boil', 80): ... If that isn't convenient (or it's a variable rather than an attribute) you should fall back on the principle that 'is it better to ask forgiveness than permission': i.e. just try to use the value and handle the exception which is thrown if it doesn't exist. (If the fallback is to substitute a simple value use getattr, if the fallback is complicated or takes a long time to calculate use exception handling). There is also a function 'hasattr' which will tell you whether or not the object has the specified attribute, but internally it just calls 'getattr' and handles the exception so (IMHO) it is generally best just not to bother with 'hasattr'. -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation for "str()" could use some adjustment.
> The Python documentation for "str" says > "str([object]) : > Return a string containing a nicely printable representation of an > object." > > However, there's no mention of the fact that "str" of a Unicode string > with non-ASCII characters will raise a conversion exception. The > documentation (and several Python books) seem to indicate that "str" will > produce some "printable representation" for anything, not raise an > exception. > > I know, it was proposed in PEP 349 to change "str" to return Unicode > strings, and that's coming someday, along with all-Unicode Python, > but meanwhile, the documentation should be clear about this. Hi John, I'm not at all an expert around here but my understanding of the workflow is that bug reports should be submitted to the tracker at sourceforge. There is no guarantee that they will be noticed there but the chances there are much higher than for a message on the mailing list. I just mention this because I've seen your mysqld, urllib and other potentially important bug reports here with no action taken but maybe submitting them to sourceforge would attract some developers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Private data
Dustan a écrit : > http://dustangroups.googlepages.com/privateattributesinpython > > This is something that I just threw together this morning, after a > eureka moment. It's a way of creating private class attributes What for ? We already have one: prefix 'private' names with a single underscore. > and > static function variables (I'm not 100% sure if that's the correct > terminology, but you get what I mean). def somefunc(param, _statics={}): # code here > I haven't tried to create > private instance attributes, mainly because it would just be too > difficult, Same recipe as above : single leading underscore. > and it would be awful syntax. I'm not considering actually > using this, but I do have a couple questions about it. > > 1. Has anyone else ever come up with something like this? I can't > imagine I'm the only person who's ever thought of this. With something like trying to forcefit access restriction in Python ? Nope, you're not the first one here. I've not seen anyone using such a thing in any of the projects I've worked on/with yet. -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
momobear wrote: > hi, I am puzzled about how to determine whether an object is > initilized in one class, anyone could give me any instructions? > here is an example code: > > class coffee: > def boil(self): >self.temp = 80 > > a = coffer() > if a.temp > 60: > print "it's boiled" > > in C++ language we must initilized a variable first, so there is no > such problem, but in python if we don't invoke a.boil(), we will not > get self.temp to be initilized, any way to determine if it's initilzed > before self.temp be used. > I think you might be looking for hasattr: class coffee: def boil(self): if hasattr(self, 'temp') and self.temp > 60: print "Its boilt, yo." else: self.temp = 80 Other ways to do this are try/except: class coffee: def boil(self): try: if self.temp > 60: print "Its bizzle, yo." return except AttributeError: pass self.temp = 80 Which is not so good in my opinion because it takes too much typing and makes your fingers hurt at the very tips. A fun way is with dict.setdefault which might actually be cleanest, but you loose testing the precondition for the print: class coffee: def boil(self): if self.__dict__.setdefault('temp', 80) > 60: print "Its bizzle m'wizzle." py> c = coffee() py> c.temp Traceback (most recent call last): File "", line 1, in AttributeError: coffee instance has no attribute 'temp' py> c.boil() Its bizzle m'wizzle. py> c.temp 80 Of course, the idea is that, in classes, you will be intimately aware of the attributes of your class via __init__, as others have mentioned, so you should never really resort to any of the above. James -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
On Mar 19, 4:50 pm, Duncan Booth <[EMAIL PROTECTED]> wrote: > "momobear" <[EMAIL PROTECTED]> wrote: > > in C++ language we must initilized a variable first, so there is no > > such problem, but in python if we don't invoke a.boil(), we will not > > get self.temp to be initilized, any way to determine if it's initilzed > > before self.temp be used. > > The simplest thing is simply never to attempt to use a variable or an > attribute until you know that is has been initialized, so initialize all > variables before using them, and initialize all attributes in the class's > __init__ method. > > If you don't have a suitable value for the attribute until later then just > start off with None and then you can check for 'a.boil is not None': if you > forget to check then Python's strong type checking will stop you from using > the None value in an expression expecting a number (or a string). > > For cases where you aren't sure whether an object has a specific attribute > you can use getattr with 3 arguments: > >if getattr(a, 'boil', 80): >... > > If that isn't convenient (or it's a variable rather than an attribute) you > should fall back on the principle that 'is it better to ask forgiveness > than permission': i.e. just try to use the value and handle the exception > which is thrown if it doesn't exist. (If the fallback is to substitute a > simple value use getattr, if the fallback is complicated or takes a long > time to calculate use exception handling). > > There is also a function 'hasattr' which will tell you whether or not the > object has the specified attribute, but internally it just calls 'getattr' > and handles the exception so (IMHO) it is generally best just not to bother > with 'hasattr'. thanks for help:), I am puzzled about if I have to use try and except to determine it. finnal code should like this? class coffee: def __init__(self): ''' do something here ''' def boil(self): self.temp = 80 a = coffer() try: if a.temp > 60: print "it's boiled" except AttributeError: print "it's not boiled" -- http://mail.python.org/mailman/listinfo/python-list
keyword arguments for xml-rpc
I've just noticed that I can't seem to use keyword arguments for xml-rpc requests even though the protocol itself encodes parameter names, types, and values when it sends the xml across the network. This becomes a bit problematic for me because I want to store some XML- RPC method dispatch signatures in a database and can't easily guarantee parameter order when I load it so being able to pass a dictionary of name/value pairs greatly eases the development effort and helps assure correct methods get invoked. Is this a limitation of the SimpleXMLRPCServer, the xmlrpclib.ServerProxy, or something completely different? -- http://mail.python.org/mailman/listinfo/python-list
Re: keyword arguments for xml-rpc
[EMAIL PROTECTED] wrote: > I've just noticed that I can't seem to use keyword arguments for > xml-rpc requests even though the protocol itself encodes parameter > names, types, and values when it sends the xml across the network. > This becomes a bit problematic for me because I want to store some XML- > RPC method dispatch signatures in a database and can't easily > guarantee parameter order when I load it so being able to pass a > dictionary of name/value pairs greatly eases the development effort > and helps assure correct methods get invoked. Is this a limitation of > the SimpleXMLRPCServer, the xmlrpclib.ServerProxy, or something > completely different? I don't see[1] the possibility to pass keyword arguments via XMLRPC. Where did you get that impression from? You can pass structs though, maybe that confused you? Diez [1] http://www.xmlrpc.com/spec -- http://mail.python.org/mailman/listinfo/python-list
from maple to python + numpy/scipy
I'm just getting started with numpy/scipy and first would like to get a view of what it can do and what it can't. The main idea is to move from maple to python and the first thing that poped up is the fact that maple is very convenient for both formal manipulations and exact integer calculations. For instance if a matrix has integer entries and the eigenvalues are integers maple can find these exactly. Can numpy/scipy do this? Or the eigenvalues will always be floating point numbers? -- http://mail.python.org/mailman/listinfo/python-list
Re: XML based programming language
Thank you Diez for answering. As far as I can see, it more or less corresponds to what I have. But my question was perhaps more this: "If elementtree is "lex", what is "yacc" ? " -- http://mail.python.org/mailman/listinfo/python-list
Re: Private data
On Mar 19, 4:09 am, Bruno Desthuilliers wrote: > Dustan a écrit : > > >http://dustangroups.googlepages.com/privateattributesinpython > > > This is something that I just threw together this morning, after a > > eureka moment. It's a way of creating private class attributes > > What for ? We already have one: prefix 'private' names with a single > underscore. > > > and > > static function variables (I'm not 100% sure if that's the correct > > terminology, but you get what I mean). > > def somefunc(param, _statics={}): ># code here > > > I haven't tried to create > > private instance attributes, mainly because it would just be too > > difficult, > > Same recipe as above : single leading underscore. > > > and it would be awful syntax. I'm not considering actually > > using this, but I do have a couple questions about it. > > > 1. Has anyone else ever come up with something like this? I can't > > imagine I'm the only person who's ever thought of this. > > With something like trying to forcefit access restriction in Python ? > Nope, you're not the first one here. I've not seen anyone using such a > thing in any of the projects I've worked on/with yet. You ignored certain parts of my post, like "I'm not considering actually using this, but I do have a couple questions about it"; I assume that means you're not even going to begin to attempt to answer my queries. Likewise, you ignored a similar message on the page I linked to. I already knew about everything you told me. With all this active ignoring, I get the feeling you're not even trying to respond to my questions. So why respond in the first place? Were you trying to be hostile? Because I can't see any other intent for your post. -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
"momobear" <[EMAIL PROTECTED]> wrote: > thanks for help:), I am puzzled about if I have to use try and except > to determine it. finnal code should like this? > class coffee: > def __init__(self): > ''' > do something here > ''' > def boil(self): >self.temp = 80 > > a = coffer() > try: > if a.temp > 60: > print "it's boiled" > except AttributeError: > print "it's not boiled" No, you should simply do the first of the options I suggested. i.e. initialise the value class coffee: def __init__(self): self.temp = 20 def boil(self): self.temp = 80 a = coffee() if a.temp > 60: print "it's boiled" else: print "it's not boiled" -- http://mail.python.org/mailman/listinfo/python-list
Re: keyword arguments for xml-rpc
Diez, Yes thanx - that (structs) is indeed where my confusion lies... :) Alas, ordered parameters it is. On Mar 19, 5:44 am, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > I don't see[1] the possibility to pass keyword arguments via XMLRPC. Where > did you get that impression from? You can pass structs though, maybe that > confused you? > > Diez > > [1]http://www.xmlrpc.com/spec -- http://mail.python.org/mailman/listinfo/python-list
Re: from maple to python + numpy/scipy
Daniel Nogradi wrote: > I'm just getting started with numpy/scipy and first would like to get > a view of what it can do and what it can't. The main idea is to move > from maple to python and the first thing that poped up is the fact > that maple is very convenient for both formal manipulations and exact > integer calculations. For instance if a matrix has integer entries and > the eigenvalues are integers maple can find these exactly. > > Can numpy/scipy do this? Or the eigenvalues will always be floating > point numbers? it might be better to ask this question on the scipy newsgroup SciPy Users List <[EMAIL PROTECTED]> cheers, Stef Mientki -- http://mail.python.org/mailman/listinfo/python-list
Re: from maple to python + numpy/scipy
Daniel Nogradi wrote: > I'm just getting started with numpy/scipy and first would like to get > a view of what it can do and what it can't. The main idea is to move > from maple to python and the first thing that poped up is the fact > that maple is very convenient for both formal manipulations and exact > integer calculations. For instance if a matrix has integer entries and > the eigenvalues are integers maple can find these exactly. > > Can numpy/scipy do this? Or the eigenvalues will always be floating > point numbers? Have a look at SAGE (Software for Algebra and Geometry Experimentation) http://www.sagemath.org/ Jaap -- http://mail.python.org/mailman/listinfo/python-list
Re: XML based programming language
stefaan wrote: > Thank you Diez for answering. > As far as I can see, it more or less corresponds to what I have. > > But my question was perhaps more this: > > "If elementtree is "lex", what is "yacc" ? " Elementtree isn't lex. You are comparing apples and oranges here. Lex tokenizes, yacc creates trees. Both of is covered in XML itself - it's defined the tokenization and parsing, built into elementtree. So, elemnttree is lex _and_ yacc for XML. And if your language is written in XML, that's all there is to it. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Building several parsing modules
Robert Neville wrote: > Basically, I want to create a table in html, xml, or xslt; with any > number of regular expressions; a script (Perl or Python) which reads > each table row (regex and replacement); and performs the replacement > on any file name, folder, or text file (e.g. css, php, html). For > example, I often rename my mp3 (files); the folder holding the mp3 > files; and replace these renamed values in a playlist/m3u/xml file. Don't do it. Just write python for the task at hand - if it involves regular expressions, use the re module if you must, but lots of stuff can be done with simpler, less confusing means like string.split and the like. The result should be a small few-liner. You are way better off with that, especially when you have to take constraints into account like moon phase or the like - you then have the full power of python at your hand, instead of inventing some wicked table-based "language" that you code exceptions into. Diez -- http://mail.python.org/mailman/listinfo/python-list
Looking for a job?
Free. Find a Job here now--> http://www.jobbankdata.com -- http://mail.python.org/mailman/listinfo/python-list
PythonCard thoughts
Hi to all folks here, i downloaded and "playing" with PythonCard and i just want to share my thoughts so maybe we can discuss a little about it. I was used to wxGlade before and i think PythonCard is even better. I like the separate implementation of GUI and Code that PythonCard provides, i also like the "binding system" so you can bind functions to events and have them executed at runtime. I also like that it does not force you to use sizers and all that stuff and that you can freely place your components on the form and set their exact position just with the mouse. The only "problem" i see with this design is that by that separation of Gui/Code, you loose the intellisense that (ex. PyDev) some editors/ plugins can provide because in the .py file nothing is indicating that , for example, the btnDoWork is a Button object. This force you to remember many properties and switch back and forth between your code and the wxPython help file. This is not the case for wxGlade because all boilerplate code is in the same file (for good and for bad) and PyDev (and others too) can "understand" for which kind of objects we are talking about and so can display -and thus help us- with their properties. Apart from that, everything else is great. Any opinions/suggestion on all this ? -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
Hitesh a écrit : > On Mar 18, 12:28 am, "Hitesh" <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I've a list like this.. >> str1 = ['this is a test string inside list'] >> >> I am doing it this way. >> >> for s in str1: >> temp_s = s >> print temp_s Why this useless temp_s var ? >> >> Any better suggestions? >> >> Thank you, >> hj > > I want to cast value of a list into string.. > There's no "cast" in Python. It would make no sens in a dynamically typed language, where type informations belong to the LHS of a binding, not the RHS. I guess that what you want is to build a string out of a list of strings. If so, the answer is (assuming you want a newline between each element of the list): print "\n".join(str1) -- http://mail.python.org/mailman/listinfo/python-list
Fun little project
This is what happens when a joke goes too far - so far that it generates Python code. http://code.google.com/p/pr0nbot/ Have fun! []s FZero -- http://mail.python.org/mailman/listinfo/python-list
Re: Still the __new__ hell ...
Paulo da Silva a écrit : (snip) Not an answer to your question, just a couple advices: > from datetime import date > import cPickle,string The string module is mostly deprecated. You should use str type methods whenever possible (cf below) > class MyDate(date): > def __new__(cls,year,month=None,day=None): > if type(year) is str: And what if it's a unicode string ? The correct idiom here is: if isinstance(year, basestring): > year,month,day=map(int,string.split(year,'-')) year, month, day = map(int, year.split('-')) > if year < 100: > year += 2000 > return date.__new__(cls,year,month,day) > (snip) -- http://mail.python.org/mailman/listinfo/python-list
Re: Private data
Dustan a écrit : > On Mar 19, 4:09 am, Bruno Desthuilliers [EMAIL PROTECTED]> wrote: >> Dustan a écrit : >> >>> http://dustangroups.googlepages.com/privateattributesinpython >>> This is something that I just threw together this morning, after a >>> eureka moment. It's a way of creating private class attributes (snip) >>> 1. Has anyone else ever come up with something like this? I can't >>> imagine I'm the only person who's ever thought of this. >> With something like trying to forcefit access restriction in Python ? >> Nope, you're not the first one here. I've not seen anyone using such a >> thing in any of the projects I've worked on/with yet. > > You ignored certain parts of my post, like "I'm not considering > actually using this, but I do have a couple questions about it"; I > assume that means you're not even going to begin to attempt to answer > my queries. Likewise, you ignored a similar message on the page I > linked to. I already knew about everything you told me. > > With all this active ignoring, I get the feeling you're not even > trying to respond to my questions. So why respond in the first place? > Were you trying to be hostile? > > Because I can't see any other intent > for your post. I didn't missed the "I'm not considering actually using this" part, but I missed the note on the page - and I apologize if you felt offended by my remarks, which were effectivly a bit on the reactive side. Still there was an implied question : *why* trying to implement access restriction in Python ? -- http://mail.python.org/mailman/listinfo/python-list
Re: XML based programming language
> Elementtree isn't lex. You are comparing apples and oranges here. Lex > tokenizes, yacc creates trees. Both of is covered in XML itself - it's > defined the tokenization and parsing, built into elementtree. So, > elemnttree is lex _and_ yacc for XML. And if your language is written in > XML, that's all there is to it. I see your point. But yacc does more: I specify a grammar, and yacc will reject input files that do not conform to the grammar. Elementtree OTOH will happily accept any valid XML file, all checking has to implememented manually by me. Best regards, Stefaan. -- http://mail.python.org/mailman/listinfo/python-list
Re: Still the __new__ hell ...
On Mon, 19 Mar 2007 13:17:11 +0100, Bruno Desthuilliers > > [snip] > >And what if it's a unicode string ? >The correct idiom here is: > if isinstance(year, basestring): > >> year,month,day=map(int,string.split(year,'-')) > year, month, day = map(int, year.split('-')) And what if it's another kind of string? The correct idiom is: try: parts = year.split('-') except AttributeError: # Handle int case else: year, month, day = map(int, parts) > >> if year < 100: >> year += 2000 >> return date.__new__(cls,year,month,day) >> >(snip) >-- >http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: IDE for wxPython
Ghirai a écrit : > Hello python-list, > > Can anyone suggest an IDE for wxPython? > Or an IDE for TkInter? Do you really mean IDE, or are you in fact looking for a GUI designer tool ? If the latter, you may want to have a look at wxGlade. -- http://mail.python.org/mailman/listinfo/python-list
Re: XML based programming language
stefaan a écrit : >> Elementtree isn't lex. You are comparing apples and oranges here. Lex >> tokenizes, yacc creates trees. Both of is covered in XML itself - it's >> defined the tokenization and parsing, built into elementtree. So, >> elemnttree is lex _and_ yacc for XML. And if your language is written in >> XML, that's all there is to it. > > I see your point. But yacc does more: I specify a grammar, and yacc > will > reject input files that do not conform to the grammar. > Elementtree OTOH will happily accept any valid XML file, all checking > has to > implememented manually by me. > > Best regards, > Stefaan. > For an XML represented programming language, isn't the DTD (or other XML definition format) your grammar? IE. Just use an XML validator tool and you dont need to write checking. DTDs may be not enough, see other definitions tools. -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
Diez B. Roggisch a écrit : > momobear schrieb: >> hi, I am puzzled about how to determine whether an object is >> initilized in one class, anyone could give me any instructions? >> here is an example code: >> >> class coffee: >> def boil(self): >>self.temp = 80 >> >> a = coffer() >> if a.temp > 60: >> print "it's boiled" >> >> in C++ language we must initilized a variable first, so there is no >> such problem, but in python if we don't invoke a.boil(), we will not >> get self.temp to be initilized, any way to determine if it's initilzed >> before self.temp be used. > > You want boil to be called __init__, which is python's constructor name. Actually, __init__ is the initializer. The proper constructor is __new__. -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
momobear a écrit : > hi, I am puzzled about how to determine whether an object is > initilized in one class, anyone could give me any instructions? > here is an example code: > > class coffee: > def boil(self): >self.temp = 80 > > a = coffer() > if a.temp > 60: > print "it's boiled" > > in C++ language we must initilized a variable first, so there is no > such problem, but in python if we don't invoke a.boil(), we will not > get self.temp to be initilized, Obviously. This is why it's good form to set all public attributes in the initializer method: class Coffee(object): def __init__(self): self.temp = 20 def boil(self): self.temp = 80 -- http://mail.python.org/mailman/listinfo/python-list
Real Time Embedded Systems Monitor in Python?
Hey Everyone! I've got a question regarding the capabilities of python in a real time environment. I'll start by saying I'm a little bit flaky when it comes to terminology, so please correct me or ask where it seems I'm not beings specific or using the wrong wording. I am looking into a project for the company I work for. Essentially it involves setting up a real time monitor / signal injector in between a CPU board and a system controller. The system controller sends signals (message packets) to the CPU board. We would like to create an environment where we can modify signals, inject new messages, drop signals, etc. This would simulate communication failures and message dropouts to see how the CPU board responds. The application monitor would use a COM port to send and receive messages. The most important part about this monitor is that absolutely no messages get delayed or dropped due to inturrupts or lag on the PC that the monitor is running on. What would be the expected sampling time range that I could expect to handle? I have seen similar applications written for other projects that we have which were done in Visual Basic. I assume that if VB is up to the task, Python should be as well. What kind of libraries am I looking at? I will probably use wxWindows, but what about for the serial ports and packet timing? Like I said - I'm not sure what kind of "real time" this is - all I know is that I need messages to not get dropped when they're received. Thanks! Blaine Booher -- http://mail.python.org/mailman/listinfo/python-list
Re: XML based programming language
stefaan wrote: >> Elementtree isn't lex. You are comparing apples and oranges here. Lex >> tokenizes, yacc creates trees. Both of is covered in XML itself - it's >> defined the tokenization and parsing, built into elementtree. So, >> elemnttree is lex _and_ yacc for XML. And if your language is written in >> XML, that's all there is to it. > > I see your point. But yacc does more: I specify a grammar, and yacc > will > reject input files that do not conform to the grammar. > Elementtree OTOH will happily accept any valid XML file, all checking > has to > implememented manually by me. First of all: nearly all parsers allow syntactically more, than their languages semantics actually admit. So you will have to have certain (most of the time context sensitive) checks hand-coded. But this is a small digression. What you are after then is the usage of a validating parser, not just well-formed XML-documents. I'm not sure where element-tree stands regarding this, but I think 4suite offers DTD, W3C-Schema and Relax-NG support. All of these are grammar-specifications that allow you to define the structure of your XML-documents with more constraints. Diez -- http://mail.python.org/mailman/listinfo/python-list
Report options...
> Hello, > > Right now Im migrating an VB6+Crystal report+Word App to Python+wxPython > +Reportlab+??? > > The VB system work with Word, creating some patterns (title, foot prints, > etc) and users maybe could insert some new text and Form fields (like > parameters) to personalize the > output, connecting this fields with an recordset retrieve from a DB. > > I dont want to use any external tool for this taks (OpenOffice+pyUno is > my last chance) > > Any suggestion? > > Thanks! > > Mi configuracion/My config: > > Ubuntu Edgy Eft 6.10 > Linux Kernel 2.6.17-11-386 > Gnome 2.16.1 > Python 2.4.4c1 > wxPython 2.8.1.1 Unicode > Python IDE: Ulipad 3.6 > Database: Firebird 2.0 Superserver > > -- > Saludos / Best regards > > Mario Lacunza Vásquez > Desarrollador de Software - Webmaster > Linux Registered User #439179 > Desarrollador 2 Estrellas VS2005 > > Website: http://mlacunzav[DOT]cogia[DOT]net > Email : mlacunza[AT]gmail.com / mario_lacunza[AT]yahoo.es > Blog : http://mlacunza.blogspot.com > Lima - Peru -- http://mail.python.org/mailman/listinfo/python-list
Timeout to readline()/readlines()
Hi folks, Sometimes, when I do an os.popen*(), the process executed by the command hangs, and the script stops forever on the readline()/ readlines() calls. I found that I can use select, but I'm thinking... if, after a sellect() call returns, the stdout (for example) has more than one line? or if it has just some characters, no newline, and the process just hangs? I just want a readline(timeout) and readlines(timeout) like functions. Do I need to create my owns or there're already implemented? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: XML based programming language
Diez B. Roggisch napisał(a): > I'm not sure where element-tree stands regarding this, but I think 4suite > offers DTD, W3C-Schema and Relax-NG support. This varies depending on implementation. As Fredrik Lundh's original implementation is based on expat parser, it has no ability to check anything besides well-formedness of document. AFAIK lxml implementation exposes some of libxml2 abilities to check the document conformance to XML schema definition. -- Jarek Zgoda "We read Knuth so you don't have to." -- http://mail.python.org/mailman/listinfo/python-list
Boost Python properties/getter functions for strings
Hi, I'm trying to expose a C++ class' internals to python via boost::python. I can do integer/boolean functions fine, but as soon as I do a string get/set it craps out. boost::python::class_ >("Entity") //publics .def("isActive", &Entity::isActive) //bool .def("activate", &Entity::activate) //bool .def("deactivate", &Entity::deactivate) //bool //... .add_property("name", &Entity::getName) //compile error (1) .def("getName", &Entity::getName, boost::python::return_internal_reference<>()); //runtime error(2) Compile error (1) shows this: C:/MinGW/include/boost/python/detail/ invoke.hpp: In function `PyObject* boost::python::detail::invoke(boost::python::detail::invoke_tag_< false, true>, const RC&, F&, TC&) [with RC = boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning, F = const std::string&(rsblsb::Entity::*)() const, TC = boost::python::arg_from_python]': C:/MinGW/include/boost/python/detail/caller.hpp:199: instantiated from `PyObject* boost::python::detail::caller_arity<1u>::impl::operator()(PyObject*, PyObject*) [with F = const std::string&(rsblsb::Entity::*)() const, Policies = boost::python::default_call_policies, Sig = boost::mpl::vector2]' C:/MinGW/include/boost/python/object/py_function.hpp:38: instantiated from `PyObject* boost::python::objects::caller_py_function_impl::operator() (PyObject*, PyObject*) [with Caller = boost::python::detail::caller >]' C:\Game\svn\Platform\Framework\Python\PyModuleSetup.cc:58: instantiated from here C:/MinGW/include/boost/python/detail/invoke.hpp:88: error: no match for call to `(const boost::python::detail::specify_a_return_value_policy_to_wrap_functions_returning) (const std::basic_string, std::allocator >&)' Runtime error 2 just crashes whenever I try: import modulename I = modulename.Entity() I.getName() Anyone have any idea what I can try? thanks a lot! -Shawn. -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
En Mon, 19 Mar 2007 05:35:00 -0300, momobear <[EMAIL PROTECTED]> escribió: >> > in C++ language we must initilized a variable first, so there is no >> > such problem, but in python if we don't invoke a.boil(), we will not >> > get self.temp to be initilized, any way to determine if it's initilzed >> > before self.temp be used. > > sorry, I should add more code to implement my ideas. > class coffee: > def __init__(self): > ''' > do something here > ''' > def boil(self): >self.temp = 80 > > a = coffer() > if a.temp > 60: > print "it's boiled" Apart from the other suggestions (ensure full initialization in __init__, using getattr, using hasattr) you may consider using a class attribute as a default value: class Coffee: temp = 50 def __init__(self): "do something" def boil(self): self.temp = 80 a = Coffee() print a.temp # 40 a.boil() print a.temp # 80 -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard thoughts
king kikapu wrote: > The only "problem" i see with this design is that by that separation > of Gui/Code, you loose the intellisense that (ex. PyDev) some editors/ > plugins can provide because in the .py file nothing is indicating > that , for example, the btnDoWork is a Button object. > This force you to remember many properties and switch back and forth > between your code and the wxPython help file. This is not the case for > wxGlade because all boilerplate code is in the same file (for good and > for bad) I don't know much about PythonCard or wxGlade, but I use wxPython (which wxGlade uses, right?) and you now have the option to separate your GUI and code using an XRC file (xml file that describes layout). So perhaps this is something you can do with wxGlade, but at the same time it might still create the problem you describe above. However, it's very to have your Python files contain just logic. -- http://mail.python.org/mailman/listinfo/python-list
Re: Choosing Python
[EMAIL PROTECTED] wrote: > One of the many things I like about Ada is that it is the same wherever > you use it. Python seems to be that way too. Java started out that way. > It was the intention for Java to be more portable than it is. I have heard > that Java was released before the developers were finished designing it. > That would account for some of the upheaval in the language. I do know > of one set of software systems that has simply stopped working after the > initial release of Java was revised. The appliation was versioned it out > of compliance. When Python 3.0 comes out, there will be some backwards incompatibility, but I doubt this will be a huge factor. It might just take some time before everyone switches to it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Still the __new__ hell ...
Jean-Paul Calderone a écrit : > On Mon, 19 Mar 2007 13:17:11 +0100, Bruno Desthuilliers >> >> [snip] >> >> And what if it's a unicode string ? >> The correct idiom here is: >> if isinstance(year, basestring): >> >>> year,month,day=map(int,string.split(year,'-')) >> year, month, day = map(int, year.split('-')) > > And what if it's another kind of string? One that doesn't inherit from basestring ? > The correct idiom is: > > try: > parts = year.split('-') > except AttributeError: > # Handle int case > else: > year, month, day = map(int, parts) > >> >>> if year < 100: >>> year += 2000 >>> return date.__new__(cls,year,month,day) >>> And what if it's an object that has nothing to do with a string but happens to have a split() method ?-) >> (snip) Jean-Paul, you're of course right from a theoretical POV. Practically speaking, chances that such a method will ever be fed with a string-like object not deriving from basestring are IMVHO *very* low. While I usually raise a big warning flag when I spot a test against isinstance(), I'd say this is an example of the few cases where it's ok. YMMV of course... -- http://mail.python.org/mailman/listinfo/python-list
When is List Comprehension inappropriate?
I have recently learned how list comprehension works and am finding it extremely cool. I am worried, however, that I may be stuffing it into places that it does not belong. What's the most "pythony" way to do this: even = [] for x in range(0,width,2): for y in range(0,height,2): color = im.getpixel((x,y)) even.append(((x,y), color)) versus list comprehension: even2 = [((x,y), im.getpixel((x,y))) for x in range(0,width,2) for y in range(0,height,2)] Is there a computational difference in creating a blank list and appending to it versus doing a list comprehension? Are there advantages to it outside of short and pretty code? Feel free to tell me a different way to do this, as well. Thanks, Ben -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard thoughts
> I don't know much about PythonCard or wxGlade, but I use wxPython (which > wxGlade uses, right?) and you now have the option to separate your GUI > and code using an XRC file (xml file that describes layout). So perhaps > this is something you can do with wxGlade, but at the same time it might > still create the problem you describe above. However, it's very to have > your Python files contain just logic. Yes, both products (PythonCard and wxGlade) uses wxPython. It's just that PythonCard is sitting on top of wxPython and it intercepts the events generated. Then it search for an appropriate declared function on your code and call it (all this happens at runtime). It shield us from much of the boilerplate code that gui toolkits require and in the case that you need to address directly wxPython, you just can! I discovered that when you run your designed GUI from PythonCard's layoutEditor, you have the ability to define a command line option that is called "Message Watcher". This, will show you the names of the actual events that you have to write code for, so you, at least for this, do not have to dig the docs for their names. Pretty good! -- http://mail.python.org/mailman/listinfo/python-list
Re: class objects, method objects, function objects
"7stud" wrote: > But the last part of the passage makes no sense to me: > -- > When the method object is called with an argument list, it is unpacked > again, a new argument list is constructed from the instance object and > the original argument list, and the function object is called with > this new argument list. > -- > Can anyone interpret that for me? when you call obj.method(arg1, arg2), Python prepends the actual instance object (obj) to the argument list, so you end up calling (obj.method) with the arguments (obj, arg1, arg2). -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing a list of functions
On Mar 16, 6:44 pm, James Stroud <[EMAIL PROTECTED]> wrote: > HMS Surprise wrote: > > Seems to me that one should be able to put the names of several > > functions in a list and then have the list executed. But it seems the > > output of the functions is hidden, only their return value is visible. > > Is this because the list execution is another scope? > > > Thanx, > > > jh > > > > > > def a(): > > print "this is a" > > > def b(): > > print "this is b" > > > lst = [a(), b()] > > > lst > > The "print" statement does nothing to return a value from the function, > so the strings "this is *" will not be stored in your list. They will, > however, be printed if you are some how observing your program output > (e.g. running it in IDLE, or a command shell). > > To save the "results" of the functions, you need to produce results, > which means actually using "return" to return some value. Here is an > example: > > def a(): >print "this is a" >return "return value from a" > > def b(): >print "this is b" >return "return value from b" > > functions = [a, b] > results = [f() for f in functions] > print results > > Here is the result of this example: > > py> def a(): > ... print "this is a" > ... return "return value from a" > ... > py> def b(): > ... print "this is b" > ... return "return value from b" > ... > py> functions = [a, b] > py> results = [f() for f in functions] > this is a > this is b > py> print results > ['return value from a', 'return value from b'] > > A fun, but unfortunately deprecated, way to do this is with the "apply" > function in conjunction with the "map" function: > > def a(): >print "this is a" >return "return value from a" > > def b(): >print "this is b" >return "return value from b" > > functions = [a, b] > results = map(apply, functions) > print results > > Here is this example at work: > > py> def a(): > ... print "this is a" > ... return "return value from a" > ... > py> def b(): > ... print "this is b" > ... return "return value from b" > ... > py> functions = [a, b] > py> results = map(apply, functions) > this is a > this is b > py> print results > ['return value from a', 'return value from b'] > > James Thanks to all for posting. Why is apply deprecated? jh -- http://mail.python.org/mailman/listinfo/python-list
Re: When is List Comprehension inappropriate?
Ben <[EMAIL PROTECTED]> wrote: > I have recently learned how list comprehension works and am finding it > extremely cool. I am worried, however, that I may be stuffing it into > places that it does not belong. > > What's the most "pythony" way to do this: > > even = [] > for x in range(0,width,2): > for y in range(0,height,2): > color = im.getpixel((x,y)) > even.append(((x,y), color)) > > versus list comprehension: > > even2 = [((x,y), im.getpixel((x,y))) for x in range(0,width,2) for y > in range(0,height,2)] > > Is there a computational difference in creating a blank list and > appending to it versus doing a list comprehension? Are there > advantages to it outside of short and pretty code? > > Feel free to tell me a different way to do this, as well. I like list comprehensions when I'm building up a list, originally empty, with .append calls within for loops (possibly with an if guard), unless I need (e.g.) a conditional break, which LCs don't support. IOW, I would use a LC in your example. However, I would format it more neatly: even2 = [((x,y), im.getpixel((x,y))) for x in range(0,width,2) for y in range(0,height,2)] though I guess that's a matter of taste. Some people think that LCs should not be used except for extremely simple cases, but I personally disagree with that stance. The cases where an LC should NOT be used are those in which you are not really building a list as above described, but e.g. "just looping". To check whether LC is faster than, slower than, or equal to a more extensive loop, use timeit, e.g.: brain:~/py25/Doc alex$ python -mtimeit -s'xs=range(83)' 'L=[]' 'for x in xs: L.append(x*x)' 1 loops, best of 3: 34.6 usec per loop brain:~/py25/Doc alex$ python -mtimeit -s'xs=range(83)' 'L=[x*x for x in xs]' 10 loops, best of 3: 19.4 usec per loop So for this simple case, it may look like the LC is much faster; however: brain:~/py25/Doc alex$ python -mtimeit -s'xs=range(83)' 'L=[];ap=L.append' 'for x in xs: ap(x*x)' 1 loops, best of 3: 22.3 usec per loop ...as you can see, hoisting the L.append lookup out of the loop accounts for most of the difference. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Executing a list of functions
HMS Surprise <[EMAIL PROTECTED]> wrote: ... > Why is apply deprecated? Because it does exacly the same job as just calling the function with *a/**k, and there should preferably be only one obvious way to perform a given task (this guiding principle leads to simplicity in the language, and is common to Python and to the "Spirit of C" as explained in the preface of the ISO C Standard -- they phrase it as "offer only one way to perform an operation", I believe). Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard thoughts
On Mar 19, 11:44 am, "king kikapu" <[EMAIL PROTECTED]> wrote: > > I don't know much about PythonCard or wxGlade, but I use wxPython (which > > wxGlade uses, right?) and you now have the option to separate your GUI > > and code using an XRC file (xml file that describes layout). So perhaps > > this is something you can do with wxGlade, but at the same time it might > > still create the problem you describe above. However, it's very to have > > your Python files contain just logic. > > Yes, both products (PythonCard and wxGlade) uses wxPython. It's just > that PythonCard is sitting on top of wxPython and it intercepts the > events generated. Then it search for an appropriate declared function > on your code and call it (all this happens at runtime). > It shield us from much of the boilerplate code that gui toolkits > require and in the case that you need to address directly wxPython, > you just can! > > I discovered that when you run your designed GUI from PythonCard's > layoutEditor, you have the ability to define a command line option > that is called > "Message Watcher". This, will show you the names of the actual events > that you have to write code for, so you, at least for this, do not > have > to dig the docs for their names. Pretty good! Would you please explain more in detail this "Message Watcher" option? I use PythonCard from time to time, and I find it very easy to use and practical, even considering the small shortcomings you mentioned above, but I have no idea of this feature you're talking about.. Regards, Luis -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard thoughts
> Would you please explain more in detail this "Message Watcher" option? > I use PythonCard from time to time, and I find it very easy to use and > practical, even considering the small shortcomings you mentioned > above, but I have no idea of this feature you're talking about.. > > Regards, > Luis Luis, go to File/Run Options and check the third choice called "Message Watcher", then run your design. You will then see that every event that is triggered is displayed to you and when you actually want to see the event that you interested in, you just cause it to happen and then it is displayed on the message watcher event grid. You then go to your source file and armed with the known notation (on_controlName_eventName) you write the code. I copy from the manual of PythonCard: "The Message Watcher integrates with the wxPython event model to show you in real time the events that are being triggered when a PythonCard application is running. It helps determine where the application code should go and verify that a PythonCard application is operating as expected." -- http://mail.python.org/mailman/listinfo/python-list
Re: Grep Equivalent for Python
On Mar 18, 7:33 pm, [EMAIL PROTECTED] (Aahz) wrote: > In article <[EMAIL PROTECTED]>, > > > > > > tereglow <[EMAIL PROTECTED]> wrote: > >On Mar 15, 1:47 am, [EMAIL PROTECTED] (Alex Martelli) wrote: > >> tereglow <[EMAIL PROTECTED]> wrote: > > >>>grep^MemTotal /proc/meminfo | awk '{print $2}' > > >> If you would indeed do that, maybe it's also worth learning something > >> more about the capabilities of your "existing" tools, since > > >> awk '/^MemTotal/ {print $2}' /proc/meminfo > > >> is a more compact and faster way to perform exactly the same task. > > >> (You already received a ton of good responses about doing this in > >> Python, but the "pipegrepinto awk instead of USING awk properly in the > >> first place!" issue has been a pet peeve of mine for almost 30 years > >> now, and you know what they say about old dogs + new tricks!-). > > >I had no idea you could do that. Thanks for the tip, I need to start > >reading that awk/sed book collecting dust on my shelf! > > Your other option is to completely abandon awk/sed. I started writing > stuff like this in Turbo Pascal back in the early 80s because there > simply wasn't anything like awk/sed available for CP/M. In the 90s, when > I needed to do similar things, I used Perl. Now I use Python. > > From my POV, there is really no reason to learn the advanced shell > utilities. > -- > Aahz ([EMAIL PROTECTED]) <*>http://www.pythoncraft.com/ > > "Typing is cheap. Thinking is expensive." --Roy Smith- Hide quoted text - > > - Show quoted text - Well, my goal is to become proficient enough at Python, that I can replace most shell functionality with it. I was partially successful when learning Perl. The trouble is that I started with shell, awk/sed/ grep, that sort of stuff. It is somewhat difficult to break free of "shell" like thinking and programming when you have created habits of coding in that style. I've recently started to work with an application (HP Application Mapping) that has an awful lot of Jython code running in the background; so that project sort of inspired me to start really digging into Python; to gain a better understanding of the application, and for any added benefit; especially in regards to automating systems administration. Am really enjoying learning it, though it hurts the head a bit, trying to re-train myself. Things take time though, I'm not giving up! -- http://mail.python.org/mailman/listinfo/python-list
Using pxssh
Hello, I am trying to convert some Expect/Tcl code into Python by using the Pexpect module. The environment is such that authenticated keys are disabled although SSH is available. I do not have control over this environment, so I'm trying to automate tasks within it via Expect. I noticed that, within the Pexpect documentation, it mentions a class called "pxssh". Has anyone used this before? If so, I'm having some trouble importing it. If I just import pxssh doesn't seem to work; really am not sure how this is related to Pexpect or how to use it from within it. Any help is appreciated. Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: When is List Comprehension inappropriate?
On Mar 19, 9:41 am, "Ben" <[EMAIL PROTECTED]> wrote: > even = [] > for x in range(0,width,2): > for y in range(0,height,2): > color = im.getpixel((x,y)) > even.append(((x,y), color)) > > versus list comprehension: > > even2 = [((x,y), im.getpixel((x,y))) for x in range(0,width,2) for y > in range(0,height,2)] > To simplify access to individual pixels, you can make even2 into a dict using: even2asDict = dict(even2) and then you can directly get the pixel in the 4th row, 5th column (zero-based) as: even2asDict[(4,5)] If you really want something more like a 2-D array, then create a list comp of lists, as in: even2 = [ [im.getpixel((x,y)) for x in range(0,width,2) ] for y in range(0,height,2) ] which allows you to use list indexing to get individual pixel values, as in: even2[4][5] to get the same pixel as above. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Still the __new__ hell ...
On Mon, 19 Mar 2007 15:39:49 +0100, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: >Jean-Paul Calderone a écrit : >> On Mon, 19 Mar 2007 13:17:11 +0100, Bruno Desthuilliers >>> >>> [snip] >>> >>> And what if it's a unicode string ? >>> The correct idiom here is: >>> if isinstance(year, basestring): >>> year,month,day=map(int,string.split(year,'-')) >>> year, month, day = map(int, year.split('-')) >> >> And what if it's another kind of string? > >One that doesn't inherit from basestring ? > >> The correct idiom is: >> >> try: >> parts = year.split('-') >> except AttributeError: >> # Handle int case >> else: >> year, month, day = map(int, parts) >> >>> if year < 100: year += 2000 return date.__new__(cls,year,month,day) > >And what if it's an object that has nothing to do with a string but >happens to have a split() method ?-) > >>> (snip) > >Jean-Paul, you're of course right from a theoretical POV. Practically >speaking, chances that such a method will ever be fed with a string-like >object not deriving from basestring are IMVHO *very* low. While I >usually raise a big warning flag when I spot a test against >isinstance(), I'd say this is an example of the few cases where it's ok. > YMMV of course... http://mail.python.org/pipermail/python-dev/2005-February/051717.html Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Boost Python properties/getter functions for strings
I forgot to mention, getname is defined as: const std::string &Entity::getName() const; -- http://mail.python.org/mailman/listinfo/python-list
check if files are the same on Windows
A crude way to check if two files are the same on Windows is to look at the output of the "fc" function of cmd.exe, for example def files_same(f1,f2): cmnd= "fc " + f1 + " " + f2 return ("no differences" in popen(cmnd).read()) This is needlessly slow, because one can stop comparing two files after the first difference is detected. How should one check that files are the same in Python? The files are plain text. -- http://mail.python.org/mailman/listinfo/python-list
Re: check if files are the same on Windows
In <[EMAIL PROTECTED]>, Beliavsky wrote: > […] How should one check that files are the same in Python? The files > are plain text. Take a look at the `filecmp` module. Pay attention to the shallow argument of `filecmp.cmp()` and the default value! Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Embedding and undefined symbols
I am embedding python into a linux shared library (let's call it libembedpy.so). The main application loads this shared library dynamically using libdl and is not linked against libembedpy.so Under this scenerio, I get ImportErrors when I try import modules: File "test.py", line 3, in ? import time ImportError: /usr/lib64/python2.4/lib-dynload/timemodule.so: undefined symbol: PyExc_ValueError By building a simple test case, I can make this error go away if the main application links against the shared library libembedpy.so. For the real case, however, I do not have access to the source, so I cannot relink it. Any ideas of how to get rid of this problem? Thanks, Lane -- http://mail.python.org/mailman/listinfo/python-list
Re: When is List Comprehension inappropriate?
On 19 Mar 2007 07:41:59 -0700, Ben <[EMAIL PROTECTED]> wrote: > I have recently learned how list comprehension works and am finding it > extremely cool. I am worried, however, that I may be stuffing it into > places that it does not belong. > > What's the most "pythony" way to do this: > > even = [] > for x in range(0,width,2): > for y in range(0,height,2): > color = im.getpixel((x,y)) > even.append(((x,y), color)) > > versus list comprehension: > > even2 = [((x,y), im.getpixel((x,y))) for x in range(0,width,2) for y > in range(0,height,2)] I would definitely not use list comprehension in this case. While they may be faster, Psyco is great here. Also, if you have lots of 2d-loops like "for x in something: for y in something:", then it could be more beautiful to separate the iteration from the task: def iterimage(im, width, height, step = 1): for y in range(0, height, step): for x in range(0, width, step): yield (x, y), im.getpixel((x, y)) Then the list comprehension becomes a little more manageable: even2 = [(pos, col) for pos, col in iterimage(im, width, height, 2)] Although this must definitely be the slowest of all the different approaches. -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
tracking memory usage
Sort of two questions here: The first is about the internal view: are there Python introspection functions that can be called such that a running script can keep tabs on how much memory is being used? And the second is about using either os or system calls on Windows such that a Python script could get similar information about other processes (i.e., external)? Thanks, -ej -- http://mail.python.org/mailman/listinfo/python-list
SQLObject 0.7.4
Hello! I'm pleased to announce the 0.7.4 release of SQLObject. What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and Firebird. It also has newly added support for Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject == Site: http://sqlobject.org Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.7.4 News and changes: http://sqlobject.org/docs/News.html What's New == News since 0.7.3 * Documentation updates Small Features -- * For MySQLdb 1.2.2+ call ping(True) on the connection to allow autoreconnect after a timeout. Bug Fixes - * Another round of changes to create/drop the tables in the right order in the command-line client `sqlobject-admin`. * Fixed a bug in UnicodeField - allow comparison with None. For a more complete list, please see the news: http://sqlobject.org/docs/News.html Oleg. -- Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. -- http://mail.python.org/mailman/listinfo/python-list
Re: List to string
On Mar 19, 8:11 am, Bruno Desthuilliers wrote: > Hitesh a écrit : > > > On Mar 18, 12:28 am, "Hitesh" <[EMAIL PROTECTED]> wrote: > >> Hi, > > >> I've a list like this.. > >> str1 = ['this is a test string inside list'] > > >> I am doing it this way. > > >> for s in str1: > >> temp_s = s > >> print temp_s > > Why this useless temp_s var ? > > > > >> Any better suggestions? > > >> Thank you, > >> hj > > > I want to cast value of a list into string.. > > There's no "cast" in Python. It would make no sens in a dynamically > typed language, where type informations belong to the LHS of a binding, > not the RHS. > > I guess that what you want is to build a string out of a list of > strings. If so, the answer is (assuming you want a newline between each > element of the list): > > print "\n".join(str1) Thank you guys. Yes that helped. :) hj -- http://mail.python.org/mailman/listinfo/python-list
Re: Boost Python properties/getter functions for strings
On Mar 19, 12:00 pm, "Shawn McGrath" <[EMAIL PROTECTED]> wrote: > I forgot to mention, getname is defined as: > const std::string &Entity::getName() const; After more reading I found the copy_const_reference, and replaced: boost::python::return_internal_reference<>()); with: boost::python::return_value_policy()); and it fixed my problem. Is there any downside to using copy_const_reference over return_internal_reference? Thanks, Shawn. -- http://mail.python.org/mailman/listinfo/python-list
Re: Boost Python properties/getter functions for strings
On 19 Mar, 16:40, "Shawn McGrath" <[EMAIL PROTECTED]> wrote: > On Mar 19, 12:00 pm, "Shawn McGrath" <[EMAIL PROTECTED]> wrote: > > > I forgot to mention, getname is defined as: > > const std::string &Entity::getName() const; > > After more reading I found the copy_const_reference, and replaced: > boost::python::return_internal_reference<>()); > with: > > boost::python::return_value_policy()); > > and it fixed my problem. Is there any downside to using > copy_const_reference over return_internal_reference? You might get some answers here; if not, can I suggest http://mail.python.org/mailman/listinfo/c++-sig ? I think a lot of the Boost.Python developers hang around on that list. hth, Jon. -- http://mail.python.org/mailman/listinfo/python-list
Re: check if files are the same on Windows
In the unix world, 'fc' would be like diff. """ Python example of checksumming files with the MD5 module. In Python 2.5, the hashlib module would be preferable/more elegant. """ import md5 import string, os r = lambda f: open(f, "r").read() def readfile(f,strip=False): return (strip and stripper(r(f))) or r(f) def writefile(f, data, perms=750): open(f, "w").write(data) and os.chmod(f, perms) def get_md5(fname): hash = md5.new() contents = readfile(fname) hash.update(contents) value = hash.digest() return (fname, hash.hexdigest()) import glob for f in glob.glob('*'): print get_md5(f) A crude way to check if two files are the same on Windows is to look at the output of the "fc" function of cmd.exe, for example def files_same(f1,f2): cmnd= "fc " + f1 + " " + f2 return ("no differences" in popen(cmnd).read()) This is needlessly slow, because one can stop comparing two files after the first difference is detected. How should one check that files are the same in Python? The files are plain text. -- Shane Geiger IT Director National Council on Economic Education [EMAIL PROTECTED] | 402-438-8958 | http://www.ncee.net Leading the Campaign for Economic and Financial Literacy begin:vcard fn:Shane Geiger n:Geiger;Shane org:National Council on Economic Education (NCEE) adr:Suite 215;;201 N. 8th Street;Lincoln;NE;68508;United States email;internet:[EMAIL PROTECTED] title:IT Director tel;work:402-438-8958 x-mozilla-html:FALSE url:http://www.ncee.net version:2.1 end:vcard -- http://mail.python.org/mailman/listinfo/python-list
Re: * operator--as in *args?
On Mar 18, 7:52 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > def f(*args, **kw): > > ... print "args",args > ... print "kw",kw > ...>>> d = {"a":1, "b":2, "c":3} > >>> f(**d) > Whoa! **? And applied to a function parameter? Back to the drawing board. On Mar 18, 7:21 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > More generally, with any iterable x, the *x > construct in function call will pass as positional arguments exactly > those items which (e.g.) would be printed by the loop: > for item in x: print x > Thanks. On Mar 18, 7:52 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > def f(*args, **kw): > > ... print "args",args > ... print "kw",kw > ...>>> d = {"a":1, "b":2, "c":3} > >>> f(**d) > Whoa! **? And applied to a function parameter name? Back to the drawing board. The following is what I discovered for anyone else that is interested: More on Defining Functions(GvR tutorial, section 4.7) --Keyword Argument Lists --Arbitrary Argument Lists --Unpacking Argument Lists 1) Applying ** to a function parameter: def g(a, b, **xtraArgs): print xtraArgs g(b=20, c="big", a="hello", d=10) #output: {'c': 'big', 'd': 10} **xtraArgs will be a dictionary of all arguments sent to the function with the syntax "keyword=value" if the keyword does not match any of the function parameter names. 2)Applying * to a function parameter: def g(a, *xtraArgs): print xtraArgs g(10, 20, 30, 40) #output: (20, 30, 40) *xtraArgs will be a tuple containing all arguments sent to the function with the syntax "value" that do not match any function parameter. 3) A function parameter with the syntax *xtraArgs1 must come before a function parameter with the syntax **xtraArgs2: def g(a, b, *xtraArgs1, **xtraArgs2): print xtraArgs1 print xtraArgs2 g(10, 20, 30, 35, d=40, e="hello") #(30, 35) #{'e': 'hello', 'd': 40} 4) Using * to unpack a list, tuple, etc.(any iterable collection--see earlier posts): def g(a, b, c): print a,b,c tpl = (1, 2, 3) g(*tpl) #output: 1 2 3 5) Using ** to unpack dictionaries: def g(a, b, c): print a,b,c dict = {"b":"world", "c":"goodbye", "a":"hello"} g(**dict) #output: hello world goodbye -- http://mail.python.org/mailman/listinfo/python-list
SQLObject 0.8.1
Hello! I'm pleased to announce the 0.8.1 release of SQLObject. What is SQLObject = SQLObject is an object-relational mapper. Your database tables are described as classes, and rows are instances of those classes. SQLObject is meant to be easy to use and quick to get started with. SQLObject supports a number of backends: MySQL, PostgreSQL, SQLite, and Firebird. It also has newly added support for Sybase, MSSQL and MaxDB (also known as SAPDB). Where is SQLObject == Site: http://sqlobject.org Development: http://sqlobject.org/devel/ Mailing list: https://lists.sourceforge.net/mailman/listinfo/sqlobject-discuss Archives: http://news.gmane.org/gmane.comp.python.sqlobject Download: http://cheeseshop.python.org/pypi/SQLObject/0.8.1 News and changes: http://sqlobject.org/News.html What's New == News since 0.8.0 * Documentation updates Small Features -- * For MySQLdb 1.2.2+ call ping(True) on the connection to allow autoreconnect after a timeout. Bug Fixes - * Another round of changes to create/drop the tables in the right order in the command-line client `sqlobject-admin`. * Fixed a bug in UnicodeField - allow comparison with None. * ID columns are reverted back from INT UNSIGNED to INT for MySQL to be in accord with FOREIGN KEYs. * Fixed return value from Firebird/MaxdbConnection.createTable(). * Fixed and simplified DatabaseIndex.get(). * Fixed ConnectionHub.doInTransaction() - close low-level connection on commit() to prevent connections leaking. For a more complete list, please see the news: http://sqlobject.org/News.html Oleg. -- Oleg Broytmannhttp://phd.pp.ru/[EMAIL PROTECTED] Programmers don't die, they just GOSUB without RETURN. -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation for "str()" could use some adjustment - Unicode issue
Daniel Nogradi wrote: >> The Python documentation for "str" says >> "str([object]) : >> Return a string containing a nicely printable representation of an >> object." >> >> However, there's no mention of the fact that "str" of a Unicode string >> with non-ASCII characters will raise a conversion exception. The >> documentation (and several Python books) seem to indicate that "str" will >> produce some "printable representation" for anything, not raise an >> exception. >> >> I know, it was proposed in PEP 349 to change "str" to return Unicode >> strings, and that's coming someday, along with all-Unicode Python, >> but meanwhile, the documentation should be clear about this. > > > Hi John, I'm not at all an expert around here but my understanding of > the workflow is that bug reports should be submitted to the tracker at > sourceforge. There is no guarantee that they will be noticed there but > the chances there are much higher than for a message on the mailing > list. I just mention this because I've seen your mysqld, urllib and > other potentially important bug reports here with no action taken but > maybe submitting them to sourceforge would attract some developers. More people read the mailing list than the bug reports, and Google indexes it, so it puts the problem on record. If this problem were reported as a bug, there'd be denial that it was a problem, on the grounds that it will be fixed in a future version of Python. This was addressed in PEP 349 (status "Deferred"), so it's a known problem that's being ignored. Python strings are in transition; in ASCII-only Python, "str" could never raise a conversion exception, and when we get to Unicode-only strings, "str" will never raise a conversion exception. But right now, "str" can definitely raise an exception. The real problem is the published books on Python: "Learning Python", by Lutz and Ascher: "str(string) -- returns the string representation of any object." "Python in a Nutshell", by Martelli Doesn't really address the issue, but says that "print" calls "str" for conversions. Neither of these mentions that "str" is ASCII-only. I think that you can use "unicode()" on any object on which you can use "str()", but I'm not sure that's official. Incidentally, is "repr" ASCII-only, or does it understand Unicode? And what happens if the __str__() method of an object returns Unicode? John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
Bruno Desthuilliers wrote: > Diez B. Roggisch a écrit : >> momobear schrieb: >>> hi, I am puzzled about how to determine whether an object is >>> initilized in one class, anyone could give me any instructions? >>> here is an example code: >>> >>> class coffee: >>> def boil(self): >>>self.temp = 80 >>> >>> a = coffer() >>> if a.temp > 60: >>> print "it's boiled" >>> >>> in C++ language we must initilized a variable first, so there is no >>> such problem, but in python if we don't invoke a.boil(), we will not >>> get self.temp to be initilized, any way to determine if it's initilzed >>> before self.temp be used. >> You want boil to be called __init__, which is python's constructor name. > > > Actually, __init__ is the initializer. The proper constructor is __new__. > > Actually you would have to ensure that the class's metaclass was for that to be true. Classic classes don't *have* a __new__ method. And of course the real answer is that the __init__ method should set a default value (modulo the sneaky use of class attributes) for any attributes that might be accessed before other methods get a chance to set them. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: class objects, method objects, function objects
Hi, Thanks for the responses. I understand that python automatically sends 'self' to a member function, i.e. self gets prepended to the argument list. I guess I am having trouble with this statement: When the method object is called with an argument list, it is unpacked again, a new argument list is constructed from the instance object and the original argument list, and the function object is called with this new argument list. --- because I don't quite understand the timing. The "unpacked again" part confuses me. If I have this code: class MyClass: def g(self, name): print "Hello " + name x = MyClass() x.g("GvR") here is what happens when I try to follow the sequence of events GvR describes: When an instance attribute is referenced that isn't a data attribute, its class is searched. x.g("GvR") ==> 'g' is not a data attribute, so class is searched. If the name denotes a valid class attribute that is a function object, a method object is created by packing (pointers to) the instance object and the function object just found together in an abstract object: this is the method object. ==>method object is created When the method object is called with an argument list, x.g("GvR") ==> I think I'm both "referencing an instance attribute" and calling the method object with an argument list it(the method object) is unpacked again, a new argument list is constructed from the instance object and the original argument list, and the function object is called with this new argument list. ?? -- http://mail.python.org/mailman/listinfo/python-list
PythonCard or Dabo?
I'm curious to know what others think of these two frameworks for building wxPython apps. PythonCard has been around longer, but its development seems to have slowed. The last release, 0.8.2, has been out for quite awhile now. Dabo is newer and seems to have gathered a lot of buzz. Anyone try both? What's your preference and why? Is one more robust than the other? -- Kevin Walzer Code by Kevin http://www.codebykevin.com -- http://mail.python.org/mailman/listinfo/python-list
[ANNOUNCE] Boxtream v0.991 is out
Hi there, I'm pleased to announce the immediate availability of Boxtream v0.991 Boxtream is a mobile audio/video recording and streaming studio, made from a set of optional hardware bricks and of a Python written, GNU GPLed, GStreamer based software. The software part can be used without most of the hardware, although having hardware similar to the one used will offer more options (support for Extron and soon Kramer A/V switchers, for example). The Boxtream software is made of an headless encoding backend which publishes its API over XML-RPC, and from a GUI frontend made with wxPython. Boxtream is mostly used to record and stream compressed video of live events like congresses, presentations, courses and so on, with or without synchronized slides, while at the same time saving the original audio and video sources in the native DV format, allowing postprocessing with any tool of your choice. Five encoding schemes are currently available, each in a set of framerates, sizes, audio frequency,or number of audio channels, but adding new schemes is easy, and will become even easier in future releases. More details, screenshot, and download from the following (temporary) website : http://cortex.unice.fr/~jerome/boxtream/ Please report bugs or send comments to : [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: check if files are the same on Windows
On Mar 19, 11:55 am, Shane Geiger <[EMAIL PROTECTED]> wrote: > In the unix world, 'fc' would be like diff. > > """ > Python example of checksumming files with the MD5 module. > > In Python 2.5, the hashlib module would be preferable/more elegant. > """ > > import md5 > > import string, os > r = lambda f: open(f, "r").read() > def readfile(f,strip=False): return (strip and stripper(r(f))) or r(f) > def writefile(f, data, perms=750): open(f, "w").write(data) and > os.chmod(f, perms) > > def get_md5(fname): > hash = md5.new() > contents = readfile(fname) > hash.update(contents) > value = hash.digest() > return (fname, hash.hexdigest()) > > import glob > > for f in glob.glob('*'): > print get_md5(f) > > > A crude way to check if two files are the same on Windows is to look > > at the output of the "fc" function of cmd.exe, for example > > > def files_same(f1,f2): > > cmnd= "fc " + f1 + " " + f2 > > return ("no differences" in popen(cmnd).read()) > > > This is needlessly slow, because one can stop comparing two files > > after the first difference is detected. How should one check that > > files are the same in Python? The files are plain text. > > -- > Shane Geiger > IT Director > National Council on Economic Education > [EMAIL PROTECTED] | 402-438-8958 | http://www.ncee.net > > Leading the Campaign for Economic and Financial Literacy > > sgeiger.vcf > 1KDownload You can also use Python's file "read" method to read a block of each file in a loop in binary mode. Something like: file1 = open(path1, 'rb') file2 = open(path2, 'rb') bytes1 = file1.read(blocksize) bytes2 = file2.read(blocksize) And then just compare bytes to see if there is a difference. If so, break out of the loop. I saw this concept in the book: Python Programming, 3rd Ed. by Lutz. Have fun! Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard or Dabo?
On Mar 19, 12:24 pm, Kevin Walzer <[EMAIL PROTECTED]> wrote: > I'm curious to know what others think of these two frameworks for > building wxPython apps. > > PythonCard has been around longer, but its development seems to have > slowed. The last release, 0.8.2, has been out for quite awhile now. > > Dabo is newer and seems to have gathered a lot of buzz. > > Anyone try both? What's your preference and why? Is one more robust than > the other? > > -- > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com You might want to submit this to the wxpython news-group. They'll have a lot more on-target responses and I've noticed that some of the Dabo creators regularly contribute to that mailing list. Personally, I haven't had much luck with either. Dabo has great tutorials on their website, but for some reason, I can't get it to run on my PC. PythonCard, on the other hand, is just not intuitive for me. I am currently experimenting with XRC. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: 911 was a RACIST crime by YANK BASTARDS against all other NATIONS Re: *POLL* How many sheeple believe in the 911 fairy tale and willing to accept an Orwellian doublespeak and enslavement world ?
On Mar 19, 12:42 am, "Don Stockbauer" <[EMAIL PROTECTED]> wrote: > 911's primary utility was that, inadvertently, it sparked off the > formation of the global brain: > > The Social Superorganism and its Global Brain > > http://pespmc1.vub.ac.be/SUPORGLI.html > > Have a nice Monday, all. > > - Don Hey YANK MOTHERFUCKER, why didnt you bark this chime on that day when the BUSH bastards were talking of war and murder ... Typical genocidal and selfish yank bastard attitude ... heads I win, tail you lose. Thats why every country needs to have NUCLEAR WEAPONS TO DEFEND THEIR HONOR, WEALTH AND LAND FROM THE GRDY YANK BASTARDS. Venezuela, Bolivia, Cuba, Saudi Arabia, Iran, Malaysia, DPRK all need long range anti-satellite missiles, ICBMs to defend against Yank Bastards. The GENOCIDAL anglo-saxon race has occupied TWO continents of North America and Australia and murdered the native population COMPLETELY -- http://mail.python.org/mailman/listinfo/python-list
Re: 911 was a RACIST crime by YANK BASTARDS against all other NATIONS Re: *POLL* How many sheeple believe in the 911 fairy tale and willing to accept an Orwellian doublespeak and enslavement world ?
On 19 mar, 19:47, [EMAIL PROTECTED] wrote: > On Mar 19, 12:42 am, "Don Stockbauer" <[EMAIL PROTECTED]> > wrote: > > > 911's primary utility was that, inadvertently, it sparked off the > > formation of the global brain: > > > The Social Superorganism and its Global Brain > > >http://pespmc1.vub.ac.be/SUPORGLI.html > > > Have a nice Monday, all. > > > - Don > > Hey YANK MOTHERFUCKER, why didnt you bark this chime on that day when > the BUSH bastards were talking of war and murder ... > > Typical genocidal and selfish yank bastard attitude ... heads I win, > tail you lose. > > Thats why every country needs to have NUCLEAR WEAPONS TO DEFEND THEIR > HONOR, WEALTH AND LAND FROM THE GRDY YANK BASTARDS. > > Venezuela, Bolivia, Cuba, Saudi Arabia, Iran, Malaysia, DPRK all need > long range anti-satellite missiles, ICBMs to defend against Yank > Bastards. > > The GENOCIDAL anglo-saxon race has occupied TWO continents of North > America and Australia and murdered the native population > COMPLETELY ** As long as you continue taking it easily and with calm, dearwe all love you. Tonio Pd. Why didn't you include Micronesia in your list of countries needing ICBM's?? So rude of you. -- http://mail.python.org/mailman/listinfo/python-list
pyosd question
Small script used to work, by last week I noticed that it simply hangs up. Can someone run this code on his own python and tell me about results? Help me please. import time import pyosd import re default_font="-adobe-helvetica-medium-r-*-*-24-*" interval = 2 temp_led_number = pyosd.osd(default_font, colour='#038b06', timeout=1,pos=pyosd.POS_BOT,offset=40,shadow=1,align=pyosd.ALIGN_CENTER) def display(): # Here it will stay forever temp_led_number.display('123', pyosd.TYPE_STRING) # Never reach this line :( print "Yeah!" while 1: display() time.sleep(interval) -- Sincerely, Eugene Antimirov PortaOne, Inc., SIP Engineer [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard thoughts
king kikapu wrote: >> I don't know much about PythonCard or wxGlade, but I use wxPython (which >> wxGlade uses, right?) and you now have the option to separate your GUI >> and code using an XRC file (xml file that describes layout). So perhaps >> this is something you can do with wxGlade, but at the same time it might >> still create the problem you describe above. However, it's very to have >> your Python files contain just logic. > > Yes, both products (PythonCard and wxGlade) uses wxPython. It's just > that PythonCard is sitting on top of wxPython and it intercepts the > events generated. Then it search for an appropriate declared function > on your code and call it (all this happens at runtime). > It shield us from much of the boilerplate code that gui toolkits > require and in the case that you need to address directly wxPython, > you just can! > > I discovered that when you run your designed GUI from PythonCard's > layoutEditor, you have the ability to define a command line option > that is called > "Message Watcher". This, will show you the names of the actual events > that you have to write code for, so you, at least for this, do not > have > to dig the docs for their names. Pretty good! > The only real problem is that PythonCard appears to have run out of development steam. I don't think there's been much^H^H^H^H any work on it in the past year or two. This is a shame, as it showed considerable promise. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: tracking memory usage
On Mar 19, 11:34 am, "Erik Johnson" <[EMAIL PROTECTED]> wrote: > Sort of two questions here: > > The first is about the internal view: are there Python introspection > functions that can be called such that a running script can keep tabs on how > much memory is being used? > > And the second is about using either os or system calls on Windows such > that a Python script could get similar information about other processes > (i.e., external)? > > Thanks, > -ej >From what I've found, it would seem that this is in development. See the following: http://svn.python.org/projects/python/branches/bcannon-sandboxing/PEP.txt I also found a cool recipe for doing some of what you want, but it's only been tested on Linux. You might be able to modify it for your needs, if you don't mind delving into process ids: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/286222 Good luck! Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard or Dabo?
Kevin Walzer wrote: > I'm curious to know what others think of these two frameworks for > building wxPython apps. > > PythonCard has been around longer, but its development seems to have > slowed. The last release, 0.8.2, has been out for quite awhile now. > > Dabo is newer and seems to have gathered a lot of buzz. > > Anyone try both? What's your preference and why? Is one more robust than > the other? > It's not just a matter of robustness. PythonCard is limited to GUI development, while Dabo is a fully-fledged application architecture intended to allow you to build complete suites. So not only does it have a superior GUI editor, it also has report development facilities and many other features that simply weren't envisaged for PythonCard. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Recent Ramblings http://holdenweb.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard or Dabo?
Kevin Walzer <[EMAIL PROTECTED]> writes: > I'm curious to know what others think of these two frameworks for > building wxPython apps. > > PythonCard has been around longer, but its development seems to have > slowed. The last release, 0.8.2, has been out for quite awhile now. > > Dabo is newer and seems to have gathered a lot of buzz. > > Anyone try both? What's your preference and why? Is one more robust > than the other? > Incidentally, there's also boa constructor, which at least has the best name of the three :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Renaming or Overloading In Python
On Mar 18, 4:57 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: > gamename <[EMAIL PROTECTED]> wrote: > > Hi, > > > I'm a recent convert from TCL. One of the more powerful aspects of > > TCL is the ability to rename a function at will (generally for testing > > purposes). > > > Example from the tcl doc: > > > rename ::source ::theRealSource > > set sourceCount 0 > > proc ::source args { > > global sourceCount > > puts "called source for the [incr sourceCount]'th time" > > uplevel 1 ::theRealSource $args > > } > > > So, is such a thing possible in Python? > > Assuming that source is a function previously defined in this scope, the > exactly equivalent Python snippet should be: > > theRealSource = source > sourceCount = 0 > def source(*args): > global sourceCount > sourceCount += 1 > print "called source for the %s'th time" % sourceCount > return theRealSource(*args) > > Others have already offered you other alternatives, but I thought you > might also be interested in a more direct/immediate translation. > > Alex Excellent! Thanks guys, that really gives me a place to start. -T -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard or Dabo?
On Mar 19, 10:24 am, Kevin Walzer <[EMAIL PROTECTED]> wrote: > I'm curious to know what others think of these two frameworks for > building wxPython apps. > > PythonCard has been around longer, but its development seems to have > slowed. The last release, 0.8.2, has been out for quite awhile now. > > Dabo is newer and seems to have gathered a lot of buzz. > > Anyone try both? What's your preference and why? Is one more robust than > the other? > > -- > Kevin Walzer > Code by Kevinhttp://www.codebykevin.com It all depends on what your needs are. I agree with Steve's comment that the two packages has somewhat of a different application in mind. If you need a working GUI application working *really* quick, I highly recommend Pythoncard - but if you need anything else, you might look at other packages. You might not see lots of development activities with Pythoncard but sometimes not being the breeding edge has its place. -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard thoughts
On Mar 19, 5:08 am, "king kikapu" <[EMAIL PROTECTED]> wrote: > Hi to all folks here, > > i downloaded and "playing" with PythonCard and i just want to share my > thoughts so maybe we can discuss a little about it. > I was used to wxGlade before and i think PythonCard is even better. > I like the separate implementation of GUI and Code that PythonCard > provides, i also like the "binding system" so you can bind functions > to events and have them executed at runtime. > I also like that it does not force you to use sizers and all that > stuff and that you can freely place your components on the form and > set their exact position just with the mouse. > > The only "problem" i see with this design is that by that separation > of Gui/Code, you loose the intellisense that (ex. PyDev) some editors/ > plugins can provide because in the .py file nothing is indicating > that , for example, the btnDoWork is a Button object. > This force you to remember many properties and switch back and forth > between your code and the wxPython help file. This is not the case for > wxGlade because all boilerplate code is in the same file (for good and > for bad) and PyDev (and others too) can "understand" for which kind of > objects we are talking about and so can display -and thus help us- > with their properties. > > Apart from that, everything else is great. > > Any opinions/suggestion on all this ? (If I understand your question correctly) There is no restirction on what you call your objects. For instance, I do call all of my buttons btnSomeThing, and so forth. If you use the codeEditor that comes with Pythoncard, you can easily see which method goes with what control. (And yes, I wish there are more developers drawn to Pythoncard too - it's such a nice package). -- http://mail.python.org/mailman/listinfo/python-list
Load three different modules which have the same name
I have the following directory structure setup... c:\alpha\Person.py -- class Person(IPerson): def __init__(self): print "Alpha person here" c:\beta\Person.py -- class Person(IPerson): def __init__(self): print "Beta person here" c:\gamma\Person.py -- class Person(IPerson): def __init__(self): print "Gamma person here" c:\ok\playground.py --- def tryAllThree(): a = "c:\\alpha" b = "c:\\beta" g = "c:\\gamma" sys.path.append(a) from Person import Person alpha = Person() sys.path.remove(a) sys.path.append(b) from Person import Person beta = Person() sys.path.remove(b) sys.path.append(g) from Person import Person gamma = Person() Notice that my three different projects (alpha, beta, gamma) have a Person.py which contains a Person class. When I execute the following (on windows): c:\ok> python >>> from playground import * >>> tryAllThree() I see... Alpha person here Alpha person here Alpha person here What I want to see is Alpha person here Beta person here Gamma person here how can I get this to work? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Load three different modules which have the same name
nevermind this took care of it: import sys def tryAllThree(): a = "c:\\alpha" b = "c:\\beta" g = "c:\\gamma" sys.path.append(a) import Person alpha = Person.Person() sys.path.remove(a) sys.path.append(b) reload(Person) beta = Person.Person() sys.path.remove(b) sys.path.append(g) reload(Person) gamma = Person.Person() thanks -- http://mail.python.org/mailman/listinfo/python-list
RE: Choosing Python
glad to hear it. Those of us who would like to introduce it in reluctant schools elsewhere could benefit from a post-semester evaluation, including student comments and some sample, running projects. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of [EMAIL PROTECTED] Sent: Sunday, March 18, 2007 9:22 PM To: python-list@python.org Subject: Choosing Python The choice is made. The school where I teach has finally made its decision to teach Python first.For several years, we have been teaching Java first, and before that, C++. I introduced Python in one of my courses and got a lot of flak from some of the other faculty. I also introduced Ruby, and got even more flak. In my course, the students loved Python for its simplicity, its power, and its flexibility. It is clear that Python is not the ultimate, one-size-fits-all language. No language is. However, for a beginner's language it is nearly ideal. Further, it is a great language for a wide range of serious programming problems. For large-scale, safety-critical software, I still prefer Eiffel or Ada. Java could vanish tomorrow and, with Python and Ruby available, no one would miss Java at all. As for C++, for any serious software systems, it should always be the language of last resort. C++, as an object-oriented assembler, is pretty much its own virus. Already, students are turning in really good projects in Python, and some in Ruby. Not all the professors are on-board with this decision, but in time I think they will be. Richard Riehle -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Pycron for windows - please help
Hey all, I'm using Pycron for windows to run 5 scripts at various times of the day, all of which work well. I recently added a 6th job, a simply file copy operation, and it won't run. Once the job is configured, I click the test execution button, and it works fine. However, it won't run automatically. I looked in the pycron.log file, and I noticed that for the entires of my new job, I see "rc=4" and the end of each line. All other jobs have "rc=0" at the end of the line. I assume then, that rc=4 is a reference to an error code of some kind, but there is no information on this in the readme.txt, at the pycron website, or here in groups. Does anyone know how to troubleshhot this? Thanks in advance. Al -- http://mail.python.org/mailman/listinfo/python-list
Re: Choosing Python
On Mar 19, 1:52 pm, "Sells, Fred" <[EMAIL PROTECTED]> wrote: > glad to hear it. Those of us who would like to introduce it in reluctant > schools elsewhere could benefit from a post-semester evaluation, including > student comments and some sample, running projects. > > -Original Message- > From: [EMAIL PROTECTED] > > [mailto:[EMAIL PROTECTED] > Behalf Of [EMAIL PROTECTED] > Sent: Sunday, March 18, 2007 9:22 PM > To: [EMAIL PROTECTED] > Subject: Choosing Python > > The choice is made. The school where I teach has finally > made its decision to teach Python first.For several years, > we have been teaching Java first, and before that, C++. > > I introduced Python in one of my courses and got a lot of > flak from some of the other faculty. I also introduced Ruby, > and got even more flak. In my course, the students loved > Python for its simplicity, its power, and its flexibility. > > It is clear that Python is not the ultimate, one-size-fits-all > language. No language is. However, for a beginner's > language it is nearly ideal. Further, it is a great language > for a wide range of serious programming problems. > > For large-scale, safety-critical software, I still prefer Eiffel > or Ada. Java could vanish tomorrow and, with Python > and Ruby available, no one would miss Java at all. As for > C++, for any serious software systems, it should always be > the language of last resort. C++, as an object-oriented > assembler, is pretty much its own virus. > > Already, students are turning in really good projects in Python, > and some in Ruby. Not all the professors are on-board with > this decision, but in time I think they will be. > > Richard Riehle > > --http://mail.python.org/mailman/listinfo/python-list What would be really cool is to mix in the whole C/C++ extension paradigm...or IPython/Jython in a second semester class. That way the students could get into more real-world language mixes, which most developers have to deal with. We run COBOL, Python, PHP, and some truly awful VBA here. I wish I could have learned Python to being with, but it would have needed to have been supplemented with some of the other lower-level languages as well. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Load three different modules which have the same name
On Mon, 2007-03-19 at 11:42 -0700, abcd wrote: > nevermind this took care of it: > > import sys > > def tryAllThree(): > a = "c:\\alpha" > b = "c:\\beta" > g = "c:\\gamma" > > sys.path.append(a) > import Person > alpha = Person.Person() > > sys.path.remove(a) > sys.path.append(b) > reload(Person) > beta = Person.Person() > > sys.path.remove(b) > sys.path.append(g) > reload(Person) > gamma = Person.Person() That sort of works, but it's really unclean. I suggest you turn each directory that contains an implementation of Person into a package. That can be done by simply putting an __init__.py file into each of those directories. This __init__.py file can be empty or only contain a "pass" statement, but as long as it's there, the directory containing it becomes a package. Then, add the directory that contains your packages (C:\ in your example) to your path, and you can import and use your Person modules like this: import alpha.Person, beta.Person, gamma.Person alpha_person = alpha.Person.Person() beta_person = beta.Person.Person() gamma_person = gamma.Person.Person() The main advantages are that the different implementations of Person don't shadow each other in your name space, and you don't gratuitously force module reloads. Hope this helps, Carsten. -- http://mail.python.org/mailman/listinfo/python-list
Create TarFile using string buffers
I have a program that generates a number of files that will be packaged into a tarball. Can I stream the content into TarFile without first writing them out to the file system? All add(), addfile() and gettarinfo() seems to assume there is a file in the disk. But for me I seems inefficient to write all the content to the disk and then have it read back by the TarFile module. Thank you for your help wy -- http://mail.python.org/mailman/listinfo/python-list
Anything available that can read Microsoft .MDB files from Python?
I'm looking for something that can read .MDB files, the format Microsoft Access uses, from Python. I need to do this on Linux, without using Microsoft tools. I just need to read the files once, so I can load the tables into another database. Speed isn't an issue, and I don't need to access the file in database fashion. The files are too big to read into RAM all at once, though. I tried "MDBtools", but the only (last) release was a pre-release three years ago, and I've encountered many build problems trying to make it work on Fedora Core 6. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Boost Python properties/getter functions for strings
On Mar 19, 12:49 pm, "Jon Clements" <[EMAIL PROTECTED]> wrote: > On 19 Mar, 16:40, "Shawn McGrath" <[EMAIL PROTECTED]> wrote: > > > On Mar 19, 12:00 pm, "Shawn McGrath" <[EMAIL PROTECTED]> wrote: > > > > I forgot to mention, getname is defined as: > > > const std::string &Entity::getName() const; > > > After more reading I found the copy_const_reference, and replaced: > > boost::python::return_internal_reference<>()); > > with: > > > boost::python::return_value_policy()); > > > and it fixed my problem. Is there any downside to using > > copy_const_reference over return_internal_reference? > > You might get some answers here; if not, can I > suggesthttp://mail.python.org/mailman/listinfo/c++-sig? I think a lot of the > Boost.Python developers hang around on that list. > > hth, > > Jon. Cool thanks a lot. The problem is actually due to python's strings being immutable (I knew this, but I thought returning const std::string& would do it). return_internal_reference<> works for other pointers/references, just not strings. (I just answered it so if it gets searched later on people will find the solution) -Shawn. -- http://mail.python.org/mailman/listinfo/python-list
Re: Anything available that can read Microsoft .MDB files from Python?
John Nagle schrieb: > I'm looking for something that can read .MDB files, the format > Microsoft Access uses, from Python. I need to do this on > Linux, without using Microsoft tools. I just need to read > the files once, so I can load the tables into another database. > Speed isn't an issue, and I don't need to access the file in > database fashion. The files are too big to read into RAM all at once, > though. > > I tried "MDBtools", but the only (last) release was > a pre-release three years ago, and I've encountered > many build problems trying to make it work on Fedora > Core 6. I was just gonna suggest it. Under ubuntu, it works easy as cake, and converts the mdb nicely to some CSV-files. I think you should really try and make it work. Diez -- http://mail.python.org/mailman/listinfo/python-list
Writing files
I am writing a program that walks a directory full of mp3s reads their ID3 data (using Mutagen), this part works perfectly. The problem is I write these tags to a CSV file through the CSV module. But when I read the file the file seems to be incomplete. Further inspecting it has seemed to have stopped writing to the file at a certain point. Something in my code? a bug? System: Linux 2.4.31 (Slackware), Python 2.5c1 Any help is greatly appreciated. Adonis -- code -- def _scan(self): outFile = file("mp3.dat", "wb") outCSV = csv.writer(outFile) output = list() for root, dirs, files in os.walk(self.directory): files = [x for x in files if x.endswith(".mp3")] for aFile in sorted(files): mp3Data = MP3(os.path.join(root, aFile)) title = mp3Data.get("TIT2") output.append([root, aFile, title]) outCSV.writerows(output) output = list() -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonCard thoughts
Ο/Η John Henry έγραψε: > (If I understand your question correctly) > > There is no restirction on what you call your objects. For instance, > I do call all of my buttons btnSomeThing, and so forth. No, i surely didn't mean this! What i mean is that the creation of these components happens to NOT reside in the .py file that we are use to put our logic in, so, the various Editors/Plug-ins cannot "understand" what type is the object we refer to so they cannot provide intellisense information. Let' say for example, that we create a design in PythonCard that contains a form and just one butto named btnStart. In our .py file we want to refre to that button in a way such: self.components.btnStart At this point, if we had the code that created this button in our file, PyDev (for example) would show us the properties of btnStart because it has understood that we are using a wx.Button. This is not the case of thePython card because this creation is happened to runtime by...PythonCard! Anyway, it is not that important from keeping me from using PythonCard. Do we know more things about the developing of this product, is it active/dead or something ?? I plan to use it to create something that will take a long time to finish and i wouldn't want to find out that the product is a dead- end... -- http://mail.python.org/mailman/listinfo/python-list
Re: any ways to judge whether an object is initilized or not in a class
Steve Holden a écrit : > Bruno Desthuilliers wrote: > >> Diez B. Roggisch a écrit : >> (snip) >>> You want boil to be called __init__, which is python's constructor name. >> >> >> Actually, __init__ is the initializer. The proper constructor is __new__. >> >> > I'm not sure Diez qualifies as a "novice". And since the OP makes reference to C++, I assume he's able to grasp the difference between a constructor and an initializer. > Actually you would have to ensure that the class's metaclass was "type"> for that to be true. Classic classes don't *have* a __new__ method. Yes, true. Fact is I stopped using old-style classes some years ago, so I don't really remember what features they were missing. Thanks for the correction. -- http://mail.python.org/mailman/listinfo/python-list
Re: When is List Comprehension inappropriate?
"Ben" <[EMAIL PROTECTED]> wrote: > What's the most "pythony" way to do this: > > even = [] > for x in range(0,width,2): > for y in range(0,height,2): > color = im.getpixel((x,y)) > even.append(((x,y), color)) > > versus list comprehension: > > even2 = [((x,y), im.getpixel((x,y))) for x in range(0,width,2) for y > in range(0,height,2)] > ... > > Feel free to tell me a different way to do this, as well. > Untested code, but I would try to avoid calling getpixel: data = list(im.getdata()) width, height = im.size even = [ data[i:i+width:2] for i in range(0, width*height, 2*width)] That creates a 2 dimensional list rather than one long list, and doesn't create the x,y tuples, but since they are implied by the position in the list I don't actually see why you would want to create them at all. You can calculate them separately if you actually need them. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using pxssh
tereglow <[EMAIL PROTECTED]> wrote: > I am trying to convert some Expect/Tcl code into Python by using the > Pexpect module. The environment is such that authenticated keys are > disabled although SSH is available. I do not have control over this > environment, so I'm trying to automate tasks within it via Expect. > > I noticed that, within the Pexpect documentation, it mentions a class > called "pxssh". Has anyone used this before? If so, I'm having some > trouble importing it. If I just import pxssh doesn't seem to work; In what way doesn't it work? > really am not sure how this is related to Pexpect or how to use it > from within it. It works for me according to the documentation $ python Python 2.4.4 (#2, Jan 13 2007, 17:50:26) [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import pxssh >>> s = pxssh.pxssh() >>> s.login("localhost", "user", "password") True >>> s.sendline("ls -l") 6 >>> s.prompt() True >>> print s.before ls -l total 30944 -rw-r--r-- 1 user user 936 Nov 3 14:52 #z.c# [snip] -rw-r--r-- 1 user user 221 Jan 30 11:51 z~ >>> s.logout() >>> I'm using the debian packaged version 2.1-1 with python 2.4 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Private data
Dustan a écrit : > http://dustangroups.googlepages.com/privateattributesinpython > May I report a small typo ? """ def interanalDataDecorator(func): """ Talking about private attributes... !-) -- http://mail.python.org/mailman/listinfo/python-list