Re: namespace dictionaries ok?

2005-10-24 Thread Ron Adam
Simon Burton wrote: > Yes! > > I do this a lot when i have deeply nested function calls > a->b->c->d->e > and need to pass args to the deep function without changing the > middle functions. Yes, :-) Which is something like what I'm doing also. Get the dictionary, modify it or validate it som

Re: namespace dictionaries ok?

2005-10-24 Thread Ron Adam
nstead of creating a new object? Cheers, Ron > On Monday 24 October 2005 19:53, Ron Adam wrote: > >>James Stroud wrote: >> >>>Here it goes with a little less overhead: >>> >>> >>>py> class namespace: >>>... def __init__(self,

Re: namespace dictionaries ok?

2005-10-25 Thread Ron Adam
James Stroud wrote: > Here it goes with a little less overhead: > > > py> class namespace: > ... def __init__(self, adict): > ... self.__dict__.update(adict) > ... > py> n = namespace({'bob':1, 'carol':2, 'ted':3, 'alice':4}) > py> n.bob > 1 > py> n.ted > 3 > > James How about... cl

Re: namespace dictionaries ok?

2005-10-25 Thread Ron Adam
Duncan Booth wrote: > Ron Adam wrote: > >>James Stroud wrote: >> >>>Here it goes with a little less overhead: >>> >>> > > > >>But it's not a dictionary anymore so you can't use it in the same places >>you would

Re: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName'

2005-10-25 Thread Ron Adam
[EMAIL PROTECTED] wrote: > Hi, > > unfortunately the result from py2exe won't run eventhough the original > script runs without problems. The trouble is I'm at a loss as to where > to start looking! > > Martin. Just a guess, Make sure any your file names aren't the same as any of the module na

Re: namespace dictionaries ok?

2005-10-25 Thread Ron Adam
Bengt Richter wrote: > On Tue, 25 Oct 2005 16:20:21 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: >>Or worse, the dictionary would become not functional depending on what >>methods were masked. >> >> >>And this approach reverses that, The dict values will be

Re: Setting Class Attributes

2005-10-25 Thread Ron Adam
the.theorist wrote: > So that it'll be easier to remember the next time I find myself in the > same situation on a different task, I'll extend the discussion > somewhat. > > Coming from C, I had expected that I'd get a new empty dict every time > the __init__ function ran. Guido (or some other

Re: Top-quoting defined [was: namespace dictionaries ok?]

2005-10-26 Thread Ron Adam
Duncan Booth wrote: > No, I didn't think it was malice which is why I just added what I > considered to be a polite request at the end of my message. I assumed that > most people either knew the phrase or could find out in a few seconds using > Google so there wasn't much point in rehashing t

Re: Would there be support for a more general cmp/__cmp__

2005-10-26 Thread Ron Adam
Antoon Pardon wrote: > Op 2005-10-25, Steven D'Aprano schreef <[EMAIL PROTECTED]>: >>Can somebody remind me, what is the problem Antoon is trying to solve here? > > > Well there are two issues. One about correct behaviour and one about > practicallity. > > The first problem is cmp. This is w

Re: Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName'

2005-10-26 Thread Ron Adam
[EMAIL PROTECTED] wrote: > Hi, > > which file names do you mean? > > -Martin. I've ran across a case where I copied a module from the python libs folder to my source directory, it would work fine before I built with py2exe, but afterwards it would give a file not found error. I haven't q

Re: How best to reference parameters.

2005-10-26 Thread Ron Adam
David Poundall wrote: > However, what I really would like is something like... > > class c_y: > def __init__(self): > self.P1 = [0, 'OB1', 0 ] > self.P2 = [0, 'OB1', 1 ] > self.P3 = [0, 'OB1', 2 ] > self.P4 = [0, 'OB1', 3 ] > > Because that way I can also hol

Re: How best to reference parameters.

2005-10-26 Thread Ron Adam
David Poundall wrote: > Sadly Ron, c_y can only see index and showall in your example. Well, don't give up! The approach is sound and I did say it was untested. Here's a tested version with a few corrections. :-) Cheers, Ron class Pump(object): def __init__(self, name, ptype, n

Re: namespace dictionaries ok?

2005-10-26 Thread Ron Adam
Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: >... > >> class namespace(dict): >> def __getattr__(self, name): >> return self.__getitem__(name) > >... > >>Any thoughts? Any better way to d

Re: Would there be support for a more general cmp/__cmp__

2005-10-28 Thread Ron Adam
Antoon Pardon wrote: > Op 2005-10-26, Ron Adam schreef <[EMAIL PROTECTED]>: > >>Adding complexity to cmp may not break code, but it could probably slow >>down sorting in general. So I would think what ever improvements or >>alternatives needs to be careful not

Re: tkinter blues (greens, reds, ...)

2005-10-28 Thread Ron Adam
Steve Holden wrote: > Sean McIlroy wrote: > >> hi all >> >> i recently wrote a script that implements a puzzle. the interface >> mostly consists of a bunch of colored disks on a tkinter canvas. the >> problem is that the disks change their colors in ways other than the >> way they're supposed t

Re: tkinter blues (greens, reds, ...)

2005-10-28 Thread Ron Adam
Sean McIlroy wrote: > i'm using the canned colors ("pink", "orange", etc). should i try > changing to explicit color specifications to see if that makes a > difference? i'm not sure what the other guy meant by a "soft toy", but > i take it the idea is to try and construct a correctness proof for

Re: Arguments for button command via Tkinter?

2005-10-31 Thread Ron Adam
Steve Holden wrote: > Francesco Bochicchio wrote: > >> Il Mon, 31 Oct 2005 06:23:12 -0800, [EMAIL PROTECTED] ha scritto: >> >> >>> And yet the stupidity continues, right after I post this I finnally >>> find an answer in a google search, It appears the way I seen it is to >>> create a class for

Re: dictionary that have functions with arguments

2005-11-02 Thread Ron Adam
[EMAIL PROTECTED] wrote: > hi > i have a dictionary defined as > > execfunc = { 'key1' : func1 } > > to call func1, i simply have to write execfunc[key1] . > but if i have several arguments to func1 , like > > execfunc = { 'key1' : func1(**args) } > > how can i execute func1 with variable ar

Re: dictionary that have functions with arguments

2005-11-02 Thread Ron Adam
Neal Norwitz wrote: > Ron Adam wrote: > >>Eval or exec aren't needed. Normally you would just do... >> >>execfunc['key1'](**args) >> >>If your arguments are stored ahead of time with your function... >> >>Committed re

Re: Tkinter- Building a message box

2005-11-07 Thread Ron Adam
Tuvas wrote: > I've been trying to build a fairly simple message box in tkinter, that > when a button is pushed, will pop up a box, that has a line of text, an > entry widget, and a button, that when the button is pushed, will return > the value in the line of text. However, while I can read the v

Re: Tkinter- Building a message box

2005-11-07 Thread Ron Adam
Tuvas wrote: > Do you have any info on dialogs? I've been trying to find some, without > alot of success... > Be sure and look at the examples in python24/lib/lib-tk. The Dialog.py file there does pretty much what you want. In the dialog caller example I gave, it should have been ... def do

Re: when and how do you use Self?

2005-11-07 Thread Ron Adam
Tieche Bruce A MSgt USMTM/AFD wrote: > I am new to python, > > Could someone explain (in English) how and when to use self? > > I have been reading, and haven't found a good example/explanation > > > Bruce Tieche ([EMAIL PROTECTED]) Hi, Sometimes it's hard to get a simple answer to progra

Re: Newbie Alert: Help me store constants pythonically

2005-11-07 Thread Ron Adam
Brendan wrote: >>How many is LOOONG? Ten? Twenty? One hundred? > > > About 50 per Model > > >>If it is closer to 100 than to 10, I would suggest >>putting your constants into something like an INI file: >> >>[MODEL1] # or something more meaningful >>numBumps: 1 >>sizeOfBumps: 99 >> >>[MODEL2

Re: overloading *something

2005-11-07 Thread Ron Adam
James Stroud wrote: > Hello All, > > How does one make an arbitrary class (e.g. class myclass(object)) behave like > a list in method calls with the "*something" operator? What I mean is: You need to base myclass on a list if I understand your question. class myclass(list): def __init__

Re: Returning a value from a Tk dialog

2005-11-07 Thread Ron Adam
Gordon Airporte wrote: > The dialogs in tkColorChooser, tkFileDialog, etc. return useful values > from their creation somehow, so I can do stuff like this: > > filename = tkFileDialog.askopenfilename( master=self ) > > I would like to make a Yes/No/Cancel dialog that can be used the same > wa

Re: overloading *something

2005-11-07 Thread Ron Adam
Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: > > >>James Stroud wrote: >>>And, how about the "**something" operator? >>> >>>James >> >>A dictionary would be pretty much the same except subclassed from a >

Re: How to convert a number to hex number?

2005-11-08 Thread Ron Adam
Bengt Richter wrote: > On 08 Nov 2005 08:07:34 -0800, Paul Rubin wrote: > > >>"dcrespo" <[EMAIL PROTECTED]> writes: >> >>hex(255)[2:] >>> >>>'ff' >> >>'%x'%255 is preferable since the format of hex() output can vary. Try >>hex(33**33). > > > Not to mention ([E

Re: which feature of python do you like most?

2005-11-08 Thread Ron Adam
[EMAIL PROTECTED] wrote: > which feature of python do you like most? > > I've heard from people that python is very useful. > Many people switch from perl to python because they like it more. > > I am quite familiar with perl, I've don't lots of code in perl. > Now, I was curious and intereste

Re: How to convert a number to hex number?

2005-11-09 Thread Ron Adam
Bengt Richter wrote: > On Wed, 09 Nov 2005 00:42:45 GMT, Ron Adam <[EMAIL PROTECTED]> wrote: > > >> >>Bengt Richter wrote: >> >>>On 08 Nov 2005 08:07:34 -0800, Paul Rubin <http://[EMAIL PROTECTED]> wrote: >>> >>> >>

Re: help make it faster please

2005-11-13 Thread Ron Adam
Fredrik Lundh wrote: > Lonnie Princehouse wrote: > > >>"[a-z0-9_]" means "match a single character from the set {a through z, >>0 through 9, underscore}". > > > "\w" should be a bit faster; it's equivalent to "[a-zA-Z0-9_]" (unless you > specify otherwise using the locale or unicode flags), b

Re: help make it faster please

2005-11-13 Thread Ron Adam
Fredrik Lundh wrote: > Ron Adam wrote: > > >>The \w does make a small difference, but not as much as I expected. > > > that's probably because your benchmark has a lot of dubious overhead: I think it does what the OP described, but that may not be what he rea

PythonMagick on Windows

2005-12-05 Thread Adam Endicott
Does anyone know anything about PythonMagick? I've got a project that could use ImageMagick, so I went looking around for PythonMagick, and I'm a bit lost. I was able to download the PythonMagick source from the ImageMagick site, but I'm on Windows and don't have the ability to compile it. I found

Re: PythonMagick on Windows

2005-12-05 Thread Adam Endicott
Claudio Grondi wrote: > Why is PIL *(Python Image Library) not suitable to do the graphics? > > http://www.pythonware.com/products/pil/ > > Claudio I am using PIL for some other things, but what I need ImageMagick for is to convert a PDF into a series of jpegs (one per page). Its the only tool I'v

Re: PythonMagick on Windows

2005-12-05 Thread Adam Endicott
I'm not sure I understand. What would be the benefit of GraphicsMagick over ImageMagick? I looked around the site, and it talks about using the same PythonMagick, with the same link to procoders.net. I'm actually using Python 2.3, so any issues with 2.4.2 won't be a problem. -- http://mail.pytho

Re: PythonMagick on Windows

2005-12-05 Thread Adam Endicott
I actually did some more fiddling around with it, and I think I can do what I need with ghostscript, bypassing ImageMagick altogether. It also appears to be *much* faster. -- http://mail.python.org/mailman/listinfo/python-list

Re: Documentation suggestions

2005-12-07 Thread Adam Olsen
On 12/7/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Adam> I don't expect everything to make the transition. Are discussions > Adam> of "atoms" and fragments of BNF really better than calling them > Adam> expressions and linking to

Re: Documentation suggestions

2005-12-07 Thread Adam Olsen
On 12/7/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > Adam> Having a large and detailed language specification, although an > Adam> admirable ideal, is a waste of time when the target audience is > Adam> perhaps a few dozen people. > > Just becau

Re: what is lambda used for in real code?

2004-12-31 Thread Adam DePrince
e ability to create an anonymous function simply because we can do so for every other object type, and functions are not special enough to permit this special case. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: OT: spacing of code in Google Groups

2004-12-31 Thread Adam DePrince
ling list. Take a look at http://python.org/community/lists.html The news group and this list are mirrors of each other. Of course, the benefit this provides depends on which mail client you use. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: what is lambda used for in real code?

2005-01-04 Thread Adam DePrince
On Fri, 2004-12-31 at 17:36, Steven Bethard wrote: > Adam DePrince wrote: > > Lets not forget the "real reason" for lambda ... the elegance of > > orthogonality. Why treat functions differently than any other object? > > > > We can operate on every othe

Re: what is lambda used for in real code?

2005-01-04 Thread Adam DePrince
On Fri, 2004-12-31 at 22:09, Terry Reedy wrote: > "Adam DePrince" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > In sort, we must preserve the ability to create an anonymous function > > simply because we can do so for every other object type,

Re: what is lambda used for in real code?

2005-01-04 Thread Adam DePrince
On Sat, 2005-01-01 at 11:42, Steve Holden wrote: > Adam DePrince wrote: > [...] > > > > In sort, we must preserve the ability to create an anonymous function > > simply because we can do so for every other object type, and functions > > are not special enou

Re: Download .jpg from web

2005-01-06 Thread Adam DePrince
ora codec is pretty mature right now and, assuming that consequtive images are similar, will compress way better than just saving jpegs. - Adam > > Am I approaching this incorrectly? I have to do a urlopen, then .read() > for each image. Is there any way to 'persist' the urlo

Re: Writing huge Sets() to disk

2005-01-10 Thread Adam DePrince
saying NP != P. Then tell us what you are tring to do; perhaps there is a better way, perhaps the problem is unsolvable and there is a heuristic that will satisfy your needs. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: how to ncurses on win32 platform

2005-01-26 Thread adam . vandenberg
> * Curses for Windows for Python (It was previously > mentioned on a follow-up. there are some missing > features): > http://flangy.com/dev/python/curses/ I've posted an update to this module (better color support, half delay input, some other stuff) and the source code, in case anyone wants to

[Plone] Detailed poll results?

2005-01-29 Thread Adam Twardoch
Hello, Is there a method, or an alternative module that could be used, to have "polls" in Plone that display detailed results of the poll, i.e. all users and the votes they have given? Adam -- http://mail.python.org/mailman/listinfo/python-list

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

2005-02-05 Thread Adam DePrince
efarious user who might submit to you: commands.getoutput( "rm -rf %(HOME)s"%os.environ ) as the "expression" to evaluate. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Trouble converting hex to decimal?

2005-02-05 Thread Adam DePrince
>>> x = '\x00' > >>> ord(x) > 0 > >>> x = '\x15' > >>> ord(x) > 21 > >>> Ethereal's emission of \x00 shouldn't make your life any more difficult. The conversion of \0xx takes place in the eval. If you store the string \x00 in a file and call open.read or command.getoutput, you will get the python string "\\x00". Stuff you read from a file arrives un-de-escaped. The solution is simple. mystring.replace( "\x","0x" ) Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: bytecode obfuscation

2005-02-06 Thread Adam DePrince
how good their implementation of your protocol. The worst case if you depend on obscurity: The bad guys are rounding off your pennies as you read this. The worse case if you depend on encryption and open your spec: You get to publish your code, but might get competition. Just my $0.02. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

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

2005-02-06 Thread Adam DePrince
file.txt", "w+" ) hash = f.read( sha.digest_size ) mydata = f.read() if sha.new( mysecret + mydata ).digest() != hash: raise "Somebody is tring to hack you!" mydata = cPickle.loads( mydata ) Of course, the security of this scheme is dependent on a lot, including the strength of sha, your ability to keep your secret key secret, the correctness of what I'm saying, etc etc etc. Adam DePrince -- http://mail.python.org/mailman/listinfo/python-list

Re: Loop until condition is true

2005-06-18 Thread Ron Adam
Joseph Garvin wrote: > Peter Otten wrote: > >> I found 136 occurrences of "do {" versus 754 of "while (" and 1224 of >> "for >> (" in the Python 2.4 source, so using these rough estimates do-while >> still >> qualifies as "rarely used". >> >> Peter >> >> >> > That's 136 times you'd have to use

Re: Is there something similar to ?: operator (C/C++) in Python?

2005-06-19 Thread Ron Adam
Bo Peng wrote: > Roy Smith wrote: > >> Can you give us some idea of what it is that you're trying to do? It >> pretty unusual to see a requirement like that. > > > def func(type_of_obj1, type_of_obj2, .): > callfunc( [ > type_of_obj1 and obj1a() or obj1b(), > type_of_obj2 and obj

Re: Is there something similar to ?: operator (C/C++) in Python?

2005-06-20 Thread Ron Adam
Ron Adam wrote: > You might be able to use a dictionary of tuples. > > call_obj = {(type_obj1,0):obj1a, > (type_obj1,0):obj1b, > (type_boj2,1):obj2a, > (type_obj2,1):obj2b, > etc... } > call_obj[(type_of_obj,order)]() &g

Re: getting an object name

2005-06-22 Thread Ron Adam
David Bear wrote: > Let's say I have a list called, alist. If I pass alist to a function, > how can I get the name of it? > > alist = range(10) > > def afunction(list): > listName = list.__name__ (fails for a list object) > Using an object's name as data isn't a good idea because it will g

PEP 343, second look

2005-06-22 Thread Ron Adam
After taking a break from following PEP 343 and it's associated PEPs, I wanted to look at it again because it still seemed a bit hard to get my mind around. http://www.python.org/peps/pep-0343.html > A new statement is proposed with the syntax: > > with EXPR as VAR: >

Re: PEP 343, second look

2005-06-22 Thread Ron Adam
Paul Rubin wrote: > Ron Adam <[EMAIL PROTECTED]> writes: > >>>A new statement is proposed with the syntax: >>>with EXPR as VAR: >>>BLOCK >>>Here, 'with' and 'as' are new keywords; EXPR is an arbitrar

Re: Favorite non-python language trick?

2005-06-24 Thread Ron Adam
George Sakkis wrote: > "Joseph Garvin" wrote: > > >>I'm curious -- what is everyone's favorite trick from a non-python >>language? And -- why isn't it in Python? > > > Although it's an optimization rather than language trick, I like the > inline functions/methods in C++. There has been a thread

Re: Thoughts on Guido's ITC audio interview

2005-06-27 Thread Ron Adam
Dave Benjamin wrote: > Guido gave a good, long interview, available at IT Conversations, as was > recently announced by Dr. Dobb's Python-URL! The audio clips are available > here: > > http://www.itconversations.com/shows/detail545.html > http://www.itconversations.com/shows/detail559.html Than

Re: Is there something similar to ?: operator (C/C++) in Python?

2005-06-28 Thread Ron Adam
Mike Meyer wrote: > Riccardo Galli <[EMAIL PROTECTED]> writes: > > >>On Fri, 24 Jun 2005 09:00:04 -0500, D H wrote: >> >> Bo Peng wrote: >I need to pass a bunch of parameters conditionally. In C/C++, I can >do func(cond1?a:b,cond2?c:d,.) > >Is there an easier way

Re: Boss wants me to program

2005-06-28 Thread Ron Adam
[EMAIL PROTECTED] wrote: > Ok, sorry to throw perhaps unrelated stuff in here, but I want everyone > to know what we have right now in the office. We started with an > electric typewriter and file cabinets. We were given an old 386 with a > 20 mb hard drive about 5 years ago, and we moved everythi

Re: Is there something similar to ?: operator (C/C++) in Python?

2005-06-30 Thread Ron Adam
Antoon Pardon wrote: > Op 2005-06-29, Scott David Daniels schreef <[EMAIL PROTECTED]>: > >>Roy Smith wrote: >> >>>Andrew Durdin <[EMAIL PROTECTED]> wrote: >>> Corrected version: result = [(lambda: expr0), lambda: expr1][bool(cond)]() >> >>Sorry, I thought cond was a standard boolean. >>

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Ron Adam
Tom Anderson wrote: > So, if you're a pythonista who loves map and lambda, and disagrees with > Guido, what's your background? Functional or not? I find map too limiting, so won't miss it. I'm +0 on removing lambda only because I'm unsure that there's always a better alternative. So what woul

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-01 Thread Ron Adam
Terry Hancock wrote: > On Friday 01 July 2005 03:36 pm, Ron Adam wrote: > >>I find map too limiting, so won't miss it. I'm +0 on removing lambda >>only because I'm unsure that there's always a better alternative. > > > Seems like some new

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-02 Thread Ron Adam
Ralf W. Grosse-Kunstleve wrote: > class grouping: > > def __init__(self, .x, .y, .z): > # real code right here The way this would work seems a bit inconsistent to me. Args normally create local variables that receive references to the objects passed to them. In this c

Re: Folding in vim

2005-07-02 Thread Ron Adam
Terry Hancock wrote: > My general attitude towards IDEs and editors has been > extremely conservative, but today I decided to see what > this "folding" business was all about. > > I see that vim (and gvim, which is what I actually use) > has this feature, and it is fairly nice, but at present i

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-02 Thread Ron Adam
Steven D'Aprano wrote: > On Sat, 02 Jul 2005 20:26:31 -0700, Devan L wrote: > > >> Claiming that sum etc. do the same job is the whimper of >>someone who doesn't want to openly disagree with Guido. >> >>Could you give an example where sum cannot do the job(besides the >>previously mentioned prod

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-03 Thread Ron Adam
Erik Max Francis wrote: > Ron Adam wrote: >> I'm just estimating, but I think that is the gist of adding those two >> in exchange for reduce. Not that they will replace all of reduce use >> cases, but that sum and product cover most situations and can be >> i

Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code

2005-07-03 Thread Ron Adam
Bengt Richter wrote: > What if parameter name syntax were expanded to allow dotted names as binding > targets in the local scope for the argument or default values? E.g., > > def foometh(self, self.x=0, self.y=0): pass > > would have the same effect as > > def foometh(self, self.y=0, se

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-03 Thread Ron Adam
Steven D'Aprano wrote: > On Sun, 03 Jul 2005 19:31:02 +0000, Ron Adam wrote: > > >>First on removing reduce: >> >>1. There is no reason why reduce can't be put in a functional module > > > Don't disagree with that. > > >>or >

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-03 Thread Ron Adam
Erik Max Francis wrote: > Ron Adam wrote: > >> Each item needs to stand on it's own. It's a much stronger argument >> for removing something because something else fulfills it's need and >> is easier or faster to use than just saying we need x becaus

Re: Folding in vim

2005-07-03 Thread Ron Adam
Terry Hancock wrote: > On Saturday 02 July 2005 10:35 pm, Terry Hancock wrote: > >>I tried to load a couple of different scripts to >>automatically fold Python code in vim, but none of them >>seems to do a good job. >> >>I've tried: >>python_fold.vim by Jorrit Wiersma >>http://www.vim.org/sc

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-04 Thread Ron Adam
George Sakkis wrote: > And finally for recursive flattening: > > def flatten(seq): > return reduce(_accum, seq, []) > > def _accum(seq, x): > if isinstance(x,list): > seq.extend(flatten(x)) > else: > seq.append(x) > return seq > > flatten(seq) > > [1, 2, 3,

flatten(), [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-05 Thread Ron Adam
--- The results on Python 2.3.5: (maybe someone can try it on 2.4) recursive flatten: 23.6332723852 flatten in place-non recursive: 22.1817641628 recursive-no copies: 30.909762833 smallest recursive: 35.2678756658 non-recursive flatten in place without copies: 7.8551944451 A 300% improvement!!! This shows the value of avoiding copies, recursion, and extra function calls. Cheers, Ron Adam -- http://mail.python.org/mailman/listinfo/python-list

Re: flatten(), [was Re: map/filter/reduce/lambda opinions ...]

2005-07-05 Thread Ron Adam
> Ok... How about a non-recursive flatten in place? ;-) > > def flatten(seq): > i = 0 > while i!=len(seq): > while isinstance(seq[i],list): > seq.__setslice__(i,i+1,seq[i]) > i+=1 > return seq > > seq = [[1,2],[3],[],[4,[5,6]]] > print flatten(seq) > > I

Re: flatten(), [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-05 Thread Ron Adam
Tom Anderson wrote: > > We really ought to do this benchmark with a bigger list as input - a few > thousand elements, at least. But that would mean writing a function to > generate random nested lists, and that would mean specifying parameters > for the geometry of its nestedness, and that wou

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Ron Adam
Terry Reedy wrote: > I also suspect that the years of fuss over Python's lambda being what it is > rather that what it is 'supposed' to be (and is in other languages) but is > not, has encourage Guido to consider just getting rid of it. I personally > might prefer keeping the feature but using

Re: map/filter/reduce/lambda opinions and background unscientificmini-survey

2005-07-05 Thread Ron Adam
Terry Reedy wrote: > "George Sakkis" <[EMAIL PROTECTED]> wrote in message >>So, who would object the full-word versions for python 3K ? >>def -> define >>del -> delete >>exec -> execute > > > These three I might prefer to keep. > > >>elif -> else if > > > This one I dislike and would prefer

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-05 Thread Ron Adam
Robert Kern wrote: > Dan Bishop wrote: > >> There's also the issue of having to rewrite old code. > > > It's Python 3000. You will have to rewrite old code regardless if reduce > stays. > And from what I understand Python 2.x will still be maintained and supported. It will probably be more

Using Ghostscript DLL via ctypes in Py2.3/Win

2005-07-06 Thread Adam Twardoch
and cares to share a code snippet? Regards, Adam *) http://www.cs.wisc.edu/~ghost/doc/cvs/API.htm -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Tom Anderson wrote: >> del -> delete > > > How about just getting rid of del? Removal from collections could be > done with a method call, and i'm not convinced that deleting variables > is something we really need to be able to do (most other languages > manage without it). Since this is a

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Dan Sommers wrote: > On Wed, 06 Jul 2005 14:33:47 GMT, > Ron Adam <[EMAIL PROTECTED]> wrote: > > >>Since this is a Python 3k item... What would be the consequence of >>making None the default value of an undefined name? And then assigning >>

Re: Use cases for del

2005-07-06 Thread Ron Adam
Steven D'Aprano wrote: > On Wed, 06 Jul 2005 10:00:02 -0400, Jp Calderone wrote: > > >>On Wed, 06 Jul 2005 09:45:56 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: >> >>>Tom Anderson wrote: >>> How about just getting rid of del? Removal from collections could be done with a method call, an

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Devan L wrote: >># from a custom numeric class >># converts a tuple of digits into a number >>mantissa = sign * reduce(lambda a, b: 10 * a + b, mantissa) > > > I'll admit I can't figure out a way to replace reduce without writing > some ugly code here, but I doubt these sorts of things appear of

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Dan Sommers wrote: >> AttributeError: 'NoneType' object has no attribute 'read' > > > This is the one of which I was thinking. So you see this error at the > end of a (long) traceback, and try to figure out where along the (long) > line of function calls I typed the wrong name. Currently,

Re: Avoiding NameError by defaulting to None

2005-07-06 Thread Ron Adam
Scott David Daniels wrote: > Ron Adam wrote: > >> Dan Sommers wrote: >> >>> Lots more hard-to-find errors from code like this: >>> filehandle = open( 'somefile' ) >>> do_something_with_an_open_file( file_handle ) >>> fil

Re: Use cases for del

2005-07-06 Thread Ron Adam
Ron Adam wrote: > And accessing an undefined name returned None instead of a NameError? I retract this. ;-) It's not a good idea. But assigning to None as a way to unbind a name may still be an option. -- http://mail.python.org/mailman/listinfo/python-list

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Stian Søiland wrote: > On 2005-07-06 16:33:47, Ron Adam wrote: > > >>*No more NamesError exceptions! >> print value >> >> None > > > So you could do lot's of funny things like: > > def my_fun(extra_args=None): >

Re: Use cases for del

2005-07-06 Thread Ron Adam
Reinhold Birkenfeld wrote: > Ron Adam wrote: > >>Ron Adam wrote: >> >> >>>And accessing an undefined name returned None instead of a NameError? >> >>I retract this. ;-) >> >>It's not a good idea. But assigning to None as a way

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Benji York wrote: > Ron Adam wrote: > >> "if extraargs:" would evaluate to "if None:", which would evaluate to >> "if:" which would give you an error. > > > In what way is "if None:" equivalent to "if:"? > -- >

Re: Use cases for del

2005-07-06 Thread Ron Adam
Grant Edwards wrote: > On 2005-07-06, Ron Adam <[EMAIL PROTECTED]> wrote: > > >>It would be a way to set an argument as being optional without actually >>assigning a value to it. The conflict would be if there where a global >>with the name baz as well. Pro

Re: flatten(), [was Re: map/filter/reduce/lambda opinions ...]

2005-07-06 Thread Ron Adam
Stian Søiland wrote: > Or what about a recursive generator? > > a = [1,2,[[3,4],5,6],7,8,[9],[],] > > def flatten(item): > try: > iterable = iter(item) > except TypeError: > yield item # inner/final clause > else: > for elem in

Re: Use cases for del

2005-07-06 Thread Ron Adam
Grant Edwards wrote: > On 2005-07-07, Ron Adam <[EMAIL PROTECTED]> wrote: > >>Grant Edwards wrote: >> >> >>>On 2005-07-06, Ron Adam <[EMAIL PROTECTED]> wrote: >>> >>> >>> >>>>It would be a way to set an argument

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-06 Thread Ron Adam
Mike Meyer wrote: > Ron Adam <[EMAIL PROTECTED]> writes: > >>So doing this would give an error for functions that require an argument. >> >> def foo(x): >> return x >> >> a = None >> b = foo(a)# error because a dissap

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Reinhold Birkenfeld wrote: > Ron Adam wrote: > > >>Given the statement: >> >>a = None >> >>And the following are all true: >> >> a == None > > > Okay. > > >>(a) == (None) > > > Okay. > > >>(a) =

Re: Why anonymity? [was Re: map/filter/reduce/lambda opinions and background unscientific mini-survey]

2005-07-07 Thread Ron Adam
Steven D'Aprano wrote: > On Thu, 07 Jul 2005 09:36:24 +, Duncan Booth wrote: > > >>Steven D'Aprano wrote: >> >>>This is something I've never understood. Why is it bad >>>form to assign an "anonymous function" (an object) to a >>>name? >> >>Because it obfuscates your code for no benefit. Yo

Re: Use cases for del

2005-07-07 Thread Ron Adam
Grant Edwards wrote: > On 2005-07-07, Ron Adam <[EMAIL PROTECTED]> wrote: >>>>>>It would be a way to set an argument as being optional without >>>>>>actually assigning a value to it. >> >>So it would still work like you expect even tho

Re: Use cases for del

2005-07-07 Thread Ron Adam
Steven D'Aprano wrote: > Ron Adam wrote: > >> Why would you want to use None as an integer value? >> >> If a value isn't established yet, then do you need the name defined? >> Wouldn't it be better to wait until you need the name then give it a >

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Christopher Subich wrote: > As others have mentioned, this looks too much like a list comprehension > to be elegant, which also rules out () and {}... but I really do like > the infix syntax. Why would it rule out ()? You need to put a lambda express in ()'s anyways if you want to use it righ

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Erik Max Francis wrote: > Ron Adam wrote: > >> It's not an empty tuple, it's an empty parenthesis. Using tuples it >> would be. >> >> (a,) == (,) >> >> which would be the same as: >> >> (,) == (,) > > > &

Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-07 Thread Ron Adam
Erik Max Francis wrote: > Ron Adam wrote: > >> Well in my previous explanation I *mean* it to be empty parenthesis. >> >> Does that help? > > > Maybe it might be beneficial to learn a little more of the language > before proposing such wide-reaching

<    1   2   3   4   5   6   7   8   9   10   >