Re: [Tutor] Learning about callbaks
Greetings, my master. I think you need to strip back and simplify, it looks like you may have been reading too many different resources and incorporated some ideas without really understanding what they do and why. I'm humbled by your insight. This is absolutely true. I did some research, reading and test last night and I finally got it working. There was a missing bit that I needed to understand, and suddenly I saw the light. :-) In a manner of speaking. I wrote this piece of code: class UserInput: def __init__(self): pass def test_callback(self, this_callback): print testing the callback this_callback class Game: def __init__(self): self.ui = UserInput() def hello(self): print hello world def useUI(self): self.ui.test_callback(self.hello()) g = Game() g.useUI() I wanted to understand how a parent object could send a callback to a child object, and now I got it. Feel free to comment on this, please. Thank you for your patience, Alan. -- Med venlig hilsen/Kind regards Michael B. Arp Sørensen Programmør / BOFH I am /root and if you see me laughing you better have a backup. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning about callbaks
Michael Bernhard Arp Sørensen [EMAIL PROTECTED] wrote I did some research, reading and test last night and I finally got it working. Sorry, but you didn't! However you are very nearly there... class UserInput: def __init__(self): pass def test_callback(self, this_callback): print testing the callback this_callback To actually use the callback you need to use parens: this_callback() But this won't work because of the problem below... class Game: def __init__(self): self.ui = UserInput() def hello(self): print hello world def useUI(self): self.ui.test_callback(self.hello()) Here you do not pass the function object to your test_callback function, you actually call it here! You bneed to pass the function as an object then call it in the receiver self.ui.test_callback(self, self.hello) # no parens means treat as object What you have done is executed the function(which prints the message thus leading you to think it has worked) and passes the return vaklue(None) to your test_callback. But since you never actually call the function there (missing parens) there is no error message. You can prove this by inserting a raw_input statement into your test_callback before you use the callback. That way the message should only appear after you hit return... I wanted to understand how a parent object could send a callback to a child object, and now I got it. Nearly. You apply the parens when you want to execute the function you omit parens when you want to treat the function as an object. You need to swap your use of parens. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning about callbaks
Hi again. On Jan 2, 2008 2:25 PM, Alan Gauld [EMAIL PROTECTED] wrote: I did some research, reading and test last night and I finally got it working. Sorry, but you didn't! However you are very nearly there... Darn. :-( I've read what to wrote about the *parentheses*. I see why I was wrong in my premature assumption. but I fail to understand why it did work. Anyway, I removed the parentheses from the game method and added it in the userinput method. It still works. Do I dare say that I'm there now? :-) Thanks a lot for this test of my humility and for your effort. -- Med venlig hilsen/Kind regards Michael B. Arp Sørensen Programmør / BOFH I am /root and if you see me laughing you better have a backup. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Choice of GUI builders
Hello all, I've been using PythonCard to build a GUI for a simple program I'm trying to write. It's simple and easy to use, and rather intuitive. However, it seems that it hasn't been updated in some time, and so I would like a recommendation for a cross-platform (preferably) GUI builder. I'm leaning towards wxPython so far (it's had a recent release just a month or so ago), but if anyone has any suggestions, that'd be great. Thanks in advance, Roy Chen ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] need a way to get my own ip address
Greetings, i am looking for an easy way to get my own ip address as a string from python. I am using Ubuntu Linux if that makes any difference. thanks ! shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need a way to get my own ip address
You could perhaps use this method import socket myIP = socket.gethostbyaddr(socket.gethostname())[2] Jay On Jan 2, 2008 8:25 AM, shawn bright [EMAIL PROTECTED] wrote: Greetings, i am looking for an easy way to get my own ip address as a string from python. I am using Ubuntu Linux if that makes any difference. thanks ! shawn ___ 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] need a way to get my own ip address
Thanks, Jay, in IDLE, this gave me 127.0.0.1 is there a way to get my assigned ip instead of the localhost one? thanks On Jan 2, 2008 8:31 AM, jay [EMAIL PROTECTED] wrote: You could perhaps use this method import socket myIP = socket.gethostbyaddr(socket.gethostname())[2] Jay On Jan 2, 2008 8:25 AM, shawn bright [EMAIL PROTECTED] wrote: Greetings, i am looking for an easy way to get my own ip address as a string from python. I am using Ubuntu Linux if that makes any difference. thanks ! shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ 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] need a way to get my own ip address
Well that will return the reverse lookup of the current hostname assigned to your system. Is this a Windows or Linux/Unix system? What does this return? print socket.gethostname() print socket.gethostbyaddr(socket.gethostname()) j On Jan 2, 2008 8:45 AM, shawn bright [EMAIL PROTECTED] wrote: Thanks, Jay, in IDLE, this gave me 127.0.0.1 is there a way to get my assigned ip instead of the localhost one? thanks On Jan 2, 2008 8:31 AM, jay [EMAIL PROTECTED] wrote: You could perhaps use this method import socket myIP = socket.gethostbyaddr(socket.gethostname())[2] Jay On Jan 2, 2008 8:25 AM, shawn bright [EMAIL PROTECTED] wrote: Greetings, i am looking for an easy way to get my own ip address as a string from python. I am using Ubuntu Linux if that makes any difference. thanks ! shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ 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] Choice of GUI builders
While some people are Adobe haters(They hate the web...etc), I think a slick alternative available now is Flex2 calling python via XMLRPC. I've been doing so lately. It is fast to pick up and makes slick looking GUI's rather quickly. It has a cheap GUI builder that actually works if you don't feel like just typing out MXML files. You can use Apollo to do desktop apps and just Flex to do web apps, and all the controls are the same. (The difference is a build setting and a change to a couple tags, and voila, desktop app is on the web or vice versa). Bruce Eckel (the thinking in Java Guy) has written an article on this Approach: http://www.artima.com/weblogs/viewpost.jsp?thread=208528 The ActionScript module I'm currently using for XMLRPC: http://code.google.com/p/as3python-xmlrpc-lib/ You don't really need to know any ActionScript to do this. Very little is required to marshal data in and out of the controls. Other then that, everything is python! Flex is open source now, so you even have that going for you. And it's actively maintained (and updated) by Adobe. The install on a client computer is easier than with wxPython as the GUI toolkit, and I've done several wxPython apps that needed installers. The python back end to all this is SimpleXMLRPCServer, which is also, very easy to use. Exceptions even work well (a big surprise for me). And the fact this approach is cross platform, for platform being defined as Windows, Linux, Mac, Firefox, IE6, IE7 and Opera, makes this a great choice for a easy UI toolkit. --Michael On Jan 2, 2008 9:08 AM, Roy Chen [EMAIL PROTECTED] wrote: Hello all, I've been using PythonCard to build a GUI for a simple program I'm trying to write. It's simple and easy to use, and rather intuitive. However, it seems that it hasn't been updated in some time, and so I would like a recommendation for a cross-platform (preferably) GUI builder. I'm leaning towards wxPython so far (it's had a recent release just a month or so ago), but if anyone has any suggestions, that'd be great. Thanks in advance, Roy Chen ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor -- Michael Langford Phone: 404-386-0495 Consulting: http://www.RowdyLabs.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] need a way to get my own ip address
It returns this ('hostname', [], ['127.0.1.1']) i am running this on a linux system thanks On Jan 2, 2008 8:50 AM, jay [EMAIL PROTECTED] wrote: Well that will return the reverse lookup of the current hostname assigned to your system. Is this a Windows or Linux/Unix system? What does this return? print socket.gethostname() print socket.gethostbyaddr(socket.gethostname ()) j On Jan 2, 2008 8:45 AM, shawn bright [EMAIL PROTECTED] wrote: Thanks, Jay, in IDLE, this gave me 127.0.0.1 is there a way to get my assigned ip instead of the localhost one? thanks On Jan 2, 2008 8:31 AM, jay [EMAIL PROTECTED] wrote: You could perhaps use this method import socket myIP = socket.gethostbyaddr(socket.gethostname())[2] Jay On Jan 2, 2008 8:25 AM, shawn bright [EMAIL PROTECTED] wrote: Greetings, i am looking for an easy way to get my own ip address as a string from python. I am using Ubuntu Linux if that makes any difference. thanks ! shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ 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] need a way to get my own ip address
Well that is what I normally use, but I always have my hostname setup properly. In your case, that socket call won't work. You could try this link I found on google http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439094 jay On Jan 2, 2008 9:00 AM, shawn bright [EMAIL PROTECTED] wrote: It returns this ('hostname', [], ['127.0.1.1']) i am running this on a linux system thanks On Jan 2, 2008 8:50 AM, jay [EMAIL PROTECTED] wrote: Well that will return the reverse lookup of the current hostname assigned to your system. Is this a Windows or Linux/Unix system? What does this return? print socket.gethostname() print socket.gethostbyaddr(socket.gethostname ()) j On Jan 2, 2008 8:45 AM, shawn bright [EMAIL PROTECTED] wrote: Thanks, Jay, in IDLE, this gave me 127.0.0.1 is there a way to get my assigned ip instead of the localhost one? thanks On Jan 2, 2008 8:31 AM, jay [EMAIL PROTECTED] wrote: You could perhaps use this method import socket myIP = socket.gethostbyaddr(socket.gethostname())[2] Jay On Jan 2, 2008 8:25 AM, shawn bright [EMAIL PROTECTED] wrote: Greetings, i am looking for an easy way to get my own ip address as a string from python. I am using Ubuntu Linux if that makes any difference. thanks ! shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ 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] need a way to get my own ip address
Thanks, Jay, just what i was looking for. Works great. shawn On Jan 2, 2008 9:10 AM, jay [EMAIL PROTECTED] wrote: Well that is what I normally use, but I always have my hostname setup properly. In your case, that socket call won't work. You could try this link I found on google http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/439094 jay On Jan 2, 2008 9:00 AM, shawn bright [EMAIL PROTECTED] wrote: It returns this ('hostname', [], [' 127.0.1.1']) i am running this on a linux system thanks On Jan 2, 2008 8:50 AM, jay [EMAIL PROTECTED] wrote: Well that will return the reverse lookup of the current hostname assigned to your system. Is this a Windows or Linux/Unix system? What does this return? print socket.gethostname() print socket.gethostbyaddr(socket.gethostname ()) j On Jan 2, 2008 8:45 AM, shawn bright [EMAIL PROTECTED] wrote: Thanks, Jay, in IDLE, this gave me 127.0.0.1 is there a way to get my assigned ip instead of the localhost one? thanks On Jan 2, 2008 8:31 AM, jay [EMAIL PROTECTED] wrote: You could perhaps use this method import socket myIP = socket.gethostbyaddr(socket.gethostname())[2] Jay On Jan 2, 2008 8:25 AM, shawn bright [EMAIL PROTECTED] wrote: Greetings, i am looking for an easy way to get my own ip address as a string from python. I am using Ubuntu Linux if that makes any difference. thanks ! shawn ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ 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] Learning about callbaks
Michael Bernhard Arp Sørensen [EMAIL PROTECTED] wrote I've read what to wrote about the *parentheses*. I see why I was wrong in my premature assumption. but I fail to understand why it did work. I suspect that if you look closely you'll find that the testing print statement came after the hello world rather than before it. def test_callback(self, this_callback): print testing the callback this_callback Anyway, I removed the parentheses from the game method and added it in the userinput method. It still works. Do I dare say that I'm there now? :-) I hope so, and it should now display the testing message before the hello message. As to whether you are there yet that really depends on whether you are comfortable that you understand the concept clearly. Can you modify the program *without modifying the classes* to use an ordinary function as the callback? Say this goodbye function: def goodbye(): print goodbye world This should not require more than 5 lines of new code and no changes to the existing code. It could be done in 3... If you succeed then I'll be happy that you've grasped it. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Choice of GUI builders
On Wednesday 02 January 2008 06:56:54 am Michael Langford wrote: While some people are Adobe haters(They hate the web...etc), I think a slick alternative available now is Flex2 calling python via XMLRPC. I've been doing so lately. It is fast to pick up and makes slick looking GUI's rather quickly. It has a cheap GUI builder that actually works if you don't feel like just typing out MXML files. You can use Apollo to do desktop apps and just Flex to do web apps, and all the controls are the same. (The difference is a build setting and a change to a couple tags, and voila, desktop app is on the web or vice versa). Bruce Eckel (the thinking in Java Guy) has written an article on this Approach: http://www.artima.com/weblogs/viewpost.jsp?thread=208528 The ActionScript module I'm currently using for XMLRPC: http://code.google.com/p/as3python-xmlrpc-lib/ You don't really need to know any ActionScript to do this. Very little is required to marshal data in and out of the controls. Other then that, everything is python! Flex is open source now, so you even have that going for you. And it's actively maintained (and updated) by Adobe. The install on a client computer is easier than with wxPython as the GUI toolkit, and I've done several wxPython apps that needed installers. The python back end to all this is SimpleXMLRPCServer, which is also, very easy to use. Exceptions even work well (a big surprise for me). And the fact this approach is cross platform, for platform being defined as Windows, Linux, Mac, Firefox, IE6, IE7 and Opera, makes this a great choice for a easy UI toolkit. --Michael I have been very interested in the Flex solution. Mostly because it supports both desktops and the web. I use Dabo for my UI solution and found it covers most everything I need at the moment. But I have real concerns regarding data access using Flex. Flex is asynchronous and most desktop data app's are synchronous when it comes to accessing data. All I have been doing is reading about Flex so maybe there is a solution I am not aware of. It sounds like you are working with Flex - is there a solution? -- John Fabiani ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Choice of GUI builders
johnf [EMAIL PROTECTED] wrote On Wednesday 02 January 2008 06:08:10 am Roy Chen wrote: Hello all, I've been using PythonCard ... However, it seems that it hasn't been updated in some time, and so I would like a recommendation for a cross-platform (preferably) GUI builder. I tried to fined a decent GUI builder for wxPython but failed. There are two or three available but none of them really worked all that well. SPE seemed the best of a poor bunch. However... Take a look at Dabo www.dabodev.com This looked promising but doesn't use the standard wxPython widget set (this was also why I didn't choose PythonCard!), you have to learn the Dabo API. But coming from PythonCard you would have to learn the wxPython API anyway so that may not be an issue for you. Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Choice of GUI builders
On Wednesday 02 January 2008 09:41:46 am Alan Gauld wrote: I tried to fined a decent GUI builder for wxPython but failed. There are two or three available but none of them really worked all that well. SPE seemed the best of a poor bunch. However... Take a look at Dabo www.dabodev.com This looked promising but doesn't use the standard wxPython widget set (this was also why I didn't choose PythonCard!), you have to learn the Dabo API. But coming from PythonCard you would have to learn the wxPython API anyway so that may not be an issue for you. Alan G. Dabo does use slightly different names (in most cases) but is nothing more than subclasses of the wxPython. And of course Dabo does nothing to prevent the programmer from using wxPython directly. The work is learning how to use the subclasses with all of the added properties and attributes. -- John Fabiani ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Choice of GUI builders
On Wednesday 02 January 2008 06:08:10 am Roy Chen wrote: Hello all, I've been using PythonCard to build a GUI for a simple program I'm trying to write. It's simple and easy to use, and rather intuitive. However, it seems that it hasn't been updated in some time, and so I would like a recommendation for a cross-platform (preferably) GUI builder. I'm leaning towards wxPython so far (it's had a recent release just a month or so ago), but if anyone has any suggestions, that'd be great. Thanks in advance, Roy Chen Take a look at Dabo www.dabodev.com and check the screencasts -- John Fabiani ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] providing a Python command line within a Tkinter appl
eval will seriously limit you in this instance because eval only works on expressions, not statements. (Assignment won't work, for example). You can use exec though. (in which case, you wouldn't necessarily want a result back) just fyi text =my_get_pythoncommand() # text is the line of text entered in the window by the user try: result=eval(text) my_print_pythoncommand_result(result) # echoing the result of the command back to the user except error1: some error message except error2: some other error message except error3: ... etc ... except: some generic error message for unrecognised errors The question is does this make sense or is there an easier way, particularly one where I'd be able to get the same error messages provided by the command line python interpreter? I guess the other question I have is if this the way to go, are there any gotchas re the Python code I can execute in this way. Remember I am trying to provide a means of doing analyses that are not provided by the framework so it would nice to just say to the user Enter anything that is valid Python ... just like in the Python interpreter or IDLE. Prof Garry Willgoose, Australian Professorial Fellow in Environmental Engineering, Director, Centre for Climate Impact Management (C2IM), School of Engineering, The University of Newcastle, Callaghan, 2308 Australia. Centre webpage: www.c2im.org.au Phone: (International) +61 2 4921 6050 (Tues-Fri AM); +61 2 6545 9574 (Fri PM-Mon) FAX: (International) +61 2 4921 6991 (Uni); +61 2 6545 9574 (personal and Telluric) Env. Engg. Secretary: (International) +61 2 4921 6042 email: [EMAIL PROTECTED]; [EMAIL PROTECTED] email-for-life: [EMAIL PROTECTED] personal webpage: www.telluricresearch.com/garry Do not go where the path may lead, go instead where there is no path and leave a trail Ralph Waldo Emerson ___ 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] Learning about callbaks
Hi. On Jan 2, 2008 6:36 PM, Alan Gauld [EMAIL PROTECTED] wrote: Can you modify the program *without modifying the classes* to use an ordinary function as the callback? Say this goodbye function: def goodbye(): print goodbye world This should not require more than 5 lines of new code and no changes to the existing code. It could be done in 3... Like this?: class UserInput: def __init__(self): pass def test_callback(self, this_callback): print testing the callback this_callback() class Game: def __init__(self): self.ui = UserInput() def hello(self): print hello world def useUI(self): self.ui.test_callback(self.hello) def goodbye(): print goodbye world g = Game() g.useUI() g.ui.test_callback(goodbye) It took me a couple of minutes to understand your challenge. :-) Then I remembered that ui is instantiated inside g and therefore callable with the right parameter. Thank you very, very much. I enjoy a good challenge. -- Med venlig hilsen/Kind regards Michael B. Arp Sørensen Programmør / BOFH I am /root and if you see me laughing you better have a backup. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Learning about callbaks
Yes, exactly like that. Well done, you are now callback aware :-) Alan G. - Original Message From: Michael Bernhard Arp Sørensen [EMAIL PROTECTED] To: Alan Gauld [EMAIL PROTECTED] Cc: tutor@python.org Sent: Wednesday, 2 January, 2008 8:19:23 PM Subject: Re: [Tutor] Learning about callbaks Hi. On Jan 2, 2008 6:36 PM, Alan Gauld [EMAIL PROTECTED] wrote: Can you modify the program *without modifying the classes* to use an ordinary function as the callback? Say this goodbye function: def goodbye(): print goodbye world This should not require more than 5 lines of new code and no changes to the existing code. It could be done in 3... Like this?: class UserInput: def __init__(self): pass def test_callback(self, this_callback): print testing the callback this_callback() class Game: def __init__(self): self.ui = UserInput() def hello(self): print hello world def useUI(self): self.ui.test_callback(self.hello) def goodbye(): print goodbye world g = Game() g.useUI() g.ui.test_callback(goodbye) It took me a couple of minutes to understand your challenge. :-) Then I remembered that ui is instantiated inside g and therefore callable with the right parameter. Thank you very, very much. I enjoy a good challenge. -- Med venlig hilsen/Kind regards Michael B. Arp Sørensen Programmør / BOFH I am /root and if you see me laughing you better have a backup. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Choice of GUI builders
Thanks for all the help, Dabo looks interesting, but perhaps a bit overkill right now for what I have in mind. Certainly something useful to learn in the long run, though. I suppose with any GUI toolkit/builder, you're going to have learn some part of the API anyway. I might just see how I go with wxPython for now. Best regards, Roy On Jan 3, 2008 2:58 AM, johnf [EMAIL PROTECTED] wrote: On Wednesday 02 January 2008 09:41:46 am Alan Gauld wrote: I tried to fined a decent GUI builder for wxPython but failed. There are two or three available but none of them really worked all that well. SPE seemed the best of a poor bunch. However... Take a look at Dabo www.dabodev.com This looked promising but doesn't use the standard wxPython widget set (this was also why I didn't choose PythonCard!), you have to learn the Dabo API. But coming from PythonCard you would have to learn the wxPython API anyway so that may not be an issue for you. Alan G. Dabo does use slightly different names (in most cases) but is nothing more than subclasses of the wxPython. And of course Dabo does nothing to prevent the programmer from using wxPython directly. The work is learning how to use the subclasses with all of the added properties and attributes. -- John Fabiani ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] is it legal to have a class within a def
def someMethod(): class MyClass(object): . if something: . return someval -- John Fabiani ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] is it legal to have a class within a def
johnf wrote: def someMethod(): class MyClass(object): . if something: . return someval Legal? Well the police won't come after you! Python allows a class statement anywhere. So this use is part of the language. So the question becomes why would you want to do that? Considerations: 1 - this usage creates a local object MyClass. The object will not be visible outside the function. The class definition is executed each time the function is called. 2 - the object could be returned or assigned to a global or added to a parameter that is a collection. 3 - if no instances are created in the function the object will disappear once the function execution ends. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] How to convert ogg to MP3
hi, I would like to convert ogg files to mp3 files. how can I do that. Is there any inbuilt package. -- Thanks Regards, goldgod ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] is it legal to have a class within a def
On Wednesday 02 January 2008 09:31:19 pm you wrote: johnf wrote: def someMethod(): class MyClass(object): . if something: . return someval Legal? Well the police won't come after you! That's a good thing! Python allows a class statement anywhere. So this use is part of the language. So the question becomes why would you want to do that? Considerations: 1 - this usage creates a local object MyClass. The object will not be visible outside the function. The class definition is executed each time the function is called. 2 - the object could be returned or assigned to a global or added to a parameter that is a collection. 3 - if no instances are created in the function the object will disappear once the function execution ends. 1 and 3 are my reasons. I'm creating a Dabo app. When I attempted to create a special class that contained a dialog box I discovered that the dialog class created an indepentant type of window and allowed my program to continue running without waiting for the dialog to return a value first. However, I noticed if I created the dialog within a function my program stopped and waited until the dialog was closed to continue. I think that I could define the Classes outside of the function and just import them when needed. But then I wanted a self contained function so I asked why not place the class code in the function? What is the difference? -- John Fabiani ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor