Re: Continuous system simulation in Python
Nicholas, Have you looked at Octave? It is not Python, but I believe it can talk to Python. Octave is comparable to Matlab for many things, including having ODE solvers. I have successfully used it to model and simulate simple systems. Complex system would be easy to model as well, provided that you model your dynamic elements with (systems of) differential equations. -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuous system simulation in Python
Nicholas, I have a particular interest in this subject as well. I've also used the Python/Scipy combination, and it is a tantalizing combination, but I found it to be a bit more clumsy than I'd like. Plus, my need for continuous-time simulation is not as great as it has been in the past. That said, I've been down this path before (see http://custom.lab.unb.br/pub/asme/DYNAMICS/BUFORD1.zip), and I would be interested in helping to develop something. I agree that Python would be a great foundation to build upon. -- http://mail.python.org/mailman/listinfo/python-list
Re: HELP: Searching File Manager written in Python
I don't know about Norton Commander either. But, have you looked at twander? http://www.tundraware.com/Software/twander/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Octal notation: severe deprecation
Peter Hansen wrote: > [EMAIL PROTECTED] wrote: > > In Mythical Future Python I would like to be able to use any base in > > integer literals, which would be better. Example random syntax: > > > > flags= 2x00011010101001 > > umask= 8x664 > > answer= 10x42 > > addr= 16x0E84 # 16x == 0x > > gunk= 36x8H6Z9A0X > > I think I kinda like this idea. Allowing arbitrary values, > however, would probably be pointless, as there are very > few bases in common enough use that a language should make > it easy to write literals in any of them. So I think "36x" > is silly, and would suggest limiting this to 2, 8, 10, and > 16. At the very least, a range of 2-16 should be used. > (It would be cute but pointless to allow 1x0. :-) > > -Peter > > > How about base 24 and 60, for hours and minutes/seconds? -- http://mail.python.org/mailman/listinfo/python-list
how to access class methods via their name-as-string
I'd like to be able to look up a method name by passing a string with the method name. I thought I could use self.__dict__ to get at the method names, but as my example shows, this is obviously not working. I've also tried self.__class__.__dict__ without success. Can anyone point me in the right direction to make this work? Thanks, Phil >>> class a: def m1(self): print 'm1' def __getitem__(self, k): return self.__dict__[k] >>> class b(a): def m2(self): print 'm2' >>> z=b() >>> dir(z) ['__doc__', '__getitem__', '__module__', 'm1', 'm2'] >>> z['m1'] Traceback (most recent call last): File "", line 1, in ? z['m1'] File "", line 5, in __getitem__ return self.__dict__[k] KeyError: 'm1' >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggesion for an undergrad final year project in Python
How about a tool that can compute the intersection/union/disjunction of boolean expressions, and return the result as a boolean expression? This is something I've had on my plate for awhile, but haven't been able to get around to doing. As a simple example, assume we have the following expressions: e1 = (y) e2 = ((not x) and (not y)) or ((not x) and (y) and (z)) The union of these two would be ((not x) or (y)). The simplest representation of the result would be best. To make it harder consider the following additional requirements: 1) Instead of just boolean variables, allow variables with more than two discrete values (i.e., True and False). For example, if a variable x can represent the values 1, 2, and 3, then an expression could test for x!=3, or x>1, or even x in [1,3]. 2) Use Python's native data structures to represent expressions. Using the example above, we might have something like this: e1 = [{'y':True}] e2 = [{'x':False, 'y':False}, {'x':False, 'y':True, 'z':True}] How you might extend this to non-boolean expressions would be up to you. 3) Make it fast, and scalable to many variables (up to at least 50). I haven't studied this extensively, but I believe a Quine-McKlusky method is order n^2 with n being the number of variables, so this will quickly blow up as the number of variables increases. 4) As my example in (2) suggested, make variable names strings. This allows arbitrary names. For non-boolean discrete variables, allow any arbitrary list of numbers or strings as elements. 5) Since a side-effect of the program will (probably) be the ability to reduce expressions to their simplest representation, make this capability a part of the public API, since that's a useful function in itself. -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggesting a new feature - "Inverse Generators" -- tangential topic
> The ability to have 'full coroutines', or at least more 'coroutiney > behaviour' than is provided by generators alone, was I think what I was Jordan, This is somewhat off-topic, but perhaps you might be interested in taking a look at the Lua language (http://www.lua.org/). It supports coroutines, and is similar to Python in that it is a dynamically typed language with support for a nice associative dictionary-like data structure. It doesn't cover the same solution space that Python does, but it is an interesting language to play with. Phil Schmidt -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling __init__ with multiple inheritance
What if I want to call other methods as well? Modifying your example a bit, I'd like the reset() method call of Child to invoke both the Mother and Father reset() methods, without referencing them by name, i.e., Mother.reset(self). --- class Mother(object): def __init__(self, p_mother, **more): print "Mother", p_mother, more super(Mother, self).__init__(p_mother=p_mother, **more) def reset(self): print 'resetting Mother' class Father(object): def __init__(self, p_father, **more): print "Father", p_father, more super(Father, self).__init__(p_father=p_father, **more) def reset(self): print 'resetting Father' class Child(Mother, Father): def __init__(self, p_mother, p_father, **more): print "Child", p_mother, p_father, more super(Child, self).__init__(p_mother=p_mother, p_father=p_father, **more) def reset(self): print 'resetting Child' # I would like to invoke both Mother.reset() # and Father.reset() here, but it doesn't work. print 'trying "super"' super(Child, self).reset() # These next two do work, but require referencing # Mother and Father directly. print "calling directly" Mother.reset(self) Father.reset(self) a = Child(1, 2) a.reset() --- Thanks, Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: Cooperative methods, was Re: Calling __init__ with multiple inheritance
Peter Otten wrote: > The problem with that aren't incompatible signatures, but the lack of an > implementation of the reset() method at the top of the diamond-shaped > inheritance graph that does _not_ call the superclass method. That method > could be basically a noop: Ok, now that's cool! Up until now I've been getting along just fine without new-style classes, but that is about to change. Thanks for the tip! Phil -- http://mail.python.org/mailman/listinfo/python-list
Rotating arbitrary sets of elements within a list
I'm trying to come up with a good algorithm to do the following: Given a list 'A' to be operated on, and a list 'I' of indices into 'A', rotate the i'th elements of 'A' left or right by one position. Here's are some examples: A = [a, b, c, d, e, f] I = [0, 3, 4] rotate(A, I, 'left') --> [b, c, d, e, f, a] rotate(A, I, 'right') --> [b, a, c, f, d, e] I = [1, 3, 4] rotate(A, I, 'left') --> [b, a, d, e, c, f] rotate(A, I, 'right') --> [a, c, b, f, d, e] Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Rotating arbitrary sets of elements within a list
[EMAIL PROTECTED] wrote: > I'm trying to come up with a good algorithm to do the following: > > Given a list 'A' to be operated on, and a list 'I' of indices into 'A', > rotate the i'th elements of 'A' left or right by one position. Ok, here's what I've got. It seems to work right, but can it be improved upon? def list_rotate(A, I, direction=1): A1 = [A[i] for i in I] A2 = [A[i] for i in range(len(A)) if i not in I] if direction: I1 = [(i-1)%len(A) for i in I] # rotate left else: I1 = [(i+1)%len(A) for i in I] # rotate right I2 = [i for i in range(len(A)) if i not in I1] for i in range(len(I1)): A[I1[i]] = A1[i] for i in range(len(I2)): A[I2[i]] = A2[i] -- http://mail.python.org/mailman/listinfo/python-list
How to prevent Tkinter frame resize?
I am trying to prevent a user from resizing a frame beyond its "natural" size as given by winfo_reqwidth and winfo_reqheight, without any success. Can anyone make any suggestions, based on my code below? Thanks! from Tkinter import * class Table(Frame): def __init__(self, master, rows=['row 1'], cols=['col 1'], row_labels=True, col_labels=True, row_buttons=True, col_buttons=True): Frame.__init__(self, master) self.rows = rows self.cols = cols self.row_labels = row_labels self.col_labels = col_labels self.row_buttons = row_buttons self.col_buttons = col_buttons self.col_width = 6 self.draw() self.bind('', self.changed) def changed(self, ev): w, h = self.winfo_reqwidth(), self.winfo_reqheight() cfg = {} if ev.height > h: cfg['height'] = h if ev.width > w: cfg['width'] = w if cfg: self.config(**cfg) this has no effect def draw(self): if self.row_labels or self.row_buttons: col = 1 for t in self.cols: if self.row_labels: e = Entry(self, width=self.col_width, relief=GROOVE) e.insert(INSERT, t) e.grid(row=0, column=col+1) if self.row_buttons: e = Label(self, text=col, width=self.col_width, relief=GROOVE,bg='gray', fg='blue') e.grid(row=1, column=col+1) col += 1 if self.col_labels or self.col_buttons: row = 1 for t in self.rows: if self.col_labels: e = Entry(self, width=15, relief=GROOVE) e.insert(INSERT, t) e.grid(row=row+1, column=0) if self.col_buttons: e = Label(self, text=row, width=self.col_width, relief=GROOVE,bg='gray', fg='blue') e.grid(row=row+1, column=1) row += 1 if __name__ == '__main__': top = Tk() cols = ['col %s' % i for i in range(5)] rows = ['row %s' % i for i in range(5)] s = Table(top, rows=rows, cols=cols) s.pack(fill=BOTH, expand=1) mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: python coding contest
Tim Hochberg wrote: > No. I have 8 lines and 175 chars at present. And, I expect that's gonna > get beaten. I wasn't going to get into this, but I couldn't resist :). I'm already behind though... 198 characters on 1 line. It's ugly, but it works. -- http://mail.python.org/mailman/listinfo/python-list
how to use pyparsing for identifiers that start with a constant string
I am scanning text that has identifiers with a constant prefix string followed by alphanumerics and underscores. I can't figure out, using pyparsing, how to match for this. The example expression below seems to be looking for whitespace between the 'atod' and the rest of the identifier. identifier_atod = 'atod' + pp.Word('_' + pp.alphanums) How can I get pyparsing to match 'atodkj45k' and 'atod_asdfaw', but not 'atgdkasdjfhlksj' and 'atod asdf4er', where the first four characters must be 'atod', and not followed by whitespace? Thanks! -- http://mail.python.org/mailman/listinfo/python-list
How to prevent this from happening?
Regarding this expression: 1 << x I had a bug in my code that made x become Very Large - much larger than I had intended. This caused Python, and my PC, to lock up tight as a drum, and it appeared that the Python task (Windows XP) was happily and rapidly consuming all available virtual memory. Presumably, Python was trying to create a really really long integer, just as I had asked it. Is there a way to put a limit on Python, much like there is a stack limit, so that this sort of thing can't get out of hand? -- http://mail.python.org/mailman/listinfo/python-list