Re: changing local namespace of a function

2005-02-05 Thread Bo Peng
Kent Johnson wrote: You can part way there using keyword arguments. You just have to use dictionary syntax for changing values in the dictionary: >>> def f(d, x=None, y=None): ... d['z'] = x + y ... >>> a = {'x':1, 'y':2} >>> b = {'x':3, 'y':3} >>> >>> f(a, **a) >>> a {'y': 2, 'x': 1, '

RE: Python Processes for Win32

2005-02-05 Thread Robert Brewer
[EMAIL PROTECTED] wrote: > I have a daemon type script (daemon.py -- we'll say) that I would like > to have run continuously. I'd like to be able to do something like > this: > > daemon.py start > > ... and then to have it stop I'd like to do this: > > daemon.py stop > > I am having a hard time

Re: variable declaration

2005-02-05 Thread Arthur
On Sat, 5 Feb 2005 20:02:44 +0100, [EMAIL PROTECTED] (Alex Martelli) wrote: >Arthur <[EMAIL PROTECTED]> wrote: > >> On Sat, 5 Feb 2005 17:00:15 +0100, [EMAIL PROTECTED] (Alex Martelli) >> wrote: >> > >> >I consider this one of the worst ideas to have been proposed on this >> >newsgroup over the ye

Re: changing local namespace of a function

2005-02-05 Thread Bo Peng
Exec is slow since compiling the string and calls to globals() use a lot of time. The last one is most elegant but __getattr__ and __setattr__ are costly. The 'evil hack' solution is good since accessing x and y takes no additional time. Previous comparison was not completely fair since I could

Re: empty classes as c structs?

2005-02-05 Thread Carlos Ribeiro
On Sat, 05 Feb 2005 12:05:13 -0700, Steven Bethard <[EMAIL PROTECTED]> wrote: > The type suggested in this PEP also allows a simple means of > representing hierarchical data that allows attribute-style access:: > > >>> x = Bunch(spam=Bunch(rabbit=1, badger=[2, 3, 4]), ham='neewom') > >>>

Re: empty classes as c structs?

2005-02-05 Thread Carlos Ribeiro
On Sat, 05 Feb 2005 15:59:00 -0500, Brian van den Broek <[EMAIL PROTECTED]> wrote: > (I'm just a hobbyist, so if this suggestion clashes with some well > established use of 'Bag' in CS terminology, well, never mind.) There's already a well know know use for the 'bag' name, including a recipe in Py

Re: How to read POSTed data

2005-02-05 Thread Dan Perl
"Håkan Persson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi. > > I am trying to set up a simple HTTP-server but I have problems reading > data that is beeing POSTed. > > class httpServer(BaseHTTPServer.BaseHTTPRequestHandler): >def do_POST(self): >input = self.rf

pickle/marshal internal format 'life expectancy'/backward compatibility

2005-02-05 Thread Philippe C. Martin
Hi, I am looking into using the pickle format to store object/complex data structures into a smart card as it would make the design of the embedded application very simple. Yet the card might have to stay in the pocket of the customer for a few years, during which the back office application res

How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Arvid Andersson
Hello, I need to convert a string to a number, but the string can contain +,-,* and / as well as parenthesis. For example, if I have the string "30/(6+9)" I would like a function that returned the number 2. I actually wrote a java function that did this a couple of years ago, in school, as an e

Re: pickle/marshal internal format 'life expectancy'/backward compatibility

2005-02-05 Thread Tim Peters
[Philippe C. Martin] > I am looking into using the pickle format to store object/complex data > structures into a smart card as it would make the design of the embedded > application very simple. > > Yet the card might have to stay in the pocket of the customer for a few > years, during which the b

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Michael Hartl
Use the eval function: >>> eval("30/(6+9)") 2 Michael -- http://mail.python.org/mailman/listinfo/python-list

CGI POST problem was: How to read POSTed data

2005-02-05 Thread Dan Perl
I am piggybacking on Hakan's original posting because I am addressing the same group of people (those with good knowledge in the standard web programming modules), on a related topic. However, my question is independent of Hakan's. I have trouble getting a simple CGI script to work because it

Re: sos!

2005-02-05 Thread Dan Perl
"jordan2856977" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > hellow everybody! I'm from china. I'm a beginner of python. in china, > python is not a fashionable language, so it's difficult to find some > books about python. finally,I find a book named "python how to > program" wr

Re: empty classes as c structs?

2005-02-05 Thread Brian van den Broek
Carlos Ribeiro said unto the world upon 2005-02-05 16:35: On Sat, 05 Feb 2005 15:59:00 -0500, Brian van den Broek <[EMAIL PROTECTED]> wrote: (I'm just a hobbyist, so if this suggestion clashes with some well established use of 'Bag' in CS terminology, well, never mind.) There's already a well know

Re: Computing class variable on demand?

2005-02-05 Thread fortepianissimo
Thanks Steve - actually my question was simpler than that. I just wanted to use Daniels' recipe of lazy initialization on objects with __slots__: class Lazy(object): def __init__(self, calculate_function): self._calculate = calculate_function def __get__(self, obj, _=None):

Re: sos!

2005-02-05 Thread [EMAIL PROTECTED]
Dan Perl wrote: > "jordan2856977" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > hellow everybody! I'm from china. I'm a beginner of python. in china, > > python is not a fashionable language, so it's difficult to find some > > books about python. finally,I find a book named "py

Insane import behaviour and regrtest.py: heeelp

2005-02-05 Thread John J. Lee
I'm tearing my hair out at what seems like weird import behaviour I'm getting from Python's stdlib test script, regrtest.py (not for the first time: seem to have forgotten the resolution from last time, and the time before, and the time before that, when this damn test script of Python's had me scr

Re: [EVALUATION] - E01: The Java Failure - May Python Helps?

2005-02-05 Thread Terry Reedy
"Ilias Lazaridis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] If you ask too much that other people do your searching for you, answers will dry up. But here are a couple that you might not find on google anyway, at least not easily. > I want to add metadata to everything with

Re: sos!

2005-02-05 Thread Dan Perl
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Dan Perl wrote: >> [...] > Aren't you in the wrong newsgroup? :-) Aren't you funny? -- http://mail.python.org/mailman/listinfo/python-list

Re: IPython colors in windows

2005-02-05 Thread Claudio Grondi
"Ashot" <[EMAIL PROTECTED]> schrieb im Newsbeitrag news:[EMAIL PROTECTED] > whoa, that was quick, looks like it works for me. Thanks a lot! > It would be nice to be able to set the colors in the prefs file, although > its possible to edit the pyColorize file as Claudio mentioned. To get the colour

Re: How do I enter/receive webpage information?

2005-02-05 Thread John J. Lee
Jorgen Grahn <[EMAIL PROTECTED]> writes: [...] > I did it this way successfully once ... it's probably the wrong approach in > some ways, but It Works For Me. > > - used httplib.HTTPConnection for the HTTP parts, building my own requests > with headers and all, calling h.send() and h.getrespons

Re: How do I enter/receive webpage information?

2005-02-05 Thread John J. Lee
Jorgen Grahn <[EMAIL PROTECTED]> writes: [...] > - subclassed sgmllib.SGMLParser once for each kind of page I expected to > receive. This class knew how to pull the information from a HTML document, > provided it looked as I expected it to. Very tedious work. It can be easier > and safer to

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Arvid Andersson
On Sat, Feb 05, 2005 at 02:11:07PM -0800, Michael Hartl wrote: > Use the eval function: > > >>> eval("30/(6+9)") > 2 > Thanks, just what I was looking for! -- http://mail.python.org/mailman/listinfo/python-list

Re: Computing class variable on demand?

2005-02-05 Thread Steven Bethard
fortepianissimo wrote: Thanks Steve - actually my question was simpler than that. I just wanted to use Daniels' recipe of lazy initialization on objects with __slots__: class Lazy(object): def __init__(self, calculate_function): self._calculate = calculate_function def __get__(self,

Re: "Collapsing" a list into a list of changes

2005-02-05 Thread Steven Bethard
Alex Martelli wrote: Steven Bethard <[EMAIL PROTECTED]> wrote: Here's a solution that works for iterables other than lists: py> def collapse(iterable): ... enumeration = enumerate(iterable) ... _, lastitem = enumeration.next() ... yield lastitem ... for i, item in enumeration: ...

Re: IPython colors in windows

2005-02-05 Thread Gary Bishop
Claudio Grondi <[EMAIL PROTECTED]> wrote: > "Ashot" <[EMAIL PROTECTED]> schrieb im Newsbeitrag > news:[EMAIL PROTECTED] > > whoa, that was quick, looks like it works for me. Thanks a lot! > > It would be nice to be able to set the colors in the prefs file, although > > its possible to edit the pyC

Re: Pickling and inheritance are making me hurt

2005-02-05 Thread John J. Lee
Kirk Strauser <[EMAIL PROTECTED]> writes: > I have a module that defines a Search class and a SearchResult class. I use > these classes by writing other modules that subclass both of them as needed > to interface with particular search engines. > > My problem is that Search defines a method (cal

Definitive documentation on newstyle classes? (WAS: Pickling and inheritance are making me hurt)

2005-02-05 Thread Daniel Bickett
I was reading the "Pickling and inheritance are making me hurt" thread, and the latest suggestion (as of this posting) was to do with the __setstate__ and __getstate__ methods. They caught my attention because I hadn't encountered them before, and it reminded me that in the past I've never been abl

Re: Definitive documentation on newstyle classes? (WAS: Pickling and inheritance are making me hurt)

2005-02-05 Thread Bruno Desthuilliers
Daniel Bickett a écrit : I was reading the "Pickling and inheritance are making me hurt" thread, and the latest suggestion (as of this posting) was to do with the __setstate__ and __getstate__ methods. They caught my attention because I hadn't encountered them before, and it reminded me that in the

Re: Definitive documentation on newstyle classes? (WAS: Pickling and inheritance are making me hurt)

2005-02-05 Thread Brian van den Broek
Daniel Bickett said unto the world upon 2005-02-05 19:46: I was reading the "Pickling and inheritance are making me hurt" thread, and the latest suggestion (as of this posting) was to do with the __setstate__ and __getstate__ methods. They caught my attention because I hadn't encountered them befor

Re: Definitive documentation on newstyle classes? (WAS: Pickling and inheritance are making me hurt)

2005-02-05 Thread Daniel Bickett
Bruno Desthuilliers wrote: > Well, the fact is that __[get|set]state__() have nothing to do with new > style classes, but with the Pickle protocol: > http://www.python.org/doc/2.3.4/lib/pickle-inst.html Thank you for pointing that out, but all the same ;) -- Daniel Bickett dbickett at gmail.com

Re: IPython colors in windows

2005-02-05 Thread Gary Bishop
On SourceForge you will find release 1.12 of my Python readline module. If you don't want to hack the colors, there is no reason to upgrade from 1.11 to 1.12. They *should* work the same. But if you'd like to hack the iPython colors this new version makes it possible. In your ipythonrc file add a

Re: Pickling and inheritance are making me hurt

2005-02-05 Thread Tim Peters
[Kirk Strauser] > I have a module that defines a Search class and a SearchResult class. Try posting a minimal self-contained code sample that fails. > I use these classes by writing other modules that subclass both of them as > needed to interface with particular search engines. > > My problem i

Re: sos!

2005-02-05 Thread jordan2856977
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > jordan2856977 a écrit : > > hellow everybody! I'm from china. I'm a beginner of python. in china, > > python is not a fashionable language, so it's difficult to find some > > books about python. finally,I find a

Re: changing local namespace of a function

2005-02-05 Thread Kent Johnson
Bo Peng wrote: Exec is slow since compiling the string and calls to globals() use a lot of time. The last one is most elegant but __getattr__ and __setattr__ are costly. The 'evil hack' solution is good since accessing x and y takes no additional time. Previous comparison was not completely fa

Swig-friendly distutils.command.build_ext

2005-02-05 Thread George Sakkis
I'm using a custom extension of the build_ext distutils 'command' that integrates better with SWIG. Specifically, it: 1. Adds '-I' (include) swig option for each directory containing a source file in the given Extension. 2. Determines whether to add the '-c++" option by checking the source file

Re: variable declaration

2005-02-05 Thread Nick Coghlan
Alex Martelli wrote: It's not clear to me what semantics, exactly, x.y := z would be defined to have (assuming := is the syntax sugar for ``rebinding''). Perhaps, by analogy with every other augmented operator, it should be equivalent to: _temp = x.y x.y = type(temp).__irebind__(temp, z) T

bad generator performance

2005-02-05 Thread Johannes Ahl mann
hi, i am in the process of profiling an application and noticed how much time my depth first generator for walking a tree data structure took. i wrote the same thing as a recursive function producing an array, and this non-generator version is nearly 10 times faster! any ideas why this is, what

Re: "pickle" vs. f.write()

2005-02-05 Thread Martin Miller
Marc 'BlackJack' Rintsch wrote: > ... > > I write __repr__() methods similar but I think a bit more readable: > > def __repr__(self): > return "%s(%r, %r, %r, %r)" % (self.__class__.__name__, self.name, > self.age, self.friends, self.comment) > > And it'

Re: empty classes as c structs?

2005-02-05 Thread Nick Coghlan
Steven Bethard wrote: Nick Coghlan wrote: I think the idea definitely deserves mention as a possible implementation strategy in the generic objects PEP, with the data argument made optional: That's basically what the current implementation does (although I use 'update' instead of '='). The cod

Re: bad generator performance

2005-02-05 Thread Johannes Ahl mann
sorry, forgot to post the profiling info for the recursive helper function. but generator is still FAR slower... 4095/10.0500.0000.1200.120 file.py:135(rek) Johannes -- http://mail.python.org/mailman/listinfo/python-list

Re: Insane import behaviour and regrtest.py: heeelp

2005-02-05 Thread Nick Coghlan
John J. Lee wrote: The only change I made to regrtest other than the print statements was to add Lib to sys.path, so I pick up modules from CVS instead of the installed 2.4 versions (yeah, I know I should build and install a python2.5 executable from CVS, but I don't see how that's relevant here).

ANN: SPE 0.7.2.A IDE with uml, wxGlade and blender support

2005-02-05 Thread http://www.stani.be
Spe is a python IDE with auto-indentation, auto completion, call tips, syntax coloring, uml viewer, syntax highlighting, class explorer, source index, auto todo list, sticky notes, integrated pycrust shell, python file browser, recent file browser, drag&drop, context help, ... Special is its blende

Re: CGI POST problem was: How to read POSTed data

2005-02-05 Thread and-google
Dan Perl wrote: > how is a multipart POST request parsed by CGIHTTPServer? It isn't; the input stream containing the multipart/form-data content is passed to the CGI script, which can choose to parse it or not using any code it has to hand - which could be the 'cgi' module, but not necessarily.

Re: [EVALUATION] - E01: The Java Failure - May Python Helps?

2005-02-05 Thread Courageous
>Well, we don't have to ban them because we have the PSU eliminate them >alltogether. So much more efficient. Or do you think it's a coincidence >we've never seen or heard Timothy "autocoding" Rue again? Foolish, man! You said his name! It's almost like you said C'thul'hu, ... you ... ah no

RE: bad generator performance

2005-02-05 Thread Robert Brewer
Johannes Ahl mann wrote: > i am in the process of profiling an application and noticed how much > time my depth first generator for walking a tree data structure took. > > i wrote the same thing as a recursive function producing an array, and > this non-generator version is nearly 10 times faster!

Re: An Ode To My Two Loves

2005-02-05 Thread Luis M. Gonzalez
Jamey, Really, you should try to steer clear from your computer from time to time... Your mental health is more important than python or ruby, don't lose it! -- http://mail.python.org/mailman/listinfo/python-list

Re: CGI POST problem was: How to read POSTed data

2005-02-05 Thread M.E.Farmer
Dan Perl wrote: > I am piggybacking on Hakan's original posting because I am addressing the > same group of people (those with good knowledge in the standard web > programming modules), on a related topic. However, my question is > independent of Hakan's. > > I have trouble getting a simple CGI sc

Re: CGI POST problem was: How to read POSTed data

2005-02-05 Thread Dan Perl
"M.E.Farmer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Dan, > I was wondering how you were coming with your project. > I had wondered if i had missed something going the CherryPy route > instead of CGI. Now I see that you have had a bit of a snag , sorry to > hear that. > I a

Re: [EVALUATION] - E01: The Java Failure - May Python Helps?

2005-02-05 Thread Ilias Lazaridis
Terry Reedy wrote: "Ilias Lazaridis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] If you ask too much that other people do your searching for you, answers will dry up. I don't ask people to search for me. I ask people for their specific knowledge about specific python language

Re: sos!

2005-02-05 Thread jordan2856977
"Dan Perl" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > "jordan2856977" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > hellow everybody! I'm from china. I'm a beginner of python. in china, > > python is not a fashionable language, so it's difficult to find

Re: sos!

2005-02-05 Thread jordan2856977
"Dan Perl" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL PROTECTED]>... > <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > > > Dan Perl wrote: > >> [...] > > Aren't you in the wrong newsgroup? :-) > > Aren't you funny? i think i have solve the problem thank you -- http://mai

Re: sos!

2005-02-05 Thread Dan Perl
"jordan2856977" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Dan Perl" <[EMAIL PROTECTED]> wrote in message > news:<[EMAIL PROTECTED]>... >> <[EMAIL PROTECTED]> wrote in message >> news:[EMAIL PROTECTED] >> > >> > Dan Perl wrote: >> >> [...] >> > Aren't you in the wrong newsgro

Re: a type without a __mro__?

2005-02-05 Thread John Lenton
On Sat, Feb 05, 2005 at 11:37:10AM +0100, Alex Martelli wrote: > Can anybody suggest where to find (within the standard library) or how > to easily make (e.g. in a C extension) a type without a __mro__, except > for those (such as types.InstanceType) which are explicitly recorded in > the dispatch

Re: CGI POST problem was: How to read POSTed data

2005-02-05 Thread Dan Perl
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Dan Perl wrote: > >> how is a multipart POST request parsed by CGIHTTPServer? > > It isn't; the input stream containing the multipart/form-data content > is passed to the CGI script, which can choose to parse it or not using > any code

Re: changing local namespace of a function

2005-02-05 Thread Bo Peng
Kent Johnson wrote: Bo Peng wrote: Exec is slow since compiling the string and calls to globals() use a lot of time. The last one is most elegant but __getattr__ and __setattr__ are costly. The 'evil hack' solution is good since accessing x and y takes no additional time. Previous comparison w

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Adam DePrince
On Sat, 2005-02-05 at 17:11, Michael Hartl wrote: > Use the eval function: > > >>> eval("30/(6+9)") > 2 > > Michael Sure, if you trust the source of the string you are evaluating. If this is a form submission on your web site, be wary of the nefarious user who might submit to you: commands.get

Word for a non-iterator iterable?

2005-02-05 Thread Leif K-Brooks
Is there a word for an iterable object which isn't also an iterator, and therefor can be iterated over multiple times without being exhausted? "Sequence" is close, but a non-iterator iterable could technically provide an __iter__ method without implementing the sequence protocol, so it's not qu

Re: variable declaration

2005-02-05 Thread Alex Martelli
Nick Coghlan <[EMAIL PROTECTED]> wrote: ... > > _temp = x.y > > x.y = type(temp).__irebind__(temp, z) ... > I was thinking of something simpler: > >x.y >x.y = z > > That is, before the assignment attempt, x.y has to resolve to *something*, but > the interpreter isn't particu

Re: How do I convert arithemtic string (like "2+2") to a number?

2005-02-05 Thread Michael Hartl
Adam brings up a good point: eval is a very general function which evaluates an arbitrary Python expression. As a result, it (and its close cousin exec) should be used with caution if security is an issue. Michael -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble converting hex to decimal?

2005-02-05 Thread Adam DePrince
On Sat, 2005-02-05 at 12:02, Steve Holden wrote: > Pedro Werneck wrote: > > The problem is that '\x00' is a escape sequence... > > Try something like this: > x = '\x00' > int(repr(x)[3:-1], 16) > > 0 > x = '\x15' > int(repr(x)[3:-1], 16) > > 21 > > On Sat, 05 Feb 2005 06:51:32 -070

Multiple constructors

2005-02-05 Thread Philip Smith
Call this a C++ programmers hang-up if you like. I don't seem to be able to define multiple versions of __init__ in my matrix class (ie to initialise either from a list of values or from 2 dimensions (rows/columns)). Even if Python couldn't resolve the __init__ to use on the basis of argument

Re: variable declaration

2005-02-05 Thread Alex Martelli
Arthur <[EMAIL PROTECTED]> wrote: > Do the STUPID firms use Python as well. Yes, they're definitely starting to do so. > Why? The single most frequent reason is that some techie sneaked it in, for example "just for testing" or "to do a prototype" or even without any actual permission. Firms

Re: Trouble converting hex to decimal?

2005-02-05 Thread Miki Tebeka
Hello Earl, > I'm trying to process the IP packet length field, as recorded by pcap > (Ethereal) and recovered using pcapy. When I slice out those bytes, I > get a value that shows in '\x00' format, rather than '0x00'. Neither > int() nor eval() are working. How do I handle this? Try using "arr

<    1   2