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 __init__(self,name,val):
self.name=name
self.val=val

l=list()
l.append(a('yadda',42))
print l[0].name
print l[0].val
  
Is the dict preferable to a list or tuple of class instances?
-- 
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: 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 one more
node. 

Wouldn't the same be possible if I use bisect?

-- 
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


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 step. When profiling I see that the most
time consuming part of my script is rounding.

Is there a faster way than round() or is there a better way to test
than 'in' or should I store the keys in another way than a dict?

tia,
-- 
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: 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
-- 
http://mail.python.org/mailman/listinfo/python-list


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 would be nice if this was the situation. I just tested without
success. Do you say that the instructions in e.g. the first three hits
on http://www.google.com/search?q=python+mingw are no longer relevant?



-- 
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: 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 Scandinavian Open 7s Rugby http://www.rkspeed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


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 possible to write it more compact?

###3
c=1
s=8
x=2

l=list()
l.append(dict())
l[0][5]=0

l.append(dict())

for a, e in l[-2].iteritems():
if a+cs: # Can this improved?
if a+c in l[-1]: #
if l[-1][a+c]x+e: #
l[-1][a+c]=x+e #
else: #
l[-1][a+c]=x+e #
print l
#

tia,
-- 
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
-- 
http://mail.python.org/mailman/listinfo/python-list


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]x+e:
l[-1][a+c]=x+e
else:
l[-1][a+c]=x+e
#

print l


 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 possible to write it more compact?

 ###3
 c=1
 s=8
 x=2

 l=list()
 l.append(dict())
 l[0][5]=0

 l.append(dict())

 for a, e in l[-2].iteritems():
 if a+cs: # Can this improved?
 if a+c in l[-1]: #
 if l[-1][a+c]x+e: #
 l[-1][a+c]=x+e #
 else: #
 l[-1][a+c]=x+e #
 print l
 #

 tia,
 -- 
 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

-- 
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
-- 
http://mail.python.org/mailman/listinfo/python-list


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
 newvalue = x + e
 lastdict = dictlist[-1]
 if mykey not in lastdict or lastdict[mykey]  newvalue:
  lastdict[mykey] = newvalue

Better, thanks.

 4. Add some comments about what you are trying to achieve. What is the
point of keeping the two dicts in a list??? Can't you give them
names, like rawdatadict and maxdict?

It's a dynamic programming problem, so this will contain as many dicts
as hours in the year.

-- 
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
-- 
http://mail.python.org/mailman/listinfo/python-list


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 Scandinavian Open 7s Rugby http://www.rkspeed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


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
-- 
http://mail.python.org/mailman/listinfo/python-list


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
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


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 mingw. 

-- 
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: 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
http://www.rugbyklubben-speed.dk
-- 
http://mail.python.org/mailman/listinfo/python-list


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 don't understand is that it is not possible to distribute a
python compiled with gcc for windows. The main reason I saw in this
thread is that python uses mfc. So python requires api access, I
guess. 

Once I asked about distutils here. The answer was that I had access to
the source so I could just extend it. After messing around I found I
couldn't because I don't have msvc.
-- 
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: 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 misunderstood after reading
http://sebsauvage.net/python/mingw.html.

Is the information on that page not correct? Has it never been? 

 You can build the entire Python interpreter with Cygwin (but you
 don't need to, because there is a precompiled version), and you can
 build extensions for the python.org binary using MingW.

Great, then I tend to agree that there is no reason for building it
with mingw.


-- 
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: 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.
http://groups.google.com/group/comp.lang.python/browse_thread/thread/3f721b5a38fbc2d1/7af1aea19aa187b6?lnk=stq=author%3Aelmegaard+distutilsrnum=1#7af1aea19aa187b6


 mingw for the standard Python distribution. Please see my post in the thread 
 MS
 VC++ Toolkit 2003, where?.

Thanks, I will.
-- 
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: 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
-- 
http://mail.python.org/mailman/listinfo/python-list


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 some days ago. I
then needed ctypes and mySQLdb. Both of them had had some updates in
addition to the version change. What could have been seconds did take
a while because of this. Of course it is because I try to do both
steps in one installation.

-- 
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-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, wxpython...

-- 
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


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 me to the questions:
1: Isn't there a better way? 
2: Why is compilation needed for installation of a package? 
3: Why isn't python backwards compatible so reinstallation is
unneeded?
4: Would it help if python was compiled with gcc/mingw so installation
would be the same as on other systems?
5: What about a package repository and a manager like miktex has?

regards,
-- 
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-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 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-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
-- 
http://mail.python.org/mailman/listinfo/python-list


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
-- 
http://mail.python.org/mailman/listinfo/python-list


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 
Traceback (most recent call last):
  File ooo.py, line 36, in ?
Foo(value)
  File ooo.py, line 6, in __init__
self._add_instance(self)
  File ooo.py, line 9, in _add_instance
_add_instance=classmethod(_add_instance)
UnboundLocalError: local variable '_add_instance' referenced before assignment
d:/DTU/80494 $ 

 Yeps too. This is called encapsulation.

Interesting. 

 Also, if you intend to use such a solution (with or without multiple
 lists), you may want to add a classmethod to delete instances from the
 list(s).

I will have to study classmethods.

-- 
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-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 __repr__ and get the id from it to find xx of the instance with
maximum x? 

class C:
   def __init__(self, x):
 self.x = x
 self.xx = x*x

sees = [C(x) for x in (4,7,1,3,0,9,2)]  # random-ish ints
print max(sees)

-- 
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-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 x*x, but the
other attribute does not depend on x.

 [The above paragraph is always true, except for the exceptions when it is
 not true. You will know when you need id(). If you only *think* you need
 id(), you don't need it.]

:-)

 algorithm relies on object X knowing that it is the 5th item of list L,
 then you must either store that information yourself somewhere, and
 maintain it, or you must change your algorithm. 

OK, I think this is the answer I was looking for.

-- 
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-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 code. If you could
 explain what your goal is, there is probably a better way of reaching it.

Probably, this was just an example posted to show me how to add all
the instances to the class.

-- 
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-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 several questions:
1: Why can't I do:
def __init__(self,self.x):
  and avoid the self.x=x

2: Is it a good idea to insert instances in a list or is there a simpler
way to do something with all instances of a given type?

3: Why canøt I say and get the maximum of instance attributes and a
list of them?  
y_max=max(y[].x) and 
ys=[y[].x]

4: Can I avoid the dummy counter i in the for loop and do something
like: 
yz=[y[:-1].x-y[1:].x]

The code that runs:

class Foo:
def __init__(self,x): 
self.x=x

y=[]
y.append(Foo(10.0))
y.append(Foo(110.0))
y.append(Foo(60.0))

ys=[]
y_max=0.0
y_min=0.0

for s in y:
ys.extend([s.x])
y_max=max(s.x,y_max)
y_min=min(s.x,y_min)

yz=[]
for i in range(len(ys)-1):
yz.append(ys[i+1]-ys[i])

What I hoped I could do:
class Foo:
def __init__(self,self.x): 
continue
y=[]
y.append(Foo(10.0))
y.append(Foo(110.0))
y.append(Foo(60.0))

ys=([y[].x])
y_max=max(y[].x)
y_min=min(y[].x)

yz=[y[:-1].x-y[1:].x]



-- 
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
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 comprehension is the answer.

 method. Do this instead:

 ys.append(s.x)

I always get confused by extend and append.

 this is wasteful. Just call the function at the end, after collecting all
 the values:

Easier indeed.

 for index, value in enumerate(ys[:-1]):
 yz.append(ys[index+1] - value)


I will need to study enumerate a bit.

 By the way, don't be shy about using more meaningful names for variables.
 ys and yz are terribly similar, and is a bug waiting to happen.

I know, and in the real code I use better names.

 You can't use continue in there, it isn't a null-op. Perhaps you wanted
 pass?

Yes.

 yz=[y[:-1].x-y[1:].x]

 How about, before trying to invent short cuts, you actually learn some of
 the Python syntax? The [x:y] syntax already has a meaning to Python,
 just not what you want.

Perhaps it is not the same, but quite close. In matlab .* is
element-by-element multiplication. I was thinking about a .-
operator. wouldn't that make sense here?

 Also, while everything in Python is an object, you don't *have* to use
 object oriented techniques. 

In the real problem the class is:
class Stream:
def __init__(self,T_start,T_end,Q_dot):
self.T_start=T_start
self.T_end=T_end
self.Q_dot=Q_dot
self.mcp=abs(Q_dot/(T_start-T_end))
if T_startT_end:
self.type='hot'
else:
self.type='cold'

and I thought it would make sense to store this a objects. Otherwise I
would need to store each stream as a list is refer their indexes. 


-- 
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
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 that be what I already had?

-- 
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
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
-- 
http://mail.python.org/mailman/listinfo/python-list


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 class is extendible and has all the needed
methods. This means that any global lists can be
avoided. Interesting. 

-- 
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: 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 of the different toolkits. 

My main reasons for choosing wxpython (but never really try to do
something useful with it) was the native look-and-feel on different
platforms and the many different examples, and the demo application
pysketch. 

Unfortunately, even wxpython supports two or three ways of doing
drawings on a canvas, and not that many examples were available for
this. 

In addition pyqt should be great, I read. So i have been waiting for
trolltech to release qt4 and just saw that they have. pyqt is not
updated yet.

 One development is that my local public library has, to my surprise,
 managed to locate a copy of 'Python and Tkinter Programming' by J.
 Grayson.  I've not read it yet, and an initial flick through
 doesn't look too promising but maybe I am mistaken..  

I had the same experience with it. I got more from
http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf. 

-- 
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: 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 good thing is that you get plot that work in both latex and
pdflatex and integrates completely with latex text.

-- 
Brian (remove the sport for mail)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
-- 
http://mail.python.org/mailman/listinfo/python-list


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)
http://www.et.web.mek.dtu.dk/Staff/be/be.html
-- 
http://mail.python.org/mailman/listinfo/python-list


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)
http://www.et.dtu.dk/staff/be/be.html
-- 
http://mail.python.org/mailman/listinfo/python-list