Re: [Tutor] Posting a large amount of code?
> Actually according to the above paragraph, he suggests putting them all in > a seperate class. So pseudo-code... > > class Pipe: > All things related to pipe program here. > > class GUI: Exactly so. The rationale for that was that you could work with a collection of pipes each with their own dimensions etc. I forgot to explain that part Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Objects, persistence & getting
> Well, one thing learning Java is good for is for thoroughly > demystifying OOP. I'd have to disagree here because Java's version of OOP has very little to do with real OOP. Java just uss classes as a kind of modularisation mechanism and does not make much use of tthe real OO features. In fact it doesn't even support several of the things that enable real OO programming. And its class library, a strong feature because it is a standard, is dreadful from an OOP p[erspective. In fact I usually refer to Java as a Class Oriented Programming rather than Object Oriented. It is possible to use Java in an OOP way (read Brice Eckel's "Thinking in Java" to see how) but the language itself encourages a style of programming that is much more like Pythons modules than true OOP. > It's not some magical acronym of programming > goodness, it's just an 'organic' way to organise code. Certainly in Java thats true, and indeed even at the higher level OOP is a way of organizing code - by finding high level abstractions and building tree structures based on common intefaces. But Java doesn't encourage that structuring as much as Python does! > If I understand correctly, once an object is created, as long as > references to it exist, it isn't garbage collected. Yes. > Does that make sense? So, foo is floating around in the namespace, and > bar just wants to grab a field of foo. Can it? It shouldn't - it should be sending a message. One of the bad things about Java is it encourages the use of getXXX and setXXX style methods which are a total anathema to real OOP. They break the Law of Demeter. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Fwd: Re: [Tutor] py2exe]
Forgot to forward it to the list... Here it goes: Original Message Subject: Re: [Tutor] py2exe Date: Mon, 17 Jan 2005 05:40:44 -0200 From: Ismael Garrido <[EMAIL PROTECTED]> To: Guillermo Fernandez Castellanos <[EMAIL PROTECTED]> References: <[EMAIL PROTECTED]> <[EMAIL PROTECTED]> Guillermo Fernandez Castellanos wrote: Unfortunatelly, it does not work... I still have the same problem. My setup.py: from distutils.core import setup import py2exe import Tix No, put "import Tix" in openwar.py. The modules you import on setup.py don't get "carried over" to the rest of your code. Bye Ismael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] py2exe
Hi, Thanks for the quick answer. Unfortunatelly, it does not work... I still have the same problem. I though Tix was shipped with the Python distribution. And i have the Tix.pyc file in my computer, so I don't really undesrtand... My setup.py: from distutils.core import setup import py2exe import Tix # To run: # python setup.py py2exe setup(windows=['openwar.py'], name='openwar', version='0.1', description="Openwar unit management program", author="Guille", ) Thanks, Guille On Sun, 16 Jan 2005 23:12:26 -0800 (PST), Chad Crabtree <[EMAIL PROTECTED]> wrote: > Try something like. > import mx > import Tix > > Sometimes py2exe will not gather up all the modules that it depends > on. > It does an admirable job but still needs some help. Perhaps you are > in > advertently using mx? Well try that and see what happens. > > Guillermo Fernandez Castellanos wrote: > > >Hi, > > > > > > > >I've done a GUI program and it works perfectly. > > > > > > > >but when I try to package it with py2exe, I obtain the following > result: > > > >The following modules appear to be missing > > > >['mx'] > > > > > > > >And when i run it, it crashes with this error message: > > > >Traceback (most recent call last): > > > > File "openwar.py", line 41, in ? > > > > File "Tix.pyc", line 210, in __init__ > > > >_tkinter.TclError: can't find package Tix > > > > > > > >I guess the two errors are not related (mx is an optional package to > > > >pysqlite, but you don't *need* it), but I'm surprised there's an > error > > > >due to Tix, a standard package in the python distribution... > specially > > > >that my Python can work with Tix without problems! > > > > > > > >Does anyone have a guess about what's happening? > > > > > > > >Thanks a lot, > > > > > > > >G > > > >___ > > > >Tutor maillist - Tutor@python.org > > > >http://mail.python.org/mailman/listinfo/tutor > > > > > > > > > > > > > __ > Do you Yahoo!? > Yahoo! Mail - Find what you need with new enhanced search. > http://info.mail.yahoo.com/mail_250 > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] py2exe
Try something like. import mx import Tix Sometimes py2exe will not gather up all the modules that it depends on. It does an admirable job but still needs some help. Perhaps you are in advertently using mx? Well try that and see what happens. Guillermo Fernandez Castellanos wrote: >Hi, > > > >I've done a GUI program and it works perfectly. > > > >but when I try to package it with py2exe, I obtain the following result: > >The following modules appear to be missing > >['mx'] > > > >And when i run it, it crashes with this error message: > >Traceback (most recent call last): > > File "openwar.py", line 41, in ? > > File "Tix.pyc", line 210, in __init__ > >_tkinter.TclError: can't find package Tix > > > >I guess the two errors are not related (mx is an optional package to > >pysqlite, but you don't *need* it), but I'm surprised there's an error > >due to Tix, a standard package in the python distribution... specially > >that my Python can work with Tix without problems! > > > >Does anyone have a guess about what's happening? > > > >Thanks a lot, > > > >G > >___ > >Tutor maillist - Tutor@python.org > >http://mail.python.org/mailman/listinfo/tutor > > > > > __ Do you Yahoo!? Yahoo! Mail - Find what you need with new enhanced search. http://info.mail.yahoo.com/mail_250 ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] py2exe
Hi, I've done a GUI program and it works perfectly. but when I try to package it with py2exe, I obtain the following result: The following modules appear to be missing ['mx'] And when i run it, it crashes with this error message: Traceback (most recent call last): File "openwar.py", line 41, in ? File "Tix.pyc", line 210, in __init__ _tkinter.TclError: can't find package Tix I guess the two errors are not related (mx is an optional package to pysqlite, but you don't *need* it), but I'm surprised there's an error due to Tix, a standard package in the python distribution... specially that my Python can work with Tix without problems! Does anyone have a guess about what's happening? Thanks a lot, G ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter Radiobutton
Ismael Garrido wrote: Hello. I can't figure out what's wrong in here! For some reason I can't understand, the radiobuttons don't work. The code itself is correct, the problem arises when I tell them that their master is self.configurar. I don't know why, but they don't like it. After changing this: def _configurar(self): self.configurar = Tk() To this: self.configurar= Toplevel(self.root) Works I don't understand why it didn't work the other way around. Is it some kind of bug or strange 'feature'? Or was I making a silly mistake? Thanks Ismael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] sockets, files, threads
On Sat, 15 Jan 2005, Danny Yoo wrote: > > > > I have only wrapped my lock around file-descriptor creations. Should I > > wrap it around closings too? Or the whole open -> close transaction? > > It sounds like error-prone work to do the latter. What am I missing? > > Hi Marilyn, > > Can you send a link to the source code to the Tutor list? I'm getting the > feeling that there's might be a design problem. Just adding locks > whenever something doesn't work is not a sustainable way to write a > multithreaded application. > > We have to see why your file descriptors being are being shared between > threads. Is there a reason why you need to share them as global > resources? No. And I don't. They are often attributes of instantiations of classes; or they come and go quickly. Thank you for offering to look at the code. Start at: http://www.maildance.com/python/doorman/README Then, the daemon that creates the threads is: http://www.maildance.com/python/doorman/py_daemon.py I'm testing using calls to: http://www.maildance.com/python/doorman/route_mail.py http://www.maildance.com/python/doorman/doorman.py Other modules that open and close file descriptors from there are: http://www.maildance.com/python/doorman/db.py http://www.maildance.com/python/doorman/doorman_log.py http://www.maildance.com/python/doorman/exim.py http://www.maildance.com/python/doorman/move.py I'll be grateful for any improvements you suggest. But, I do know that some modules aren't well-documented, or are hardly documented at all yet. And db.py seems like a mess to me. But I'm not ready to straighten it up yet. But the most important one, py_daemon.py, I hope is very readable. Still though, I should confess, I am feeling a bit dismal about the thread situation, especially since searching around for info on critical code. The examples I found, before I gave up, were all trivial. Also, there is this article: http://linuxgazette.net/107/pai.html Which says that the performance is almost the same with threads as with single-threading. Boo. So suddenly, I have no idea why I'm down this road. We have a huge performance savings from setting up a daemon that reads a socket. But, unless something changes our minds soon, I'll rip threading out of our code. Still though, I am a teacher too, and a student. So any thoughts you have about our code will be treated like the pearls they are. Thank you again. Marilyn > > -- ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tkinter Radiobutton
Quoting Ismael Garrido <[EMAIL PROTECTED]>: > I can't figure out what's wrong in here! For some reason I can't > understand, the radiobuttons don't work. The code itself is correct, the What is the error message? > Button(self.configurar, command=lambda: self._configurarOk(), > text="Ok").grid(row=4, column=0 ) > Button(self.configurar, command=lambda: > self.configurar.destroy(), text="Cancelar").grid(row=4, column=1) An unrelated comment: This would be better as command=self._configurarOK and command=self.configurar.destroy . -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Tkinter Radiobutton
Hello. I can't figure out what's wrong in here! For some reason I can't understand, the radiobuttons don't work. The code itself is correct, the problem arises when I tell them that their master is self.configurar. I don't know why, but they don't like it. Any help is welcome Thanks Ismael def _configurar(self): self.configurar = Tk() self.configurar.title("Configurar") self.opciones = [] textos = ["Tamaño vertical", "Tamaño horizontal", "Tamaño botones"] valores = [self.x, self.y, self.tama] for i in range(3): Label(self.configurar, text=textos[i]).grid(row =i, column = 0) entr= Entry(self.configurar) entr.grid(row = i, column = 1) entr.insert(0, valores[i]) self.opciones.append(entr) self.valor = StringVar() self.valor.set('pibe') Here self.H = Radiobutton(self.configurar, text="Hombre", variable=self.valor, value='pibe') self.H.grid(row=3, column=0) self.M = Radiobutton(self.configurar, text="Mujer", variable=self.valor, value='piba') self.M.grid(row=3, column=1) if self.mensaje == "pibe": self.H.select() else: self.M.select() Button(self.configurar, command=lambda: self._configurarOk(), text="Ok").grid(row=4, column=0 ) Button(self.configurar, command=lambda: self.configurar.destroy(), text="Cancelar").grid(row=4, column=1) def _configurarOk(self): for i in range(self.x): for j in range(self.y): self.botones[i][j].destroy() self.salir.destroy() self.rein.destroy() self.mensaje = self.valor.get() print self.mensaje self.x = int(self.opciones[0].get()) self.y = int(self.opciones[1].get()) self.tama = int(self.opciones[2].get()) self._crearBotones() self.lights.x = self.x self.lights.y = self.y self.lights._hacerTablero() self.lights._llenarTablero() self._updateBotones() self.configurar.destroy() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] How to create a key-value pairs with alternative elements in a list ... please help.
Hi! >>> while True: > ... try: > ... d[slice0.next()] = slice1.next() > ... except: StopIteration > ... break > ... ### while True: try: d[s0.next()] = s1.next() except StopIteration: # wherein we point out a wayward colon break ### Took me a while to figure out why I kept getting error messages about "break": try: something() except YourExceptionHere: something_else() Misplaced colon. Why those sneaky little... Cheers, Pat ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Posting a large amount of code?
> > It would be a god excercise to extract all the p[ipe code into > > a separate class and the GUI methods call those class methods > > to get the work done. THis would allow for a fairly easy port > > to a different GUI or even the creation of a command line > > version, so you could do: Actually according to the above paragraph, he suggests putting them all in a seperate class. So pseudo-code... class Pipe: All things related to pipe program here. class GUI: def __init__(self): self stuff defined etc. def makeGuiStuff(self): connetion = Pipe(initial variables) make gui stuff here put all button events such as calculate(command = connection.calculate) (I told you it was pseudo-code) HTH, Jacob > You're exactly right setText() is a GUI method. I do have the pipe logic all > mixed up with the GUI code. Now that you point it out, most of my methods > don't have a return statement. They are completely dependant on the GUI > and wouldn't function without it. Virtually all the methods act directly upon > the GUI. > > If I'm understanding you correctly, I should have methods more along the > lines of this one (which is in my code now): > > def volCalc(self, ID, length): > """Calculates the volume/gallons of water inside of >the various pipe. > """ > from math import pi > gal = ((ID*.5)**2)*pi*(12*length)/(230.9429931) > return gal > > It does it's 'job', return a result and is not effected by the GUI at all. I > guess you could actually import this function into the interpreter and use it > without problems. But if you tried doing that with the other function above > (galCalc()) it wouldn't work out quite so well > > I'll have to see what I can do to take a step in this direction. It might take > my a little while :-) > > Thank you for your help! > > Bill > > > > > > > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Lights game
Kent's suggestions are great, but I wanted to add two. > Hello list. > > I'd really appreciate any comments, particulary regarding style > corrections. I'm a newbie... > > Thanks! > Ismael > > > import random > import tkMessageBox > from Tkinter import * > > class GUI: > def __init__(self): > self._crearGUI() > > def _crearGUI(self): > self.root = Tk() > self.root.title("Lights") > self.botones = [[0,0,0],[0,0,0],[0,0,0]] > for i in range(3): > for j in range(3): > action = lambda n=i, m=j: self._accion(n,m) > self.botones[i][j] = Button(self.root, height=5, > width=10, command=action) > self.botones[i][j].grid(row=i, column=j, padx= 4, pady=4) > > self._updateBotones() > self.root.mainloop() > > def _accion(self, i, j): > self._click(i, j) > try: > self._checkWin() > except ValueError: > tkMessageBox.showinfo(title = "You won!", message = "You > rock, kid!") > > if True == tkMessageBox.askyesno(title="What shall we do?", > message="Play another?"): > self.root.destroy() > lights.__init__() ## Is this... too ugly? Is there a > beter way? > self.__init__() > else: > self.root.destroy() > def _updateBotones(self): > for i in range(3): > for j in range(3): > if lights.tablero[i][j] == True: > self.botones[i][j].configure(bg="red") > else: > self.botones[i][j].configure(bg="grey") > > def _click(self, i, j): > lights.click(i,j) > self._updateBotones() > > def _checkWin(self): > conteo = 0 > for i in range(3): > for j in range(3): > if lights.tablero[i][j] == True: conteo +=1 if lights.tablero[i][j] == True: can be simplified to if lights.tablero[i][j]: > if conteo == 9: > print "GANO" > raise ValueError > > return > > class Luces: > def __init__(self): > self.tablero = [[0,0,0],[0,0,0],[0,0,0]] > self._hacerTablero() > > def _hacerTablero(self): > for i in range(3): > for j in range(3): > self.tablero[i][j] = not random.randint(0,1) Why use not random.randint(0,1)? If it's random, wouldn't just random.randint(0,1) give the same result? Why get a random number and then immediately return the opposite? It's like resolving to write down heads if you flip tails, and tails if you flip heads when you flip a coin! Why bother? > def _cambiarCelda(self, i, j): > self.tablero[i][j] = not self.tablero[i][j] > > def _descartarNegativos(self, n): > if n < 0: > raise IndexError > return n > > def click(self, i,j): > self._cambiarCelda(i,j) > try: > self._cambiarCelda(self._descartarNegativos(i-1), j) > except IndexError: > pass > try: > self._cambiarCelda(self._descartarNegativos(i+1), j) > except IndexError: > pass > try: > self._cambiarCelda(i, self._descartarNegativos(j-1)) > except IndexError: > pass > try: > self._cambiarCelda(i, self._descartarNegativos(j+1)) > except IndexError: > pass > > if __name__ == '__main__': > lights = Luces() > lightsGUI = GUI() > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Setting the focus to a window
> me in the past 2 days or so), I need to change the focus from the > current window to another window (from Windows Media Player to Audacity > so that the simulated keypress will have an effect). There are a couple of options and its a wee while since I did any deep windows hacking. But I think the functions you need are called something like GetActiveWindow(title), and SetActiveWindow(handle). Theres also SetForegroundWindow... One of the wacky things about Windows is that there are usually about 3 ways to do anything and only one of them actually works the way you expect so you have to experiment a lot! ISTR You can also GetDesktopWindow() and front that get all the child windows which includes most of the running apps. ie You can get the window handle(aka identifier) using the title in the title bar, and then you make it the active window using the handle. However I believe the Windows PostMessage will actually work from the handle directly. But you will need to check the docs, thisis all from very olfd memories! The XP API may even be very different to the Win95 that I used to work on... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Objects, persistence & getting
On Jan 16, 2005, at 21:13, Liam Clarke wrote: If I understand correctly, once an object is created, as long as references to it exist, it isn't garbage collected. Correct, more or less (in the exception case where a references b, b references a but nothing else references either, both are GC'd if the implementation is sound). So, if module a.py creates an instance of class foo, can method bar in module b.py access foo without foo being passed directly to bar? Well, if you don't pass at least a reference to what you want the method/function to act on (assuming bar is not a method of Foo, of course -- or else, you should know that splitting the implementation of a class across multiple files, let alone modules, is a Bad Thing(TM)), how do you expect it to know? Does that make sense? So, foo is floating around in the namespace, and bar just wants to grab a field of foo. Can it? I had a poke around the namespace yesterday, and got lost in hordes of methods that look like __this__, which is ugly. Watch out, you seem to be confusing classes and objects, there. What are you trying to achieve there, exactly? Could you give us an example? -- Max maxnoel_fr at yahoo dot fr -- ICQ #85274019 "Look at you hacker... A pathetic creature of meat and bone, panting and sweating as you run through my corridors... How can you challenge a perfect, immortal machine?" ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Objects, persistence & getting
I'm not sure I understand your question. but if I do, the answer is, sometimes you can do it, but it is rarely a good idea. Liam Clarke wrote: If I understand correctly, once an object is created, as long as references to it exist, it isn't garbage collected. That's right. So, if module a.py creates an instance of class foo, can method bar in module b.py access foo without foo being passed directly to bar? I think you mean, can bar access the instance of foo created in a.py? Probably you can access it. Probably it's not a good idea. Somehow you need to access the reference to a foo that is being kept in a.py. If a.py looks like this: # a.py class foo: pass a_foo = foo() then a_foo is a module-level variable and it is accessible from other modules as a.a_foo: # b.py import a def bar(): print a.a_foo On the other hand, the foo instance might have been created as a local variable in some function that (calls a function that) calls bar(). To access this instance of foo you need to dig around in the stack frames and you would need some information about where the foo was created. This is in general a bad idea... For some examples of how to play with stack frames, search for sys._getframe() in the Python cookbook or in comp.lang.python. The contents of a stack frame are documented in the Language Reference section 3.2. Does that make sense? So, foo is floating around in the namespace, and bar just wants to grab a field of foo. Can it? I had a poke around the namespace yesterday, and got lost in hordes of methods that look like __this__, which is ugly. Although this is probably possible, there aren't very many good reasons for doing it. It's better to just pass a reference to the object to the functions that need it. Kent Regards, Liam Clarke ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Lights game
Ismael Garrido wrote: Kent Johnson wrote: If you make _cambiarCelda() check for out-of-range indices then you could get rid of _descartarNegativos() and clean up click() considerably. def _cambiarCelda(self, i, j): if not (0<=i<3 and 0<=j<3): return Without the 'not' (it was pretty funny to see it do only the wrong moves!) :-D I think the 'not' is correct as I wrote it but a simpler way would be def _cambiarCelda(self, i, j): if 0<=i<3 and 0<=j<3: self.tablero[i][j] = not self.tablero[i][j] Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Objects, persistence & getting
Hi all, Well, one thing learning Java is good for is for thoroughly demystifying OOP. It's not some magical acronym of programming goodness, it's just an 'organic' way to organise code. That, and it looks good on your CV, even if you won't be using it. Like XML. It's got me thinking about object persistence, though, and plotting as to how I can use this for my own nefarious ends. If I understand correctly, once an object is created, as long as references to it exist, it isn't garbage collected. So, if module a.py creates an instance of class foo, can method bar in module b.py access foo without foo being passed directly to bar? Does that make sense? So, foo is floating around in the namespace, and bar just wants to grab a field of foo. Can it? I had a poke around the namespace yesterday, and got lost in hordes of methods that look like __this__, which is ugly. Regards, Liam Clarke -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Posting a large amount of code?
On Sunday 16 January 2005 1:28 pm, Alan Gauld wrote: > Some quick feedback based on a quick scim through. > > It looks like your pipe logic is all mixed up with the GUI vpde. > > It would be a god excercise to extract all the p[ipe code into > a separate class and the GUI methods call those class methods > to get the work done. THis would allow for a fairly easy port > to a different GUI or even the creation of a command line > version, so you could do: > > bash$ pipestats.py --content-weight 15 12 > bash$ pipestats.py --summary 22 1/2 > > If you then put that pipe object in a separate module you > could extend it for future projects... > > Separating all GUI code from the logical functions is > always a good idea. Simply get the GUI to reference an > instance of the pipe(having selected the sizes and passed > them in as constructor values maybe?) > > > def galCalc(self): > > """Displays a running tally of the total gallons for all > >pipe entered into each lineEdit. Recalculates whenever > >the data changes in any of the lineEdits. > > """ > > tmp = [] > > for ins, name, typ, size, weight, ID in self.lineEdits: > > if name != "lineEditTotal": > > length = ins.displayText() > > if length: > > length = int(str(length),10) > > gal = self.volCalc(ID, length) > > tmp.append(gal) > > total = sum(tmp) > > total = "%0.2f" % total > > self.lineEditTotal.setText(total) > > This is just an example, see how both the calculation and the > display of the result(*) are mixed up in the same method? > It would be good to split up the code to have a method > that does the calculation and returns the result and > another that calls the first and puts the result into > the GUI. This may require that you pass more parameters > into the calculation metjods but the gain in separation > is worth it IMHO. > > (*)Not knowing Qt I'm assuming that the setText() is a GUI method! > If it isn't I may be drawing invalid conclusions. Alan, You're exactly right setText() is a GUI method. I do have the pipe logic all mixed up with the GUI code. Now that you point it out, most of my methods don't have a return statement. They are completely dependant on the GUI and wouldn't function without it. Virtually all the methods act directly upon the GUI. If I'm understanding you correctly, I should have methods more along the lines of this one (which is in my code now): def volCalc(self, ID, length): """Calculates the volume/gallons of water inside of the various pipe. """ from math import pi gal = ((ID*.5)**2)*pi*(12*length)/(230.9429931) return gal It does it's 'job', return a result and is not effected by the GUI at all. I guess you could actually import this function into the interpreter and use it without problems. But if you tried doing that with the other function above (galCalc()) it wouldn't work out quite so well I'll have to see what I can do to take a step in this direction. It might take my a little while :-) Thank you for your help! Bill ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Setting the focus to a window
Oops, to the list also. -- Forwarded message -- From: Liam Clarke <[EMAIL PROTECTED]> Date: Mon, 17 Jan 2005 09:49:48 +1300 Subject: Re: [Tutor] Setting the focus to a window To: Orri Ganel <[EMAIL PROTECTED]> Hi Orri, What Alan said earlier in the topic. You want to use the Win32UI API, which Mark Hammond has documented in a book. You can also download his WinPython, which includes some documentation, and a link to a tutorial. http://starship.python.net/crew/skippy/ Regards, Liam Clarke PS the Windows API's are also good for manipulating MS software using COM objects, don't know how Audacity handles COM/ActiveX On Sun, 16 Jan 2005 14:51:07 -0500, Orri Ganel <[EMAIL PROTECTED]> wrote: > Hello all, > > As part of a project I'm working on (see archive of previous emails from > me in the past 2 days or so), I need to change the focus from the > current window to another window (from Windows Media Player to Audacity > so that the simulated keypress will have an effect). I have googled and > looked in the docs and all, and I can't seem to find a way to do this > (at least, not with Windows). I found something that sounds about right > in MacPython, but that doesn't help me . . . Any suggestions on how to > do this are greatly appreciated. > > Thanks in advance, > Orri > > -- > Email: singingxduck AT gmail DOT com > AIM: singingxduck > Programming Python for the fun of it. > > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Posting a large amount of code?
http://www.rafb.net/paste/ is good for when you need to make your code accessible - best of all it formats the code for you. Just copy & paste your code, and distribute the link it gives you. Your 'pasted' code expires after 24 hours though. Regards, Liam Clarke On Sun, 16 Jan 2005 02:39:20 -0500, Bill Burns <[EMAIL PROTECTED]> wrote: > Hello, > > I've been working on a small GUI program (on & off) for a little while now and > I'd love to have the group (or anyone for that matter) take a look at it and > give me some pointers. Since I'm not a programmer and I don't do this > continuously, I don't now if I'm on the right track or not. I'd love to have > some feedback! > > I had originally posted my program to the list back in Nov. 04. > > The post can be found here: > http://aspn.activestate.com/ASPN/Mail/Message/python-Tutor/2230994 > > Since that time it has changed significantly and the amount of code has grown. > The program is now 552 lines long. According to pycount.py, there's 328 lines > of code and the rest are docstrings, other comments and blank lines. > > I guess my question is, would it be acceptable to post this much code to the > list? Maybe this really isn't a lot of code, but it seems like a lot to me, so > I figured I'd ask first. If it is OK, would it be better to post the code in > the body of the message or as an attachment? I would think an attachment > would be better but then maybe attachments are not allowed on the list? > > I've used PyQt and Qt Designer to create this program. The main GUI and one > other dialog were created with Designer and compiled to python with pyuic. > These two separate modules are imported into a third module (the main > program). I'd only send the 'main module' as the other two just contain > auto-generated code from Designer & pyuic. The 'main module' contains > the code I've written. Of course, the program will not run unless you have all > three modules (and PyQt installed). > > I've probably been a little verbose with the comments in the code, but I > figured if I post it and you don't have the GUI to go along with it, you could > still get a feel for what the program is doing? > > Let me know. Comments accepted on or off the list. > > Thanks, > > Bill > ___ > Tutor maillist - Tutor@python.org > http://mail.python.org/mailman/listinfo/tutor > -- 'There is only one basic human right, and that is to do as you damn well please. And with it comes the only basic human duty, to take the consequences. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Setting the focus to a window
Hello all, As part of a project I'm working on (see archive of previous emails from me in the past 2 days or so), I need to change the focus from the current window to another window (from Windows Media Player to Audacity so that the simulated keypress will have an effect). I have googled and looked in the docs and all, and I can't seem to find a way to do this (at least, not with Windows). I found something that sounds about right in MacPython, but that doesn't help me . . . Any suggestions on how to do this are greatly appreciated. Thanks in advance, Orri -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Posting a large amount of code?
Some quick feedback based on a quick scim through. It looks like your pipe logic is all mixed up with the GUI vpde. It would be a god excercise to extract all the p[ipe code into a separate class and the GUI methods call those class methods to get the work done. THis would allow for a fairly easy port to a different GUI or even the creation of a command line version, so you could do: bash$ pipestats.py --content-weight 15 12 bash$ pipestats.py --summary 22 1/2 If you then put that pipe object in a separate module you could extend it for future projects... Separating all GUI code from the logical functions is always a good idea. Simply get the GUI to reference an instance of the pipe(having selected the sizes and passed them in as constructor values maybe?) > def galCalc(self): > """Displays a running tally of the total gallons for all >pipe entered into each lineEdit. Recalculates whenever >the data changes in any of the lineEdits. > """ > tmp = [] > for ins, name, typ, size, weight, ID in self.lineEdits: > if name != "lineEditTotal": > length = ins.displayText() > if length: > length = int(str(length),10) > gal = self.volCalc(ID, length) > tmp.append(gal) > total = sum(tmp) > total = "%0.2f" % total > self.lineEditTotal.setText(total) This is just an example, see how both the calculation and the display of the result(*) are mixed up in the same method? It would be good to split up the code to have a method that does the calculation and returns the result and another that calls the first and puts the result into the GUI. This may require that you pass more parameters into the calculation metjods but the gain in separation is worth it IMHO. (*)Not knowing Qt I'm assuming that the setText() is a GUI method! If it isn't I may be drawing invalid conclusions. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Posting a large amount of code?
On Sunday 16 January 2005 10:53 am, Orri Ganel wrote: > For future reference, you can always post code to paste: > > http://rafb.net/paste/ > > Cheers, > Orri Thanks Orri! I didn't know there was a site like that. I'll check it out and see how it works! Thanks again. Bill ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Posting a large amount of code?
[Bill] > I guess my question is, would it be acceptable to post this much code to > the list? [Alan] > Probably about the limit for posting, but if you can put it on > a web site somewhere and post a URL that would be fine... [Bill] Kent had made the same suggestion as well but alas I have no site I can post to... [Bill] > the body of the message or as an attachment? I would think an attachment > would be better but then maybe attachments are not allowed on the list? [Alan] > Since there are several files attachments would make more sense > but if only posting main.py (How big is it? Is that the 500 lines? > If so its a biggish single module.) then inline is OK. [Bill] Yes, it is the 500+ line module and I've posted it inline in my reply to Kent. Glad to hear that it's OK post since I've already sent it, D'oh! I guess like the try, except idiom says, "It's better to ask for forgiveness, than ask for permission." :-) [Bill] > I've probably been a little verbose with the comments in the code, but I > figured if I post it and you don't have the GUI to go along with it, you > could still get a feel for what the program is doing? [Alan] > That makes sense. [Bill] I'm glad to hear that! Hopefully that's what I've achieved. Thank you for the feedback! Bill ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Posting a large amount of code?
Bill Burns wrote: I accidentally sent my reply to Kent only. So I'm forwarding it to the list. Bill -- Forwarded Message -- Subject: Re: [Tutor] Posting a large amount of code? Date: Sunday 16 January 2005 10:14 am From: Bill Burns <[EMAIL PROTECTED]> To: Kent Johnson <[EMAIL PROTECTED]> [Bill] I guess my question is, would it be acceptable to post this much code to the list? Maybe this really isn't a lot of code, but it seems like a lot to me, so I figured I'd ask first. [Kent] I don't know if there is any convention for how much code is too much to post. If you have a web site you could put it on that is a good alternative. I don't mind if you just post it... [Bill] Thanks for the reply Kent. I don't have a web site so I guess that option is ruled out. So if you don't mind the post (and hopefully nobody else minds) here we go I appreciate all feedback. Thanks, Bill For future reference, you can always post code to paste: http://rafb.net/paste/ Cheers, Orri -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: Sending a command to a program using os.system (was [Tutor]: Using os.popen*() and os.spawn*() to interact with a DOS box)
Kent Johnson wrote: Can you say something about why you want to do this? If you are trying to turn Audacity into a programmable sound processor, you might do better with something that is designed as a library for programmatic use. Googling 'python sound library' gives some promising hints. The Snack Sound Toolkit in particular. http://www.speech.kth.se/snack/ OTOH if what you want is some kind of macro system for Audacity then this won't help. Kent Orri Ganel wrote: I did some googling, and found this in the archives of this mailing list: import os os.system('c:\\abaqus\\5.8-14\\abaqus.exe post') , where post was a command, *not* a file. Now, I tried something similar, since essentially what I wish to be able to do is have Audacity think I typed the 'R' key: os.system(r'c:\progra~1\audacity/audacity.exe R') All this managed to accomplish was Audacity opening (good) and a message from Audacity (not good): ("Could not open file: R" since i had to make it small to fit in the email message comfortably) Any ideas on a) why this didn't work and b) what to do to make something similar work are greatly appreciated. Thanks in advance, Orri -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor Actually, what I want to do is set Audacity up so that it automatically begins recording when a song plays in Windows Media Player (to begin with) and stops when the song is finished playing. I've already figured out how to force it to record and stop when I want to (though in a kind of ugly hackish way)(*), and now I'm working on learning the controls of WMP so I can test things like time left in the song, etc. I dl'ed the WMP 10 SDK but haven't really had a chance to take a thorough look at it yet, so hopefully it'll have what I need. Cheers, Orri (*) class autoRecord: """Uses Audacity(TM) to automatically start recording when a song starts playing in the media player of your choice (including Launch(TM), Realplayer(TM), Quicktime(TM), Musicmatch(TM) and Windows Media Player(TM)). Support for more will be added as input is received. Requirements: - Audacity(TM) for Windows (Mac and/or Linux versions pending) - Python 2.4 or higher - Launch(TM), Realplayer(TM), Quicktime(TM), Musicmatch(TM), or Windows Media Player(TM) - Windows XP Home Edition (Mac/Linux/Windows 95/98/ME/NT pending) """ ## eventually (i hope), autoRecord will do all of the above . . . def __init__(self): import time def record(self): import os, win32api, thread, time thread.start_new_thread(os.system,(r'c:\progra~1\audacity/audacity.exe',)) time.sleep(1) thread.start_new_thread(win32api.keybd_event, (82,1)) ## simulates keypress 'r' (which is audacity's shortcut for recording) thread.start_new_thread(self.stopRecord,()) def stopRecord(self): import time, win32api while wmp.currentMedia.duration: ## doesn't work yet, since I'm still looking into WMP controls pass time.sleep(2) ## makes sure all of the sound is captured by waiting a bit longer win32api.keybd_event(83,1) ## simulates keypress 's' (which is audacity's shortcut for stopping) aR = autoRecord() aR.record() -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Posting a large amount of code?
I accidentally sent my reply to Kent only. So I'm forwarding it to the list. Bill -- Forwarded Message -- Subject: Re: [Tutor] Posting a large amount of code? Date: Sunday 16 January 2005 10:14 am From: Bill Burns <[EMAIL PROTECTED]> To: Kent Johnson <[EMAIL PROTECTED]> [Bill] > I guess my question is, would it be acceptable to post this much code to > the list? Maybe this really isn't a lot of code, but it seems like a lot to > me, so I figured I'd ask first. [Kent] > I don't know if there is any convention for how much code is too much to > post. If you have a web site you could put it on that is a good > alternative. I don't mind if you just post it... [Bill] Thanks for the reply Kent. I don't have a web site so I guess that option is ruled out. So if you don't mind the post (and hopefully nobody else minds) here we go I appreciate all feedback. Thanks, Bill #! /usr/bin/env python """ pipeCalc.py - Calculates various data about HVAC/Plumbing pipe. This program calculates the following data: A). Total volume (US gallons) of water inside the pipe. B). The weight of the water inside the pipe (weight based on 60 F). C). The actual weight of the pipe, itself. The only input required from the user, is a pipe length (in feet). Currently the program works on the following types of pipe: A). Carbon Steel (Standard) B). Carbon Steel (Extra Strong) C). Copper (Type L) D). PVC (Schedule 40) E). PVC (Schedule 80) F). PEX tubing. All of the pipe calculations and totals can be written out to a csv file. After the report is written to disk, the user is given the option to open the report. I've also provided a method to write out the data that is used in making all of the calculations. This method writes to disk a file called PipeData.csv. I built the GUI using QT Designer and pyuic. The GUI is a separate module which is imported into this module. There's also a separate dialog which was created and gets imported in the same manner. The GUI contains a tabbed widget with multiple pages (tabs). Each page corresponds to a specific type of pipe. There are multiple lineEdits on each page, with each lineEdit representing a different size of pipe. The user selects a page representing a certain type of pipe and then enters the pipe length into the lineEdit corresponding to the size they want. The GUI also has a lineEdit separate from the others which displays the total gallons of water. This total is continuously updated as the user enters pipe lengths. The GUI also contains four pushButtons. They are labeled and function as follows: A). Report - after all data is entered, the user clicks this button and the PipeReport is written. A dialog will then popup allowing the report to be opened. B). Pipe Data - writes to disk the pipe specifications that are used to calculate all of the data. A dialog will popup allowing the user to write out the data for *all* pipes or the user has the option to choose any combination of individual pipe(s). C). Clear - clears the user input from all lineEdits. D). Exit - exits the program. I've also provided access to all of the above functions/methods via a popup menu that is shown when the user right-clicks on the form. The dictionary (pipeDict) holds all of the various data pertaining to the pipes. The dict *key* holds the following information (in this order): 0). lineEdit - This is the name of the the lineEdit which corresponds to a specific type and size of pipe as shown on the GUI. The numbering scheme provides the correct sort - Thanks, Bob ;) 1). material type - The type of pipe, I.e., Steel, Copper, Plastic. 2). size - The size designation of the pipe, expressed in inches. 3). weight - The weight of the pipe per foot (LBS). The dict *value* holds the inside diameter of each pipe. This value is used for calculating volume. """ pipeDict = \ { ('lineEdit001','Copper(Type L)','1/2"',.285): .585, ('lineEdit002','Copper(Type L)','3/4"',.455): .83, ('lineEdit003','Copper(Type L)','1"',.655): 1.075, ('lineEdit004','Copper(Type L)','1-1/4"',.884): 1.32, ('lineEdit005','Copper(Type L)','1-1/2"',1.14): 1.565, ('lineEdit006','Copper(Type L)','2"',1.75): 2.055, ('lineEdit007','Copper(Type L)','2-1/2"',2.48): 2.545, ('lineEdit008','Copper(Type L)','3"',3.33): 3.035, ('lineEdit009','Copper(Type L)','3-1/2"',4.29): 3.525, ('lineEdit010','Copper(Type L)','4"',5.38): 4.015, ('lineEdit011','Copper(Type L)','5"',7.61): 5.00, ('lineEdit012','Copper(Type L)','6"',10.2): 5.985, ('lineEdit013','Copper(Type L)','8"',19.3): 7.925, ('lineEdit014','Copper(Type L)','10"',30.1): 9.875, ('lineEdit015','Copper(Type L)','12"',40.4): 11.845, ('lin
Re: [Tutor] Posting a large amount of code?
> I guess my question is, would it be acceptable to post this much code to the > list? Probably about the limit for posting, but if you can put it on a web site somewhere and post a URL that would be fine... > the body of the message or as an attachment? I would think an attachment > would be better but then maybe attachments are not allowed on the list? Since there are several files attachments would make more sense but if only posting main.py (How big is it? Is that the 500 lines? If so its a biggish single module.) then inline is OK. > I've probably been a little verbose with the comments in the code, but I > figured if I post it and you don't have the GUI to go along with it, you could > still get a feel for what the program is doing? That makes sense. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: Sending a command to a program using os.system (was [Tutor]: Using os.popen*() and os.spawn*() to interact with a DOS box)
Can you say something about why you want to do this? If you are trying to turn Audacity into a programmable sound processor, you might do better with something that is designed as a library for programmatic use. Googling 'python sound library' gives some promising hints. The Snack Sound Toolkit in particular. http://www.speech.kth.se/snack/ OTOH if what you want is some kind of macro system for Audacity then this won't help. Kent Orri Ganel wrote: I did some googling, and found this in the archives of this mailing list: import os os.system('c:\\abaqus\\5.8-14\\abaqus.exe post') , where post was a command, *not* a file. Now, I tried something similar, since essentially what I wish to be able to do is have Audacity think I typed the 'R' key: os.system(r'c:\progra~1\audacity/audacity.exe R') All this managed to accomplish was Audacity opening (good) and a message from Audacity (not good): ("Could not open file: R" since i had to make it small to fit in the email message comfortably) Any ideas on a) why this didn't work and b) what to do to make something similar work are greatly appreciated. Thanks in advance, Orri -- Email: singingxduck AT gmail DOT com AIM: singingxduck Programming Python for the fun of it. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Lights game
Nice work overall! A few comments inline... Kent Ismael Garrido wrote: Hello list. I'd really appreciate any comments, particulary regarding style corrections. I'm a newbie... Thanks! Ismael import random import tkMessageBox from Tkinter import * lights is only needed by GUI(), it is a helper class. It would be better style to construct Luces() in GUI.__init__() and save it as an attribute. Then GUI stands by itself - it doesn't rely on a global variable or any outside setup. (You will have to change all accesses of lights to use self.lights) class GUI: def __init__(self): self.lights = Luces() self._crearGUI() def _crearGUI(self): self.root = Tk() self.root.title("Lights") self.botones = [[0,0,0],[0,0,0],[0,0,0]] for i in range(3): for j in range(3): action = lambda n=i, m=j: self._accion(n,m) self.botones[i][j] = Button(self.root, height=5, width=10, command=action) self.botones[i][j].grid(row=i, column=j, padx= 4, pady=4) self._updateBotones() self.root.mainloop() def _accion(self, i, j): self._click(i, j) try: self._checkWin() except ValueError: This is a little strange. I would have _checkWin() return True or False instead of throwing an exception when the user wins! Then you would write if self._checkWin(): tkMessageBox.showinfo(title = "You won!", message = "You rock, kid!") if True == tkMessageBox.askyesno(title="What shall we do?", message="Play another?"): self.root.destroy() lights.__init__() ## Is this... too ugly? Is there a beter way? self.__init__() You could use lights._hacerTablero() self._crearGUI() I agree it is little wierd to call __init__ from another function. Better to have a separate method that does exactly what you want. Then if the requirements of __init__ change you will still be doing the right thing here. Instead of destroying the window, why not just update it? if True == tkMessageBox.askyesno(title="What shall we do?", message="Play another?"): lights._hacerTablero() self._updateBotones() else: self.root.destroy() else: self.root.destroy() def _updateBotones(self): for i in range(3): for j in range(3): if lights.tablero[i][j] == True: self.botones[i][j].configure(bg="red") else: self.botones[i][j].configure(bg="grey") def _click(self, i, j): lights.click(i,j) self._updateBotones() def _checkWin(self): conteo = 0 for i in range(3): for j in range(3): if lights.tablero[i][j] == True: conteo +=1 if conteo == 9: print "GANO" raise ValueError return if conteo == 9: print "GANO" return True else: return False or maybe even just return conteo == 9 class Luces: def __init__(self): self.tablero = [[0,0,0],[0,0,0],[0,0,0]] self._hacerTablero() def _hacerTablero(self): for i in range(3): for j in range(3): self.tablero[i][j] = not random.randint(0,1) def _cambiarCelda(self, i, j): self.tablero[i][j] = not self.tablero[i][j] If you make _cambiarCelda() check for out-of-range indices then you could get rid of _descartarNegativos() and clean up click() considerably. def _cambiarCelda(self, i, j): if not (0<=i<3 and 0<=j<3): return self.tablero[i][j] = not self.tablero[i][j] def click(self, i,j): self._cambiarCelda(i,j) self._cambiarCelda(i-1, j) self._cambiarCelda(i+1, j) self._cambiarCelda(i, j-1) self._cambiarCelda(i, j+1) or if you prefer: def click(self, i,j): for ii, jj in [ (i,j), (i-1, j), (i+1, j), (i, j-1), (i, j+1) ]: self._cambiarCelda(ii, jj) def _descartarNegativos(self, n): if n < 0: raise IndexError return n def click(self, i,j): self._cambiarCelda(i,j) try: self._cambiarCelda(self._descartarNegativos(i-1), j) except IndexError: pass try: self._cambiarCelda(self._descartarNegativos(i+1), j) except IndexError: pass try: self._cambiarCelda(i, self._descartarNegativos(j-1)) except IndexError: pass try: self._cambiarCelda(i, self._descartarNegativos(j+1)) except IndexError: pass if __name__ == '__main__': lights = Luces() Not needed if you make the change I suggest at the top. lightsGUI = GUI() ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor
Re: Sending a command to a program using os.system (was [Tutor]: Usingos.popen*() and os.spawn*() to interact with a DOS box)
> import os > os.system('c:\\abaqus\\5.8-14\\abaqus.exe post') > > , where post was a command, *not* a file. Now, I tried something > similar, since essentially what I wish to be able to do is have Audacity > think I typed the 'R' key: > > os.system(r'c:\progra~1\audacity/audacity.exe R') > > All this managed to accomplish was Audacity opening (good) and a message > from Audacity (not good): os.system() simply executes a command like you would in a dOS box. No magic. Thus is Audacity can do what you want from typing manual commands att a DOS ptrompt then you can use os.system() to replicate that. But if you can't do it from DOS then you can't use os.system() either. You need to look at the Audacity help files to see what options are available both from the command line and as an API to interact with Audacity. Until you know that you can't begin to know how to solve the problem in PYthon. Does Audacity have a mailing list? Why not try asking there what options are available? Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using os.popen*() and os.spawn*() to interact with a dos-box
> Hoo boy . . . Looking at the 'help' of the win32api has left this newbie > hopelessly confused . . . Anyone who knows of a good Win32 tutorial, > please let me know! Frankly, anyone doing anything serious on Win32 in Python should buy Mark Hammond's book. It covers most things to do with Windows and doesn't have too much overlap with the more general Python books. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Faster procedure to filter two lists . Please help
> It's educational to look at the code anyway . Here it is, from > Python's listobject.c: Its been on my list of things to do for a long time. The biggest problem with C code is usually finding the bit you want, unless there is a good roadmap (aka design document) > static int > list_length(PyListObject *a) > { > return a->ob_size; > } > implementation. OTOH, people should be afraid to _write_ C code: it > will bite you every time <0.9 wink>. Yep, having run the maintenance team for a 3.5 milion line project in C/C++ its truly amazing the number of ways you can screw up in C! Its one of the reasons I now use Python and leave the C/Java stuff to others... Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor