Re: [Tutor] Is Python a good choise for this project?
I'm in the process of chosing a technology for the implementation of a system that will have a Map builder wich will allow the users to draw a map using several construction pieces. This map will then be used in the core of the program where some pathfinding will be done - and then some animation showing a character going around the map. The interface will be simple, a grid and some images that can be chosen to ocuppy spots in the grid. Input done with the mouse. Since I don't know Python (altough I've looked some examples) I am looking for suggestions... do you think it's a good option to go with Python Python is capable of building such a system if thats what you mean. Proivided high performance (real time rapid animation say) is not required then it should perform adequately. But it will require quite a bit of learning, not just the core language but a GUI toolkit, and maybe the PyGame framework too. graphics lib, like Pygame)? Other alternatives at this point are Java and C/SDL/Allegro. If you already know these environments and have built similar applications in them you may be faster sticking with them. But if you have the time and energy to learn a new language then Python offers the promise of more rapid development in the future and easier maintenance. If you know Java you might consider using Jython to write the core objects and Java to do the GUI parts - Jython makes Python objects that are also valid Java objects and vice versa. If you are completely new to programming then you have a big challenge ahead regardless of language but Python is probably easier to learn than the others mentioned. HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Class attributes not overriding parameters
Hi, I use the following construction to make sure the data attribute site_id is set only once for each object: def GetSiteID(self): return self._site_id def SetSiteID(self, value): if not (hasattr(self, '_site_id') and self._site_id): self._site_id = value site_id = property(GetSiteID, SetSiteID) site_id is supposed to be set either through a parameter, derived from the server name (the default case) or via a class attribute: class SiteList(Lists): site_id = 1 The latter case does not work: the site_id is still derived from the server name for objects of class SiteList. Why is that? How can I make Python check the superclasses for a class attribute before applying the SiteMode() method? Thanks, Jan -- How many Microsoft engineers does it take to screw in a lightbulb? None. They just redefine dark as the new standard. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pack
At 01:57 PM 11/5/2005, Shi Mu wrote: when I clicked 'quit' button, there is no response. I want to close the interface by clicking 'x', the interface could not be closed. i had to close PYTHONWIN to get out of the program. That is a known problem running Tkinter stuff under PythonWin. Others may have a solution for you. [snip] ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] pack
Note: CC'ing tutor list to make reply visible to all. i had to close PYTHONWIN to get out of the program. Aha! There are problems in running Tkinter inside both IDLE and Pythonwin. Basically both programs try to trap abnormal termination - which includes the GUI close messages... IMHO, to test Tkinter programs its better to run the program from a DOS Window - or just double click in explorer although you might not see any error messages that way. Personally I have a DOS window open at the folder with my Tkinter program. I edit in IDLE or vim and sabe I run the program by explicitly calling python: E:\PROJECTS\PYTHON python myguiprog.py I close the GUI and repeat except I can now use F3 in the DOS window to recall the last command (or up arrow if DOSKEY is defined) So after the first time I simply - edit the code, - save it and then - Alt-tab to DOS and - hit F3 Return. Its quicker to do than to read! HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] main
It is very hard for me to understand why we need the following line? if __name__ == __main__: ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] main
On Sat, 5 Nov 2005, Shi Mu wrote: It is very hard for me to understand why we need the following line? if __name__ == __main__: Hi Shi Mu, It's tied to the concept of modules. Have you learned about modules yet? Python programs can be split into several modular pieces, and these modules live in text files. You may have seen some prewritten modules already in the Standard Library: http://www.python.org/doc/lib/ These modules are physically no different than the programs you've already written: they live in text files just like others. The 'if __name__ == __main__: ... trick exists in Python so that our Python files can act as either reusable modules, or as standalone programs. As a toy example, let's say that we have two files: ## mumak:~ dyoo$ cat mymath.py def square(x): return x * x if __name__ == '__main__': print test: square(42) ==, square(42) mumak:~ dyoo$ cat mygame.py import mymath print this is mygame. print mymath.square(17) ## In this example, we've written mymath.py to be both used as a utility module, as well as a standalone program. We can run mymath standalone by doing this: ## mumak:~ dyoo$ python mymath.py test: square(42) == 1764 ## But we can also use mymath.py as a module; let's see what happens when we run mygame.py: ## mumak:~ dyoo$ python mygame.py this is mygame. 289 ## Notice that here we don't see the 'test' line that mymath.py had near the bottom of its code. That's because, in this context, mymath is not the main program. That's what the 'if __name__ == __main__: ...' trick is used for. (Another mainstream programming language that does a simliar trick is Java: each Java class can define a main function that gets executed if we use that class as our entry point.) Does this make sense? Please feel free to ask more questions about this. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] main
At 03:39 PM 11/5/2005, Shi Mu wrote: It is very hard for me to understand why we need the following line? if __name__ == __main__: We don't need it. Often we code a module for importing into another module. But sometimes we also want to run the module independently as a Python program, perhaps just to test it, or for other purposes. if __name__ == __main__: is one way to test whether the module has been imported or is running standalone. When run standalone __name__ is __main__. When imported __name__ is the module name. Now is it easier to understand? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor