Re: Embedded Python interpreter and sockets

2005-11-18 Thread [EMAIL PROTECTED]
Hi Jan, I believe the problem lies with how Houdini uses dlopen() to open your plugin. It uses RTLD_LOCAL to load your plugin, which means that all your plugin's symbols (including the python symbols) are private to that library. Subsequent dlopen() calls, including those made by the python libr

Re: the PHP ternary operator equivalent on Python

2005-11-18 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > WHY WHY WHY the obsession with one-liners? What is wrong with the good old > fashioned way? > > if cond: > x = true_value > else: > x = false_value > > It is easy to read, easy to understand, only one of true_value and > false_value is evaluated. It isn't a one-lin

Re: the PHP ternary operator equivalent on Python

2005-11-18 Thread [EMAIL PROTECTED]
Roy Smith wrote: > I think the list comprehensions are going to be the death of readable > python programs. Could be, but seems that someone in charge of the language wants readable python programs to die then as if list comprehension is not enough, there comes generator expression and now the for

Re: Underscores in Python numbers

2005-11-18 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > On Fri, 18 Nov 2005 16:26:08 -0800, [EMAIL PROTECTED] wrote: > > > Personally, I would rather see the int() and float() function be > > smarter to take what is used for this, i.e. : > > > > a = int("1,234,567") > > But th

Re: the PHP ternary operator equivalent on Python

2005-11-18 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > Why do you assume that everything you need for your list comprehension has > to go into a single line? Chances are your list comp already calls > functions, so just create one more for it to use. > > > py> def describe(cond): > ... if cond: > ... return "odd" >

Re: the PHP ternary operator equivalent on Python

2005-11-19 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > L = ["zero" if n == 0 else \ > "negative " + ("odd" if n % 2 else "even") if n < 0 else \ > "odd" if n % 2 else "even" for n in range(8)] > BTW, the continuation is not necessary I believe. [ x==0 and "zero" or ["","-"][x < 0] + ("even", "odd")[x%2] for x in range

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Stefan Rank wrote: > The other idea of teaching int() about separator characters has > internationalis/zation issues: > In many European countries, one would naturally try:: > >int('500.000,23') > > instead of:: > >int('500,000.23') That is why I said "Of course, also support the locale

Re: what happens when the file begin read is too big for all lines to be read with "readlines()"

2005-11-19 Thread [EMAIL PROTECTED]
newer python should use "for x in fh:", according to the doc : fh = open("your file") for x in fh: print x which would only read one line at a time. Ross Reyes wrote: > HI - > Sorry for maybe a too simple a question but I googled and also checked my > reference O'Reilly Learning Python > book an

Re: Obtaining an member function by name

2005-11-19 Thread [EMAIL PROTECTED]
f = getattr(obj,"bar") f() guy lateur wrote: > Hi all, > > Suppose you have this class: > > class foo: > def bar(): > > Suppose you also have the strings "foo" and "bar". How can you obtain the > function foo.bar()? > > Surely somebody knows.. > > TIA, > g -- http://mail.python.org/mailman

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Sybren Stuvel wrote: > [EMAIL PROTECTED] enlightened us with: > > Of course, also support the locale variant where the meaning of "," > > and "." is swapped in most European countries. > > This is exactly why I wouldn't use that notation. What happen

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Steve Holden wrote: > [EMAIL PROTECTED] wrote: > > Stefan Rank wrote: > > > >>The other idea of teaching int() about separator characters has > >>internationalis/zation issues: > >>In many European countries, one would naturally try:: > &g

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Steve Holden wrote: > Being European myself I am well aware of the notational differences of > the different locales, and I am perfectly happy that users can enter > numbers in their preferred format when they execute a program. > > However, I am not happy about the idea that a program source woul

Re: Underscores in Python numbers

2005-11-19 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > That's a tad unfair. Dealing with numeric literals with lots of digits is > a real (if not earth-shattering) human interface problem: it is hard for > people to parse long numeric strings. In the wider world outside of IT, > people deal with long numeric digits by grouping

Re: what happens when the file begin read is too big for all lines to be read with "readlines()"

2005-11-20 Thread [EMAIL PROTECTED]
Xiao Jianfeng wrote: > First, I must say thanks to all of you. And I'm really sorry that I > didn't > describe my problem clearly. > > There are many tokens in the file, every time I find a token, I have > to get > the data on the next line and do some operation with it. It should be easy

Re: what happens when the file begin read is too big for all lines to be read with "readlines()"

2005-11-20 Thread [EMAIL PROTECTED]
Xiao Jianfeng wrote: > I have compared the two methods, > (1). "for x in fh:" > (2). read all the file into memory firstly. > > I have tested the two methods on two files, one is 80M and the second > one is 815M. > The first method gained a speedup of about 40% for the first file, and >

Re: about dictionary

2005-11-20 Thread [EMAIL PROTECTED]
b = dict([(x,dict()) for x in a]) Shi Mu wrote: > I have have the following code: > >>> a=[3,5,8,0] > >>> b={} > >>> > How I can i assign each item in a as the key in the dictionary b > simultaneously? > that is, > b={3:[],5:[],8:[],0:[]} > Thanks! -- http://mail.python.org/mailman/listinfo/pytho

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
przemek drochomirecki wrote: > i am not sure what is the purpose of having ordered dictionaries built in > python, could u provide any examples? > > i use a contruction: > for x in sorted(d.keys()) > By ordered dict, one usually wants order that is arbitary which cannot be derived from the con

Re: about sort and dictionary

2005-11-20 Thread [EMAIL PROTECTED]
Shi Mu wrote: > Got confused by the following code: > >>> a > [6, 3, 1] > >>> b > [4, 3, 1] > >>> c > {1: [[6, 3, 1], [4, 3, 1]], 2: [[6, 3, 1]]} > >>> c[2].append(b.sort()) > >>> c > {1: [[6, 3, 1], [1, 3, 4]], 2: [[6, 3, 1], None]} > #why c can not append the sorted b?? > >>> b.sort() > >>> b >

Re: about lambda

2005-11-20 Thread [EMAIL PROTECTED]
Shi Mu wrote: > what does the following code mean? It is said to be used in the > calculation of the overlaid area size between two polygons. > map(lambda x:b.setdefault(x,[]),a) The equivalent of : def oh_my_yet_another_function_name_why_not_use_lambda(x): b.setdefault(x,[]) map(oh_my_yet_an

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > I am writing a web applications(simple forms) which has a number of > > fields. Each field naturally has a name and a number of > > attributes(formatting etc.), like this : > > > > d = {'a':{...},

Re: Underscores in Python numbers

2005-11-20 Thread [EMAIL PROTECTED]
Peter Hansen wrote: > But why would anyone want to create numeric literals for credit card > numbers? > May be for space saving ? But storage space being so cheap, this is not a very good reason, but still a reason. -- http://mail.python.org/mailman/listinfo/python-list

Re: Underscores in Python numbers

2005-11-20 Thread [EMAIL PROTECTED]
D H wrote: > Steve Holden wrote: > > David M. Cooke wrote: > >> One example I can think of is a large number of float constants used > >> for some math routine. In that case they usually be a full 16 or 17 > >> digits. It'd be handy in that case to split into smaller groups to > >> make it easier

Re: Underscores in Python numbers

2005-11-20 Thread [EMAIL PROTECTED]
Peter Hansen wrote: > [EMAIL PROTECTED] wrote: > > Peter Hansen wrote: > > > >>But why would anyone want to create numeric literals for credit card > >>numbers? > >> > > May be for space saving ? But storage space being so cheap, this is not >

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > but you can easily generate an index when you need it: > > index = dict(d) > > name, type = index["pid"] > print name > > the index should take less than a microsecond to create, and since it > points to the members of the original dict, it doesn't use much memor

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Ben Finney wrote: > Another possibility: ordered dictionaries are not needed when Python > 2.4 has the 'sorted' builtin. > What does sorted() have anythng to do with orders like insertion order, or some arbitary order that instead of a,b,c,d,e, I want it as e, c, b, d, a ? Personally, I have need

Re: about list

2005-11-20 Thread [EMAIL PROTECTED]
try to describe what you want as it is not very obvious, and has syntax error. Shi Mu wrote: > How to run a function to make [1,2,4] become [[1,2],1,4],[2,4]]? > Thanks! -- http://mail.python.org/mailman/listinfo/python-list

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Christoph Zwerschke wrote: > [EMAIL PROTECTED] wrote: > > Personally, I have needs for ordered dict but I don't think it should > > be in standard library though, as different situation called for > > different behaviour for "ordered" and skewing my code

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Alex Martelli wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >... > > there are at least two behaviour. What I need is a "preferred order". > > Say if I have designed a web form(correspond to a database table), I > > just want say 3 fiel

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Peter Hansen wrote: > [EMAIL PROTECTED] wrote: > > Using the same logic, we don't need types other than string in a DBMS > > as we can always convert a string field into some other types when it > > is needed. > > You mean, like SQLite does? (http://www.sqlite.

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > On Sun, 20 Nov 2005 22:03:34 +0100, Christoph Zwerschke <[EMAIL PROTECTED]> > wrote: > >> Ordering the keys isn't the normal case, and can be done easily when > >> needed. > > > >That depends. Maybe I do not want the keys t

Re: Why are there no ordered dictionaries?

2005-11-20 Thread [EMAIL PROTECTED]
Ben Finney wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > [sort by] some other metadata that is not present in the data. > > [...] > > Of course, you may say, just put another column that represent > > this(some reporting programs I have seen do it th

Re: best cumulative sum

2005-11-20 Thread [EMAIL PROTECTED]
Erik Max Francis wrote: > Micah Elliott wrote: > > > On Nov 21, David Isaac wrote: > > > >> What's the good way to produce a cumulative sum? > > > import operator > x = 1,2,3 > reduce(operator.add, x) > > 6 > > Or just sum(x). > He seems to want scanl -- http://mail.python.org/

Re: Why are there no ordered dictionaries?

2005-11-21 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > Fredrik Lundh wrote: > > > but you can easily generate an index when you need it: > > > > > > index = dict(d) > > > > > > name, type = index["pid"] > > >

Re: Why are there no ordered dictionaries?

2005-11-21 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > If I need the dict feature 90% of the time, and the list feature 10% of > > the time. > > Wasn't your use case that you wanted to specify form fields in > a given order (LIST), render a default view of the

unittest can not use function name 'test' ?

2005-11-21 Thread [EMAIL PROTECTED]
Hello I found something strange in my unittest : This code is ok (will report error ): class MyTest1(unittest.TestCase): def runTest(self): self.assertEqual(2,3) pass if __name__ == '__main__': unittest.main() But if I add a function with the first name is 'test' it fa

Re: unittest can not use function name 'test' ?

2005-11-21 Thread [EMAIL PROTECTED]
Thanks Fredrik... pujo -- http://mail.python.org/mailman/listinfo/python-list

tkinter and cygwin

2005-11-21 Thread [EMAIL PROTECTED]
Hi, I've recently started learning python programming and have been experimenting with a few basic GUI programs. My work system is cygwin/Windows XP. I use X-windows in cygwin but when I run my python/tkinter program from an x-win terminal , a normal XP window is opened up. Any text output from

Numeric array in unittest problem

2005-11-21 Thread [EMAIL PROTECTED]
hello, I found that if I use Numeric.array into unittest it is not consistance, Is that normal ? import Numeric class myTest(unittest.TestCase): def runTest(self): a = Numeric.array([1,2]) b = Numeric.array([1,33]) self.assertEqual(a, b) pass This will not raise

Re: Numeric array in unittest problem

2005-11-21 Thread [EMAIL PROTECTED]
Sorry Peter, Try this import unittest import Numeric class myTest(unittest.TestCase): def runTest(self): var1 = Numeric.array([1,22]) var2 = Numeric.array([1,33]) self.assertEqual(var1,var2) if __name__ == '__main__': unittest.main() pujo -- http://ma

Re: running functions

2005-11-21 Thread [EMAIL PROTECTED]
Tom Anderson wrote: > > If you program threads with shared nothing and communication over Queues > > you are, in effect, using processes. If all you share is read-only > > memory, similarly, you are doing "easy" stuff and can get away with it. > > In all other cases you need to know things like "w

Re: mxODBC sql MSAccess

2005-11-21 Thread [EMAIL PROTECTED]
BartlebyScrivener wrote: > Hello, I'm new to python and trying to get records from an MSAccess > database using mxODBC. It works, but the output is not formatted the > way I want it. > > Here's the script: > > import mx.ODBC.Windows as odbc > > driv='DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:

Re: path module / class

2005-11-21 Thread [EMAIL PROTECTED]
Peter Hansen wrote: > Okay, granted. I guess this is the same as in any other case of > deprecation (e.g. some people still have to work with code that uses > apply() or string module methods). Yup, this is exactly what will have to happen. Most or all of os.path and maybe some of os/glob/fnmatc

Re: best cumulative sum

2005-11-22 Thread [EMAIL PROTECTED]
David Isaac wrote: > <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > He seems to want scanl > > Yes. But it's not in Python, right? > (I know about Keller's version.) > > Robert Kern wrote: > > Define better. More accurate? Les

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Magnus Lycka wrote: > sorted_l = l.sort() > > and while sorted_l would contain what one might expect, it > would in fact just be another name referencing exactly the > same sorted list as l, and it would probably be surprising > that l was also sorted, and that subsequent changes would > show up i

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > > so what would an entry-level Python programmer expect from this > > > piece of code? > > > > > > for item in a.reverse(): > > > print item > > > for item in a.revers

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > so what would an entry-level Python programmer expect from this > piece of code? > > for item in a.reverse(): > print item > for item in a.reverse(): > print item > I would expect it to first print a in reverse then a as it was. a=[1,2,3] I expect i

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > Ok, so if not in the standard library, what is the problem? Can't find what > you want with google and PyPI etc.? Or haven't really settled on what your > _requirements_ are? That seems to be the primary problem people who complain > with "why no sprollificator mode?" questi

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Christoph Zwerschke wrote: > Bengt Richter schrieb: > > Ok, so if not in the standard library, what is the problem? Can't find what > > you want with google and PyPI etc.? Or haven't really settled on what your > > _requirements_ are? That seems to be the primary problem people who complain > > wi

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Christoph Zwerschke wrote: > Fredrik Lundh wrote: > > I'll repeat this one last time: for the use cases presented by Zwerschke > > and "bonono", using a list as the master data structure, and creating the > > dictionary on demand, is a lot faster than using a ready-made ordered > > dict implementa

Re: Converting a flat list to a list of tuples

2005-11-22 Thread [EMAIL PROTECTED]
Duncan Booth wrote: > metiu uitem wrote: > > > Say you have a flat list: > > ['a', 1, 'b', 2, 'c', 3] > > > > How do you efficiently get > > [['a', 1], ['b', 2], ['c', 3]] > > That's funny, I thought your subject line said 'list of tuples'. I'll > answer the question in the subject rather than the

Re: Numeric array in unittest problem

2005-11-22 Thread [EMAIL PROTECTED]
Thanks all, I will use alltrue and allclose as Alex and Robert point out.. Cheers, pujo -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting a flat list to a list of tuples

2005-11-22 Thread [EMAIL PROTECTED]
André Malo wrote: > * Duncan Booth <[EMAIL PROTECTED]> wrote: > > > metiu uitem wrote: > > > > > Say you have a flat list: > > > ['a', 1, 'b', 2, 'c', 3] > > > > > > How do you efficiently get > >

Re: How to paste python code on wordpress?

2005-11-22 Thread [EMAIL PROTECTED]
If you're using vim [1] as your editor, or even if you have it installed, you can make use of the 2html.vim script [2] to convert your python code to HTML complete with syntax highlighting. In vim, try running: :run! syntax/2html.vim If you don't want to run vim as your editor, but just want to c

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > so what would an entry-level Python programmer expect from this > > piece of code? > > > > for item in a.reverse(): > > print item > > for item in a.reverse(): > > print item > > > >

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > > Still don't see why even you ask it again. > > fyi, I'm not " [EMAIL PROTECTED] ", and I've > never, as far I know, posted from "readfreenews.net" > I have no idea what you are talking about. I read this list through

interact with application installer prompts using Python

2005-11-22 Thread [EMAIL PROTECTED]
I've written a script that automatically executes a set of Windows installers sequentially. For example, it will install Eudora, Firefox, SpyBot, etc. However, I still have to interact with the installer prompt windows. Is there anyway to programmatically interact with these prompt windows? I want

Comp.Lang.Python Podcase

2005-11-22 Thread [EMAIL PROTECTED]
This is very experimental but here is a http://www.latedecember.com/sites/pythonpod/podcast.xml";>comp.lang.python Podcast. The backend is Python of course via PyTTS. It should be updated daily. Happy Listening! Comments welcome. Davy Mitchell Mood News - BBC News Headlines Auto-Classified as

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > There are four possibilities for a construction like list.sort(): > > (1) sort the list in place and return a reference to the same list; > (2) sort the list in place and return a copy of the same list; > (3) sort the list in place and return None; > (4) don't sort in plac

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
OKB (not okblacke) wrote: > Fredrik Lundh wrote: > > > [EMAIL PROTECTED] wrote: > > > >> > so what would an entry-level Python programmer expect from this > >> > piece of code? > >> > > >> > for item in a.rev

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > On 22 Nov 2005 03:07:47 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > > >Bengt Richter wrote: > >> Ok, so if not in the standard library, what is the problem? Can't find what > >> you want with goo

Re: hex string to hex value

2005-11-22 Thread [EMAIL PROTECTED]
avnit wrote: > If you just want to convert a string to an integer, it would be: > > >>> int(n) That's what the OP tried and it didn't work. BECAUSE you have to tell the int function what base the string is in (even though it has "0x" at the start). >>> int(n,16) 66 > > in your case it would be

Re: Converting a flat list to a list of tuples

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > On Tue, 22 Nov 2005 13:37:06 +0100, =?ISO-8859-1?Q?Andr=E9?= Malo <[EMAIL > PROTECTED]> wrote: > > >* Duncan Booth <[EMAIL PROTECTED]> wrote: > > > >> metiu uitem wrote: > >> > >> > Say you have a flat

Re: hex string to hex value

2005-11-22 Thread [EMAIL PROTECTED]
tim wrote: > but then i get : > > >>> m > 66 > >>> n=int(hex(m)) > Traceback (most recent call last): > File "", line 1, in ? > ValueError: invalid literal for int(): 0x42 > >>> > > what am I missing here ? Avnit's solution was wrong. When converting a string, you must state what base you ar

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Mike Meyer wrote: > [EMAIL PROTECTED] writes: > > I think this is just another (admittedly minor) case of Python's > > designers using Python to enforce some idea of programming > > style purity. > > You say that as if it were a bad thing. > I would say "in

Re: Converting a flat list to a list of tuples

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > On 22 Nov 2005 07:42:31 -0800, "George Sakkis" <[EMAIL PROTECTED]> wrote: > > >"Laurent Rahuel" wrote: > > > >> Hi, > >> > >> newList = zip(aList[::2], aList[1::2]) > >> newList > >> [

Re: best cumulative sum

2005-11-22 Thread [EMAIL PROTECTED]
Michael Spencer wrote: > David Isaac wrote: > for a solution when these are available. > > Something like: > > def cumreduce(func, seq, init = None): > > """Return list of cumulative reductions. > > > > > This can be written more concisely as a generator: > > >>> import operator > >>> de

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-22 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: > IIRC, this was discussednd rejected in an SF bug report. It should not > be a defined behavior for severals reasons: > > * It is not communicative to anyone reading the code that zip(it, it) > is creating a sequence of the form (it0, it1), (it2, it3), .

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-22 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: > > * It is bug-prone -- zip(x,x) behaves differently when x is a sequence > > and when x is an iterator (because of restartability). Don't leave > > landmines for your code maintainers. > > Err thanks for the advice, but they are *my* co

Re: Converting a flat list to a list of tuples

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > On 22 Nov 2005 16:32:25 -0800, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > > > > >Bengt Richter wrote: > >> On 22 Nov 2005 07:42:31 -0800, "George Sakkis" <[EMAIL PROTECTED]> wrote: > >> > >&

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Alex Martelli wrote: > However, since Christoph himself just misclassified C++'s std::map as > "ordered" (it would be "sorted" in this new terminology he's now > introducing), it seems obvious that the terminological confusion is > rife. Many requests and offers in the past for "ordered dictionar

Re: Anyway to clarify this code? (dictionaries)

2005-11-22 Thread [EMAIL PROTECTED]
Mike Meyer wrote: > def my_search(another, keys, x): >return dict([[k, v] for k, v in another.items() if v >= x and k in keys]) > > But then you're looking through all the keys in another, and searching > through keys multiple times, which probably adds up to a lot more > wasted work than inde

Re: Anyway to clarify this code? (dictionaries)

2005-11-22 Thread [EMAIL PROTECTED]
Mike Meyer wrote: > def my_search(another, keys, x): > new = dict() > for k in keys: > if another[k] >= x: > new[k] = another[k] > return new > BTW, this would raise exception if k is not in another. -- http://mail.python.org/mailman/listinfo/python-list

Re: Anyway to clarify this code? (dictionaries)

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > >>> def my_search(another, keys, x): return dict((k,another[k]) for k in > keys if another[k]>x) > ... > >>> my_search(another, 'cb', .3) > {'b': 0.35806602909756235} > >>> my_search(another, 'abcd', .4) > {'a': 0.60649466203365532, 'd': 0.77440643221840166} > Do you

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-22 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: > Well, I do too mostly. On rereading my post, it seems I overreacted > a bit. But the attitude I complained about I think is real, and has > led to more serious flaws like the missing if-then-else expression, > something I use in virtually every piece of

Re: about sort and dictionary

2005-11-22 Thread [EMAIL PROTECTED]
Alex Martelli wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >... > > intuitive seems to be a very subjective matter, depends on once > > background etc :-) > > That's a strong point of Ruby, actually -- allowing an exclamation mark > at the end

Re: Anyway to clarify this code? (dictionaries)

2005-11-22 Thread [EMAIL PROTECTED]
Mike Meyer wrote: > First, remember the warnings about premature optimization. Which is why I said the one-liner(your first one) is clean and clear, and bug free in one go. > > use = set(another) - set(keys) > return dict([[k, another[k]] for k in use if another[k] >= x] > > Though I

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > For me the implication of "sorted" is that there is a sorting algorithm > that can be used to create an ordering from a prior state of order, > whereas "ordered" could be the result of arbitrary permutation, e.g., > manual shuffling, etc. Of course either way, a result can b

What a curious assignment.

2005-11-22 Thread [EMAIL PROTECTED]
[test 1] >>> class A: ...i = 1 ... >>> a = A() >>> A.i 1 >>> a.i 1 >>> A.i = 2 >>> A.i 2 >>> a.i 2 >>> [test2] >>> class A: ...i = 1 ... >>> a = A() >>> A.i 1 >>> a.i 1 >>> a.i = 2 >>> A.i 1 >>> a.i 2 >>> Is there somthing wrong -- http://mail.python.org/mailman/listinfo/python-list

Re: What a curious assignment.

2005-11-22 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote: > [test 1] > >>> class A: > ...i = 1 > ... > >>> a = A() > >>> A.i > 1 > >>> a.i > 1 > >>> A.i = 2 > >>> A.i > 2 > >>> a.i > 2 > >>> > > [tes

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Alex Martelli wrote: > What you can obtain (or anyway easily simulate in terms of effects on a > loop) through an explicit call to the 'sorted' built-in, possibly with a > suitable 'key=' parameter, I would call "sorted" -- exactly because, as > Bengt put it, there IS a sorting algorithm which, et

Re: Why are there no ordered dictionaries?

2005-11-22 Thread [EMAIL PROTECTED]
Alex Martelli wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >... > > But I can also record these changes in a seperate table which then > > becomes a "sorted" case ? > > somedict['x']='y', per se, does no magic callback to

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-22 Thread [EMAIL PROTECTED]
Steven Bethard wrote: > [EMAIL PROTECTED] wrote: > >> > ii. The other problem is easier to explain by example. > >> > Let it=iter([1,2,3,4]). > >> > What is the result of zip(*[it]*2)? > >> > The current answer is: [(1,2),(3,4)], > >

Re: What a curious assignment.

2005-11-23 Thread [EMAIL PROTECTED]
Steven D'Aprano wrote: > [EMAIL PROTECTED] wrote: > > > Is there somthing wrong > > Kids today, don't they learn about inheritence? :-) > > Python's object model is that instances inherit both > methods and attributes from the class (and > supe

Re: Why are there no ordered dictionaries?

2005-11-23 Thread [EMAIL PROTECTED]
Steve Holden wrote: > Perhaps now the answer top your question is more obvious: there is by no > means universal agreement on what an "ordered dictionary" should do. > Given the ease with which Python allows you to implement your chosen > functionality it would be presumptuous of the core develope

Re: sort the list

2005-11-23 Thread [EMAIL PROTECTED]
Peter Otten wrote: > [EMAIL PROTECTED] wrote: > > > Duncan Booth wrote: > >> e.g. it is stable when you reverse the order: > >> > >> >>> lst = [[4,1],[4,2],[9,3],[5,4],[2,5]] > >> >>> list(reversed([ x[-1] for x in sorted([ (x[0],

Re: sort the list

2005-11-23 Thread [EMAIL PROTECTED]
Duncan Booth wrote: > e.g. it is stable when you reverse the order: > > >>> lst = [[4,1],[4,2],[9,3],[5,4],[2,5]] > >>> list(reversed([ x[-1] for x in sorted([ (x[0],x) for x in lst ]) ])) > [[9, 3], [5, 4], [4, 2], [4, 1], [2, 5]] > >>> l1 = list(lst) > >>> l1.sort(key=operator.itemgetter(0), rev

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-23 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > > (Well, ok that is not the end of the world either but it's lack is > > irritating > > as hell, and yes, I know that it is now back in favor.) > > the thing that's in favour is "then-if-else", not "if-then-else". > there it comes :-) -- http://mail.python.org/mailman/li

Re: Converting a flat list to a list of tuples

2005-11-23 Thread [EMAIL PROTECTED]
Bengt Richter wrote: > >it's not only the order that matters, but also the number of items > >read from the source iterators on each iteration. > > > Not sure I understand. > > Are you thinking of something like lines from a file, where there might be > chunky buffering? ISTM that wouldn't matter

Re: about sort and dictionary

2005-11-23 Thread [EMAIL PROTECTED]
Sion Arrowsmith wrote: > 1. sort() in place makes sense in terms of space, and is not >completely unintuitive. > 2. reverse() should do what sort() does. > 3. The inexperienced user is most likely to expect the above >code to print 3 2 1 3 2 1, and is more likely to have >difficulty tr

Re: syntax errors while building pypgsql

2005-11-23 Thread [EMAIL PROTECTED]
Tin Gherdanarra wrote: > [EMAIL PROTECTED] wrote: > > Have you tried apt-get build-dep pypgsql ? > > > > It could be that you lacks the necessary packages to build it. > > funny you'd mention it, I did. pypgsql does not seem to > be an apt-get package, ho

Re: syntax errors while building pypgsql

2005-11-23 Thread [EMAIL PROTECTED]
Have you tried apt-get build-dep pypgsql ? It could be that you lacks the necessary packages to build it. Tin Gherdanarra wrote: > Hallo, > > I'm trying to install pypgsql. However, I get syntax errors > while compiling the C sources. The following excerpt > from pgconnection.h looks a little fun

Re: best cumulative sum

2005-11-23 Thread [EMAIL PROTECTED]
David Isaac wrote: > > Michael Spencer wrote: > > > This can be written more concisely as a generator: > > > <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > If iterable has no elements, I believe the behaviour should be [init], > > t

Re: the PHP ternary operator equivalent on Python

2005-11-23 Thread [EMAIL PROTECTED]
Luis M. Gonzalez wrote: > This could be done easier this way: > > L = [('even','odd')[n%2] for n in range(8)] That is even/odd, his(created to demonstrate the uglies of ternary) has 4 states, zero, -/+ then even/odd. -- http://mail.python.org/mailman/listinfo/python-list

Re: best cumulative sum

2005-11-23 Thread [EMAIL PROTECTED]
David Isaac wrote: > OK, this might do it. But is a generator "better"? > (I assume accuracy is the same, so what about speed?) > I have the slightest idea. So long it works for me and is not too hard to understand and has no obvious speed problem, I don't care too much. I believe in line is in g

Re: defining the behavior of zip(it, it) (WAS: Converting a flatlist...)

2005-11-23 Thread [EMAIL PROTECTED]
yet another :-) Fredrik Lundh wrote: > Steven Bethard wrote: > > > Then why document itertools.izip() as it is? The documentation there is > > explicit enough to know that izip(it, it) will work as intended. Should > > we make the documentation there less explicit to discourage people from > > u

Re: hex string to hex value

2005-11-23 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > Fredrik Lundh's solution works if the hex string starts with "0x" > > that's what "interpret [it] as a Python literal" meant. I know from personal experience that the implications of that someti

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-23 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > maybe it's time to change "equivalent to" to "similar to", to avoid > messing things up for people who reads the mostly informal library > reference as if it were an ISO specification. That is their fault as the library reference is supposed to be "(keep this under your pill

Re: defining the behavior of zip(it, it) (WAS: Converting a flat list...)

2005-11-23 Thread [EMAIL PROTECTED]
Fredrik Lundh wrote: > [EMAIL PROTECTED] wrote: > > > > maybe it's time to change "equivalent to" to "similar to", to avoid > > > messing things up for people who reads the mostly informal library > > > reference as if it were an ISO

wxPython installation issues on Debian

2005-11-23 Thread [EMAIL PROTECTED]
Hi all, I'm trying to install wxPython on Debian using 'apt-get install python-wxgtk2.4.' I've got both Python 2.3 and 2.4 installed with 2.4 set as my default. For whatever reason, wxPython always installs under /usr/lib/python2.3/site-packages. Does anyone know how I can force it to install in

Re: Python as Guido Intended

2005-11-23 Thread [EMAIL PROTECTED]
Mike Meyer wrote: > > I do think that the Python development community believes they do, > > or more accurately, that if someone wants to use a different style, > > they can go use something else. > > In other words, they believe that you should use a screwdriver to > drive screws, and not a hamme

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