[Tutor] Macintosh Help with Python
Can you help me through a phone number or chat on working with Python? -- Mark Warren Humboldt Unified School District # 258 801 New York Street Humboldt, Kansas 66748 Phone -- (620) 704-1527 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] cPickle and shjelving
Hi, I am new to python. I am having slight issue in using the cPickle and shelving function. Here is what i want the program need to do: Open an file with employees in it with relevant information like: employee number, surname and department. I also need to add an employee with the relevant information without rewriting the current data. I have tried the code but not completely sure what i am doing wrong. Here is the code that i tried: # Defines pickles[employee_num] pickle_file = shelve.open(empl.dat) print Add new Employee employee_num = raw_input(\nEmployee number: ) surname = raw_input(Surname: ) name = raw_input(Name: ) department = raw_input(Department: ) #Storing DATA # cPickles.dump(employee_num, emp1.dat) print key, -,pickles[key] pickles.sync () # Makes sure date is written Can you please help me in solving this issue? Kind regards Warren Jones This E-mail and any attachment(s) to it are for the addressee's use only. It is strictly confidential and may contain legally privileged information. No confidentiality or privilege is waived or lost by any mis-transmission. If you are not the intended addressee, then please delete it from your system and notify the sender immediately. You are hereby notified that any use, disclosure, copying or any action taken in reliance on it is strictly prohibited and may be unlawful. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] __mul__ for different variable types?
I'm a little confused on this one. I have a Vector class that I want to be able to multiply by either another vector or by a single float value. How would I implement this in my override of __mul__ within that class? Do you check the variable type with a stack of if isinstance statements or something? What is the preferred Python way of doing this? - Warren (war...@wantonhubris.com) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] __mul__ for different variable types?
Awesome, Rich, thanks! - Warren (war...@wantonhubris.com) On Oct 4, 2009, at 5:31 PM, Rich Lovely wrote: 2009/10/4 Warren war...@wantonhubris.com: I'm a little confused on this one. I have a Vector class that I want to be able to multiply by either another vector or by a single float value. How would I implement this in my override of __mul__ within that class? Do you check the variable type with a stack of if isinstance statements or something? What is the preferred Python way of doing this? - Warren (war...@wantonhubris.com) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor I think isinstance is probably the most pythonic way of doing this, and don't forget to add __rmul__ as well, for floats: try: from numbers import Real except NameError: Real = (int, long, float) class Vector(object): #__init__ and other methods ommitted. def __mul__(self, other): self * other if isinstance(other, Vector): # code for Vector * Vector elif isinstance(other, Number): # code for Vector * number else: return NotImplemented def __rmul__(self, other): other * self return self.__mul__(other) Note that I've got no type checking in __rmul__, because if only Vector * Vector has a different value if the terms are swapped, and other * self will use other.__mul__ if other is a Vector. Also note the import at the top: numbers.Real is an Abstract Base Class use for all real number types, introduced in Python 2.6, so simplifies testing types. See http://docs.python.org/library/numbers.html for info. If it's not there, the code demos another feature of isinstance most people don't notice: the type argument can be a sequence of types, so I set Real to a tuple of all the builtin real number types (that I can remember off the top of my head) if the import fails. If you want multiplication to be defined for complex numbers, change all occurances of Real to Number, and add complex to the tuple. -- Rich Roadie Rich Lovely There are 10 types of people in the world: those who know binary, those who do not, and those who are off by one. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Import vs #include
I'm trying to get my head around the organization of a larger Python project. 1. Am I right in thinking that in Python, you don't have the concept of something like a precompiled header and that every file that wants to use, say vector.py needs to import that module? 2. How are Python projects typically organized in terms of having many files. Are sub-directories for different kinds of files (rendering files go here, file management files go here, etc), or does that not play nicely with the import command? 3. As you can tell, I've done a lot of C/C++/C# and I'm trying to shake loose the analog that I've built up in my head that import is Python's answer to #include. It isn't, is it? - Warren (epic...@gmail.com) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Import vs #include
Excellent, OK, this is becoming clearer ... So if I wanted a common library of code that several Python apps would be using, best practices would say I should put that into a directory that the projects can see and import it as a package.module. Cool... - Warren (epic...@gmail.com) On Sep 18, 2009, at 3:25 PM, Kent Johnson wrote: On Fri, Sep 18, 2009 at 2:14 PM, Warren Marshall epic...@gmail.com wrote: I'm trying to get my head around the organization of a larger Python project. 1. Am I right in thinking that in Python, you don't have the concept of something like a precompiled header and that every file that wants to use, say vector.py needs to import that module? Yes. 2. How are Python projects typically organized in terms of having many files. Are sub-directories for different kinds of files (rendering files go here, file management files go here, etc), or does that not play nicely with the import command? It's fine. The directories are called packages and must contain a (possibly empty) file named __init__.py. Then you can do things like from package.module import SomeClass See the std lib for examples, for example the email and logging packages. 3. As you can tell, I've done a lot of C/C++/C# and I'm trying to shake loose the analog that I've built up in my head that import is Python's answer to #include. It isn't, is it? Not really, it is more like a using declaration in C# except it doesn't bring the contents of the module into scope, just the module itself. using System; // C# is like from sys import * # Python though the latter form is discouraged in favor of just import sys or importing the specific items you need: from sys import modules Kent ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New guy question...
First, let me say thanks for all the responses! This definitely looks like a useful mailing list for complete noobs like me. Second, I think my machine is probably set up a little weird. I have Python 2.6.2 installed alongside 3.1.1 so maybe that makes a difference. I'm writing programs in TextMate and running them from there. Which seemed to be working fine until I ran into this input issue. At any rate, I've installed 2.6.2 over again from a fresh download and I think I can move ahead. The example works now as long as I change input to raw_input. This should allow me to get through some more of this tutorial book anyway. Thanks again, all! I appreciate the help. - Warren (war...@wantonhubris.com) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New guy question...
Does TextMate support input into a running Python program? I'm not sure if it supports standard input. You might have to run the program from Terminal to get this to work. Good question, Kent. That might be the root of all of this pain. I'll experiment when I get a chance... - Warren (war...@wantonhubris.com) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] New guy question...
Hey all, I'm just getting started with Python and I'm working my way through my first Learn Python book on my Mac. I ran into a weird issue though. Here's the example code I'm using: #!/usr/bin/env python3 print( Type integers, each followed by ENTER; or just ENTER to finish ) total = 0 count = 0 while True: line = input() if line: try: number = int(line) except ValueErr as err: print( BLARGH : , err ) continue total += number count += 1 else: break if count: print( count =, count, total =, total, mean =, total / count ) Now, what happens is that this starts up and immediately dies, giving me this error: Type integers, each followed by ENTER; or just ENTER to finish Traceback (most recent call last): method module in test.py at line 9 line = input() EOFError: EOF when reading a line Why is the input statement not waiting for input like it should be and instead killing the app? My google-fu is failing me on this one. - Warren (war...@wantonhubris.com) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] New guy question...
Well, I thought that as well but I took it out which makes it run under 2.6.1 and I get similar, but not exactly the same, output: Type integers, each followed by ENTER; or just ENTER to finish EOFError: EOF when reading a line - Warren (war...@wantonhubris.com) On Sep 14, 2009, at 3:57 PM, Robert Berman wrote: Hi, I noticed this: #!/usr/bin/env python3 which I think indicates you are using python version 3. I strongly suspect you are reading a text based on one of the version 2 issues of python. You might consider dropping back a version(such as 2.6.) since most learning texts are not updated to work with Version 3. Robert Berman On Mon, 2009-09-14 at 15:30 -0400, Warren wrote: Hey all, I'm just getting started with Python and I'm working my way through my first Learn Python book on my Mac. I ran into a weird issue though. Here's the example code I'm using: #!/usr/bin/env python3 print( Type integers, each followed by ENTER; or just ENTER to finish ) total = 0 count = 0 while True: line = input() if line: try: number = int(line) except ValueErr as err: print( BLARGH : , err ) continue total += number count += 1 else: break if count: print( count =, count, total =, total, mean =, total / count ) Now, what happens is that this starts up and immediately dies, giving me this error: Type integers, each followed by ENTER; or just ENTER to finish Traceback (most recent call last): method module in test.py at line 9 line = input() EOFError: EOF when reading a line Why is the input statement not waiting for input like it should be and instead killing the app? My google-fu is failing me on this one. - Warren ( war...@wantonhubris.com ) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help
I think eve-online is written in stackless python, they make quite a dealy about it on their site www.eve-online.com although I cant find the page myself right now due to filters in the way. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Kent Johnson Sent: 01 October 2006 22:21 Cc: tutor@python.org Subject: Re: [Tutor] Help wesley chun wrote: I am trying to learn a programming language good for programming entire games (core functions too) check out the PyGame engine: http://pygame.org download the games written on top of PyGame that appear to match the functionality you're looking for. if you learn Python at the same time, tweaking those games and changing their functionality will help you learn it even faster. You should also look at the PyGame Challenge web site: http://www.pyweek.org/ I'm not a game writer either but I have a few thoughts...my impression is that Python and PyGame are a good foundation for hobbyist games. The PyGame and PyWeek games are good examples. I doubt that you could write a commercial quality game like Final Fantasy using just these tools though. Commercial games have highly optimized game engines. Some of them use Python as scripting engines for high-level game play; I doubt that any commercial games use Python for their core game engine. On the other hand, you are a long way from being able to write Final Fantasy. You need to start small and develop your skills. Python and PyGame should be well suited for this. You might want to read this: http://tinyurl.com/hc6xc which says in part, Starcraft, Everquest and Quake were all made by teams of professionals who had budgets usually million dollar plus. More importantly though, all of these games were made by people with a lot of experience at making games. They did not just decide to make games and turned out mega-hit games, they started out small and worked their way up. This is the point that anyone who is interested in getting into game development needs to understand and repeat, repeat, repeat until it becomes such a part of your mindset that you couldn't possibly understand life without this self evident, universal truth. and here are more links: http://en.wikipedia.org/wiki/Game_programming http://www-cs-students.stanford.edu/~amitp/gameprog.html I found these all by Googling game programming language; there are many more interesting links there. Good luck, Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor This email is confidential and may be privileged. If you are not the intended recipient please notify the sender immediately and delete the email from your computer. You should not copy the email, use it for any purpose or disclose its contents to any other person. Please note that any views or opinions presented in this email may be personal to the author and do not necessarily represent the views or opinions of Digica. It is the responsibility of the recipient to check this email for the presence of viruses. Digica accepts no liability for any damage caused by any virus transmitted by this email. UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK Reception Tel: + 44 (0) 115 977 1177 Support Centre: 0845 607 7070 Fax: + 44 (0) 115 977 7000 http://www.digica.com SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South Africa Tel: + 27 (0) 21 957 4900 Fax: + 27 (0) 21 948 3135 http://www.digica.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] hey i need some help here
I just started attempting to program and thought i would try python as my first tool. However following the beginners guide on their page it says to insert python as a command and that it should come up with the program information. When i insert python it says it is not recognizable as an internal or external command. can somebody help me? _ Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/ ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor