Re: Problem of Readability of Python

2007-10-07 Thread Brian Elmegaard
Bruno Desthuilliers [EMAIL PROTECTED] writes: Use dicts, not lists or tuples: a = dict(name='yadda', val=42) print a['name'] print a['val'] I guess you will then need a list or tuple to store the dicts? I might have made it with a list of class instances: class a: def

Re: Floats as keys in dict

2007-08-02 Thread Brian Elmegaard
greg [EMAIL PROTECTED] writes: Be careful with this. If you have two values that are very close together, but on different sides of a rounding boundary, they will end up as distinct keys even though they should be regarded as equal. I don't think this is a big problem. It will only give me

Floats as keys in dict

2007-08-01 Thread Brian Elmegaard
Hi I am making a script to optimiza by dynamic programming. I do not know the vertices and nodes before the calculation, so I have decided to store the nodes I have in play as keys in a dict. However, the dict keys are then floats and I have to round the values of new possible nodes in each

Re: Floats as keys in dict

2007-08-01 Thread Brian Elmegaard
Steve Holden [EMAIL PROTECTED] writes: Alex Martelli wrote: [snip] Thanks a lot for your intersting answers. I will start out taking a look at bisect. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk --

Re: Compile python with Mingw

2007-07-28 Thread Brian Elmegaard
iwinux [EMAIL PROTECTED] writes: To build python with mingw, there is a common way. First you should install msys, which can be downloaded from mingw's website. Run msys and type 'cd /path/to/source'. Then type ./configure make make install. And you will get a python built with mingw. It

Re: emacs shell hangs on W32 with python

2006-11-02 Thread Brian Elmegaard
[EMAIL PROTECTED] writes: Is there any way to run python through emacs or xemacs without having it hang or is shell support broken? Doing it from eshell gives the same problem :-( -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html Rugbyklubben Speed

Dictionary question

2006-07-18 Thread Brian Elmegaard
Hi I have written the following which works, but I would like to write it less clumsy. I have a dictionary in which I loop through the keys for a dynamic programming algorithm. If a key is present I test if its value is better than the current, if it is not present I just create it. Would it be

Re: Dictionary question

2006-07-18 Thread Brian Elmegaard
Brian Elmegaard [EMAIL PROTECTED] writes: At least it was clumsy to post a wrong example. This shows what = find clumsy. c=1 x=2 l=list() l.append(dict()) l[0][5]=0 l.append(dict()) for a, e in l[-2].iteritems(): # Can this be written better? if a+c in l[-1]: if l[-1][a+c

Re: Dictionary question

2006-07-18 Thread Brian Elmegaard
John Machin [EMAIL PROTECTED] writes: 2. Put spaces around operators -- in general, RTFStyleGuide http://www.python.org/dev/peps/pep-0008 I din't know it. Thanks. Only you know what *really* meaningful names you should be using. I have better names in my running code. mykey = a + c

Re: Dictionary question

2006-07-18 Thread Brian Elmegaard
Justin Azoff [EMAIL PROTECTED] writes: last[keytotal] = min(last.get(keytotal), valtotal) comes close to working - it would if you were doing max. Thanks, I think this would help. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html Rugbyklubben Speed

Re: Dictionary question

2006-07-18 Thread Brian Elmegaard
Nick Vatamaniuc [EMAIL PROTECTED] writes: if l[-1].setdefault(a+c, x+e)x+e: l[-1][a+c]=x+e Thanks for the answer. I will try it. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html Rugbyklubben Speed Scandinavian Open 7s Rugby http://www.rkspeed.dk --

Re: MS VC++ Toolkit 2003, where?

2006-04-28 Thread Brian Elmegaard
sturlamolden [EMAIL PROTECTED] writes: I believe MinGW can link .lib C libraries files from Visual Studio. But there are no .a for Python24.dll as far as I can tell. But afaik you don't need one. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html

Re: MS VC++ Toolkit 2003, where?

2006-04-26 Thread Brian Elmegaard
Robert Kern [EMAIL PROTECTED] writes: Martin v. Löwis wrote: Robert Kern wrote: Oh, that's right, you need an import library for Python24.dll . That shouldn't be a problem: that library is included with Python. For mingw, too? I.e. a .a not a .lib? It is possible to load a .dll in

Re: MinGW and Python

2006-04-26 Thread Brian Elmegaard
Neal Becker [EMAIL PROTECTED] writes: release. Since mingw is usually current, I haven't checked, but they may be using 4.1 now. It is not, it is 3.4.2. http://www.mingw.org/download.shtml#hdr2 -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html

Re: MinGW and Python

2006-04-25 Thread Brian Elmegaard
Robert Kern [EMAIL PROTECTED] writes: the gcc project is to provide a portable compiler, not one that generates the best code for any given platform. And in that goal, it succeeds remarkably well. Will a python program be slower on the same machine running windows compared to linux? What I

Re: MinGW and Python

2006-04-25 Thread Brian Elmegaard
Martin v. Löwis [EMAIL PROTECTED] writes: It would certainly be possible to distribute a gcc-compiled python. However, what is the point in doing so? Cygwin already includes a gcc-compiled Python, for Windows: Interesting. That is simply not true. Actually, you answered me then too. I

Re: MinGW and Python

2006-04-25 Thread Brian Elmegaard
Robert Kern [EMAIL PROTECTED] writes: If you meant writing extension modules for Python instead of extending distutils, I thought about extending distutils to make non-python installers. I may have misunderstood the answers I got.

Re: MinGW and Python

2006-04-25 Thread Brian Elmegaard
Fredrik Lundh [EMAIL PROTECTED] writes: a better optimizer usually results in programs that run faster, not slower. Got it the wrong after some editing ;-( -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk --

Re: MinGW and Python

2006-04-24 Thread Brian Elmegaard
Robert Kern [EMAIL PROTECTED] writes: - gcc does not optimize particularly well. But well enough for other platforms. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk -- http://mail.python.org/mailman/listinfo/python-list

Re: Upgrading and modules

2006-04-18 Thread Brian Elmegaard
Lawrence Oluyede [EMAIL PROTECTED] writes: (despite the ongoing Pypi project and Eby's efforts in setuptools) you have to do it manually :) Great, there is progress in this. How many modules do you really use? It's a matter of minutes. Yes, but 60 minutes make an hour. I installed 2.4

Re: Upgrading and modules

2006-04-16 Thread Brian Elmegaard
BartlebyScrivener [EMAIL PROTECTED] writes: Are you saying you're on Windows? Yes http://www.activestate.com/Products/ActivePython/ It's a one-click, msi install with everything you need for win32, including IDE etc. I don't it includes every possible module, e.g., py2exe, ctypes, mysqldb,

Upgrading and modules

2006-04-14 Thread Brian Elmegaard
Hi, Every time I upgrade python I also have to download all packages and reinstall them. http://www.voidspace.org.uk/python/articles/upgrading_python.html tells me that this is only a problem on windows for some reasons that have to do with binary distributions, compiling and more. This leads

Re: Simple questions on use of objects (probably faq)

2006-03-10 Thread Brian Elmegaard
Michael [EMAIL PROTECTED] writes: Based on the code that runs, you want* this: [(y[x+1].x-y[x].x) for x in range(len(y)-1) ] Yes. Since personally I find that a lot clearer than: map(float.__sub__, [X.x for X in y[1:]], [X.x for X in y[:-1] ]) Me too. -- Brian (remove the sport for

Re: Simple questions on use of objects (probably faq)

2006-03-10 Thread Brian Elmegaard
Steven D'Aprano [EMAIL PROTECTED] writes: With this method in the class, your solution is easier than ever: Nice solution. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk --

Re: Simple questions on use of objects (probably faq)

2006-03-10 Thread Brian Elmegaard
bruno at modulix [EMAIL PROTECTED] writes: I should just take some time and learn to read !-) Then I am better of than you. I just had to learn the syntax of a language :-) -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk --

Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
bruno at modulix [EMAIL PROTECTED] writes: So it's time to move to 2.4x !-) I guess so. What is going wrong exactly ? def _add_instance(cls, instance): _add_instance=classmethod(_add_instance) cls._instances.append(instance) gives me: d:/DTU/80494 $ python.exe ooo.py

Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
James Stroud [EMAIL PROTECTED] writes: You should look into __cmp__ and other magic methods. This is probably the type of functionality you seem to be after. Good example, I need to look at the magic methods. What I want is to get the value of another variable in C. Would I need to use

Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
Steven D'Aprano [EMAIL PROTECTED] writes: Can you explain more carefully what you are trying to do? If you want the square of the maximum value, just do this: I want to get the value of another attribute of the instance with maximum x. I know I could do it like you suggest for the case with

Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
Steven D'Aprano [EMAIL PROTECTED] writes: What you probably think you want is something like this: Thanks, that made it run. Now I need to study what classmethods are. I say think you want because I don't know what problem you are trying to solve with this messy, self-referential, piece of

Re: Simple questions on use of objects (probably faq)

2006-03-09 Thread Brian Elmegaard
bruno at modulix [EMAIL PROTECTED] writes: May I suggest that you first learn the language syntax and basics ?-) I'll try -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk -- http://mail.python.org/mailman/listinfo/python-list

Simple questions on use of objects (probably faq)

2006-03-08 Thread Brian Elmegaard
Hi, I am struggling to understand how to really appreciate object orientation. I guess these are FAQ's but I have not been able to find the answers. Maybe my problem is that my style and understanding are influenced by matlab and fortran. I tried with the simple example below and ran into

Re: Simple questions on use of objects (probably faq)

2006-03-08 Thread Brian Elmegaard
Matt Hammond [EMAIL PROTECTED] writes: See List comprehensions in python docs: Great, thanks for the hint. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple questions on use of objects (probably faq)

2006-03-08 Thread Brian Elmegaard
Steven D'Aprano [EMAIL PROTECTED] writes: Thanks for the answers. They are very useful. self.args = (x, y, z) # save a copy of the arguments As always python makes it easy. max(obj.lister()) 4 Actually I wanted to get the maximum of attributes of several instances. List

Re: Simple questions on use of objects (probably faq)

2006-03-08 Thread Brian Elmegaard
Matt Hammond [EMAIL PROTECTED] writes: Hmmm, rereading, I think you're right ... and I think I'm confused too :-) You both are. Attempt #2: yz = [ (y1.x - y2.x) for (y1,y2) in zip(y[:-1], y[1:]) ] Frankly, a for loop with an index would probably be easier to read :) Me too, would

Re: Simple questions on use of objects (probably faq)

2006-03-08 Thread Brian Elmegaard
Matt Hammond [EMAIL PROTECTED] writes: y_max = max([e.x for e in y]) Would there be a way to refer back to the e with maximum x, or how could I find other attributes of it? -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk --

Re: Simple questions on use of objects (probably faq)

2006-03-08 Thread Brian Elmegaard
bruno at modulix [EMAIL PROTECTED] writes: Now how you could do it the OO way (QD, not really tested): Something goes wrong in my 2.3 when I change the syntax to _add_instance=classmethod(_add_instance). If I understand this correctly the class is keeping track of the instances of itself. The

Re: How to get started in GUI Programming?

2005-11-28 Thread Brian Elmegaard
[EMAIL PROTECTED] writes: Others recommended wxPython, PyQt and various derivatives. The trouble is there's too much choice! Agreed, I tried to find /the answer/ some time ago, and I got to the same conclusion. In addition it is even more difficult to find the advantages and disadvantages

Re: Scipy - Latex Annotations in plots

2005-07-08 Thread Brian Elmegaard
Matthias R. [EMAIL PROTECTED] writes: Unfortunately matplotlib is only a 2D-plotting library. Do you know another one with 3D-capabilities as well? That would be very nice, You can quite easily write a function that produces metapost code. Featpost is the best 3d-lib for that, afaik. The

Re: Favorite non-python language trick?

2005-06-30 Thread Brian Elmegaard
Joseph Garvin [EMAIL PROTECTED] writes: I'm curious -- what is everyone's favorite trick from a non-python language? Metapost solution of linear equations: x1+9=x2-8=2; And -- why isn't it in Python? I'd like to know too. -- Brian (remove the sport for mail)

Re: pyqt and Eric 3

2005-04-28 Thread Brian Elmegaard
[EMAIL PROTECTED] writes: http://kscraft.sourceforge.net/convert_xhtml.php?doc=pyqt-windows-install.xhtml Which, afaics, unfortunately requires either that you have msvc or that you compile python and every addon with mingw :-( -- Brian (remove the sport for mail)