[Tutor] Exercise suggestions
I am new to programming, I intend to get an entry level job programming next year (or a little bit longer). I am switching fields and not going to college, but kinda "self teaching" myself through various methods. I currently understand concepts in programming in python up to classes (like I understand how to make objects, I understand inheritance, etc...), and I have experimented with building guis in Tkinter, but I'm finding that I understand concepts, but have no real way to implement them. So now my problem emerges... can anyone give me suggestions of exercises I should do to help improve my knowledge of what I can "actually" do with the concepts I have. My main goal is to get to the point where I can assist in fixing bugs in open source programs (I'll be learning C++ in a couple months as well), but when I look at bugs / source code of larger programs, I am just so blown away at how little I understand. So I need to find a way to bridge the gap between my current level and the level needed to contribute to open source programs. A lofty goal I understand, but it is my goal. And I am very dedicated to reaching it. Anyways, given my situation, do you good people have any suggestions for me. I don't need a person walking me through it, a simple, "build a program that asks a user to give you a name and create permutations of it" is great. Of course that example is elementary, but that is the gist of the responses I'm looking for. I just have no idea of what kind of programs to build, my ignorance is holding me back in my opinion. Any response is welcomed, but I do ask if you are critical of me, please offer a method for me to improve the deficiency / deficiencies I have. Thank you so much for reading my inquiry :) What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] print "Hello, World!"
Hey doug please don't be discouraged..., and be glad you didn't start in C++ like me... talk about being discouraged... But anyways, I just started as well. I've only been programming like 5 months. So I understand you very much :) Here are some of the better (more clear) tutorials I ran across in my short stint as a programmer. Here is the tutorial I used the most. How to think like a computer scientist (python version). This tells you stuff, then it gives you practice problems to reinforce what you just learned. (There are no answers to the problems, but this actually helped me learn a lot by researching the answers). http://openbookproject.net/thinkcs/python/english2e/index.html Bucky's youtube tutorials, in here he comments as he shows you some concepts then talks about them. He teaches python in normal english, its not technical at all, its very good :) http://www.youtube.com/user/thenewboston#p/c/0/4Mf0h3HphEA And I'm 26... so you are a million years ahead of me :) One piece of advice I can give is abuse google, almost any question you have has already been asked, learn from others who asked before you :) Oh yea, I once read that there are no intermediate tutorials in any programming language, because once you get past the basics, you only need to reference the "documentation" that comes with the language. I hope this helps. What is it about you... that intrigues me so? From: Doug Marvel To: tutor@python.org Sent: Wed, February 2, 2011 9:00:47 PM Subject: [Tutor] print "Hello, World!" Hey folks, I'm Doug. I've been using computers since second grade, and I know a little about them. I am, however, completely new to programming. I don't even know what I know about it. I'd like some social interaction with this, but I can't go back to school until summer or fall of this year. I don't want to wait to start learning this as I feel like I'm already about a million years behind. I asked the Oracle (www.google.com) and after messing around with the Python Shell and getting a lot of error messages, I decided I need some remote help. Here's where I'm at: - I have downloaded and installed Python 2.6.4. Successfully, I think. - I am running Windows XP SP3 (though I'm going to see if I can do this on my laptop, which has Windows 7) - I have toyed around with some tutorials, but all they really taught me is that I need a teacher. I'm sure you guys are busy, but I read that the most basic questions are okay. As I'm sure there is at least one good resource on the net for people in my position, I'd like some suggestions on where to start. I plan on bothering you all as little as possible, but I am seriously hoping to make real progress between now and my first class. I have a feeling once I get a basic understanding, I'll run away with it. It's just very... big right now. So this list seems like a good thing, but tell me if I'm in the wrong place. I am hoping for a link to a somewhat comprehensive online resource that explains from the beginning in English, plain English, as this is the only language I speak. Something to get my foot in the door would be awesome. Cheers, Doug Marvel ___ 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] textbook question
Hi, Justin, how are you? Most of the nice people here like to see that you try before you ask for help. So next time post some code that you have tried (and failed on) so they can see WHERE you are going wrong or WHAT is throwing you off. I'm a beginner too, also I am using How to Think Like a Computer Scientist. So I really am similar to you. But to give you a bit of help on your problem. Strings can actually have some basic math done on them (like addition and multiplication). for example a = "Resident" b = " Evil" # you can perform addition on these two strings to join one big string. #so... a + b = "Resident Evil" #Like wise, multiplication can be done on a string (string times a number) to achieve a similar effect. c = "Ha " c * 3 = "Ha Ha Ha" So using my example can you think of a way to set up your function to augment strings to produce the effect that you desire? Give it a shot and if you get stuck post here again. What is it about you... that intrigues me so? From: Justin Bonnell To: tutor@python.org Sent: Mon, February 28, 2011 12:36:43 AM Subject: [Tutor] textbook question In trying to learn Python, I'm reading through How to Think Like a Computer Scientist. I'm just on the third chapter but I'm getting stuck on this question: Fill in the body of the function definition for cat_n_times so that it will print the string, s, n times: def cat_n_times(s, n): Save this function in a script named import_test.py. Now at a unix prompt, make sure you are in the same directory where the import_test.py is located ( ls should show import_test.py). Start a Python shell and try the following: >>> from import_test import * >>> cat_n_times('Spam', 7) >>>SpamSpamSpamSpamSpamSpamSpam >>> If all is well, your session should work the same as this one. Experiment with other calls to cat_n_times until you feel comfortable with how it works. I'm thinking it should be pretty easy but, again, I'm a beginner. I copied the whole question but basically I just need some help with what the script should look like, that'd be great. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help! (solution)
I know that the question has long been answered (and probably due today), but I solved it and it was great exercise for me (as I'm not in college at the moment and I need assignments like these to gauge my skills). I'll probably build a gui for it tomorrow, just so I can practice at that. I wish I had a comp sci lab... (T_T) but I digress But anyways Andrew here is an alternative way to solve the problem (even if it is a long and round about method). And to anyone else who is reading beside Andrew, if something about my code could be better, please tell me, as this was just as much a learning experience for me as it is for Andrew. I need constructive criticism at the moment so I don't develop bad habits. def production_time(): creation_time = 127 time_till_rest = 18161 items = raw_input("How many items will be produced?\n> ") item_time = int(items) * creation_time rest_times = item_time/time_till_rest print rest_times if rest_times > 0: total = item_time + (313 * rest_times) #313 is 5 min and 13 secs in second form else: total = item_time time = sec_to_standard(total) print "It would take %d days %d hours %d minutes and %d seconds to produce that many items" %(time[0], time[1], time[2], time[3]) def sec_to_standard(seconds): day = 86400 #secs hour = 3600 #secs mins = 60#seconds creation_time = 127 #secs time_till_rest = 18161 #secs days = 0 hours = 0 minutes = 0 secs = 0 if seconds > day: while seconds > day: print "doing days" seconds = seconds - day days += 1 if seconds > hour: while seconds > hour: print "doing hours" seconds = seconds - hour hours += 1 if hours >= 24: days += 1 hours -= 24 if seconds > mins: while seconds > mins: print "doing minutes" seconds = seconds - mins minutes += 1 if minutes > 60: hours += 1 minutes -= 60 secs = seconds return days, hours, minutes, secs production_time() What is it about you... that intrigues me so? From: Andrew Bouchot To: tutor@python.org Sent: Thu, March 3, 2011 4:28:33 PM Subject: [Tutor] Help! okay so this is my comp sci lab Problem: ProductionTime.py It takes exactly 2 minutes and 7 second to produce an item. Unfortunately, after 143 items are produced, the fabricator must cool off for 5 minutes and 13 seconds before it can continue. Write a program that will calculate the amount of time required to manufacture a given number of items. Output: Output the amount of time D days HH:MM:SS Sample Input : numItems =1340 Represents the numbers items to be manufactured Sample Output : 2 days 00:03:17 this is the coding i have written for it! numitems= int(raw_input("Enter the number of items needed to be manufactured:")) seconds=numitems*127 m, s = divmod(seconds, 60) h, m = divmod(m, 60) print "%d:%02d:%02d" % (h, m, s) but how would i add the 5 min and 13 seconds after 143 items have been produced??? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Print/Loop Question
Hi Jeff how are you today? Well about your question... I copy and pasted your code and it worked fine for me. Well except for in the code bit you posted you forgot to give a guess a value before it was referred to. So under number = 44 I just wrote guess = 0 and it worked fine. But perhaps I'm misunderstanding your question, because I did not get any of the errors you mentioned. Here is what I got jigenbakuda@jigenbakuda-HP-G50-Notebook-PC:~$ python 6.py Guess a number between 1 - 100: 45 Too high Guess a number between 1 - 100: 43 Too low Guess a number between 1 - 100: 44 Just right jigenbakuda@jigenbakuda-HP-G50-Notebook-PC:~$ with this code number = 44 guess = 0 while guess != number : guess = int(raw_input("Guess a number between 1 - 100: ")) if guess > number : print ("Too high") elif guess < number : print ("Too low") else: print ("Just right" ) If I'm misunderstanding your problem, I'm sorry. What is it about you... that intrigues me so? From: Jeff Goodwin To: tutor@python.org Sent: Thu, March 17, 2011 2:19:17 PM Subject: [Tutor] Print/Loop Question I'm trying to run the below program and get it to print out feedback as the loop goes. However, if you enter a number too high or too low, it skips the print statement under the if and elif clauses and asks the user to "Guess a number between 1-100" again. Any suggestions on how to get it to print the "too high" and "too low" responses?? Once the number is entered correctly it prints "Just Right" and exits correctly. number = 44 while guess != number : guess = int(raw_input("Guess a number between 1 - 100: ")) if guess > number : print ("Too high") elif guess < number : print ("Too low") else: print ("Just right" ) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Saving information for my program
I apologize now but I'm going to be spamming the tutor list as I have just decided to create an extremely ambitious project for someone of my level. Anyhow, I will start with my first question. How do I save user created information in python? In my progam I will have users input various "attributes" of people they like (age, height, movies they have been in, songs they sung in, favorite part of them, important links dealing with them, etc), and I'd like to know how to save these things so that even after you stop running the program they are saved and when you start the program again, these variables are loaded. This part of my program will be sort of like an offline-wiki-gui-thingie. I was planning on using classes for each person so that I could store their attributes that way . jessica = Profile() jessica.name = "jessica ngorn" jessica.age = 25 jessica.favorite_song = "chinpo no uta" I was thinking I have 2 options, which is save the information to a text file a write / read it in every session, but I have no idea how to do this with class attributes. I know how to do it for like a paragraph of text, but I have no idea how to do it with classes and their attributes. The other option I was thinking about was using the pickle module. I have never used it, but I read the documentation, and I'm not exactly sure how to use it... it says it only saves the class "name", but not the body (same for functions), but how would that help me? Well if you can contribute to helping me please do. Linking me to stuff to read is great, explaining it here is great, writing short example code is great too, anything helps. What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Checksum program
Hi Lezlie, Well first off, let me admit I have no idea what checksums are (I be a noobz) and I can not help you with that part of your program at all, but there are lots of people here who can. But since you are new to python, let me comment on some of the general things I noticed in your code. When I ran your code with the word being hello I got the error. "TypeError: cannot concatenate 'str' and 'int' objects" it occured at line 8 of your code "output=output+name+ord(message[i])". Now in this line you are adding 2 strings together (output and name) with 1 int (ord(message[i])). In python you can not add these types together. Hence the error. But if it did add them together (using hello as an example) you would get output = hellohello104, is this what you want? Since message = hello and output = hello and ord("h") = 104. Also keep in mind that for every iteration of the for loop, output actually changes (meaning that output lost its last value, to make room for the new one, and it only has 1 value in it), so if python actually did what you asked it to your output would look like this. The value of message[i] is h The value of the message is hellohello104 The value of message[i] is e The value of the message is hellohello101 The value of message[i] is l The value of the message is hellohello108 The value of message[i] is l The value of the message is hellohello108 The value of message[i] is o The value of the message is hellohello111 The checksum is , 111 (according to "checksum=(output)%256" supposing the hellohello was not added and just 111 was evaluated, if you had put in "256%(output)" the answer would have been 54 instead of 111) Note that because it changed in every iteration the last letter (o) is the final value of output, instead of the values being appended to the variable output Is this what you wanted to happen? If its not, try to think of ways to slighty change your code to give you closer results to what you want. If this is what you want, there are cheats to actually make it output this without errors... I hope this helps (^_^) What is it about you... that intrigues me so? From: Lezlie Kline To: tutor@python.org Sent: Wed, March 23, 2011 9:09:53 AM Subject: [Tutor] Checksum program Hi, I'm trying to work out the bugs in a program for calculating the checksum (modulo 256) of an input string. I'm testing it with my full name and I'm a beginner with Python. Here's what I have so far. def main(): print"This program creates a checksum for a message." name=raw_input("Please enter the message to encode: ") message=name output=name for i in range(len(message)): print"The value of message[i] is ", message[i] output=output+name+ord(message[i]) print"The value of the message is ", output checksum=(output)%256 print"The checksum is ", checksum main() I know I'm offbase somewhere, but I'm not understanding some parts of the accumulator part of the program. I need it to work with the message[i] intact. In other words, I need the pseudo code to go something like this: print message get input find length using length in range function accumulate ASCII numbers calculate checksum print checksum I'd appreciate any help offered as I'm "pulling out my hair." ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] User Made Dictionaries
Hello, I'm trying to find out the best course of action for the next stage of my program. I want to hold information on various idols. I first thought to do this with classes, but realised that I could represent the data the same way with a dictionary. So I am now just concentrating on dictionaries. So lets say for example I wanted to have a dictionary with keys like this. chiaki = { "name" : "Chiaki Kuriyama", "age": "26", "charm_point" : "nose", "profile_pic" : "/home/jigenbakuda/Pictures/chiaki/chiaki.jpg", "pic_quantity" : 120, "bio" : "First met this lady in kill bill, and the descent afterwards was horrible, I fan boy over this chick hard, etc..."} I understand, or at least I have pretty good ideas about how to get this information (the keys and their values) from a user. I was thinking something like this for my general flow (this is all just fake code trying to represent my thought process) mold = { "name" : " ", "age": " ", "charm_point" : " ", "profile_pic" : " ", "pic_quantity" : 0 , "bio" : " "} chiaki = copy.copy(mold) #have the user fill in the data here natalie = copy.copy(mold) #have the user fill in the data here # etc... But my question is how do I repeatedly automate new names for the dictionaries? Like how do I get the user to create the dictionary name (chiaki, natalie, etc...)? Would it be better to represent this data with classes? If so, how do I have users create new class names? Ex. chiaki = Idol(), how do I get the user to create the chiaki name? Any hints, answers, or links to recommended reading would be greatly appreciated :) What is it about you... that intrigues me so?___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Recommendations required
Hello Ankur, Well as a beginner myself I suggest that you check out these games and modify them or create new versions of them (with additional functionality). There are lots of stock answers, but in general old arcade games from the 70's are great places to start. They are simple enough and you should understand enough about them to know the various things you will need to implement. Heavily coded games http://inventwithpython.com/blog/category/code-comments/ I asked the same question a while back and I'm sure you will get similar answers to what I got. Although If you have not done most of the tutorials on the pygame site itself, even these heavily coded source codes may be too complex for you too handle. The pygame tutorials http://pygame.org/wiki/tutorials Good luck and I hope you create fun games for others to play. What is it about you... that intrigues me so? From: ANKUR AGGARWAL To: pygame-us...@seul.org; tutor@python.org Sent: Mon, April 4, 2011 12:12:26 PM Subject: [Tutor] Recommendations required Hey I am reading pygame module and experimenting with it in small codes too . I want your help. I want you to recommend the games ,beginner of this module should try to develop as a practice or so. Thanks Ankur Aggarwal ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (sqlite3) Testing if a table has been created.
Hello guys, Since sqlite gives an error if you try to create a table that's already there, how do I test if a table is already present? for example in def database(info): import sqlite3 connection = sqlite3.connect("test.db") cursor = connection.cursor() if table not in test.db: #with this being my test that I'm not sure how to implement cursor.execute(""" CREATE TABLE stuff (id INTEGER PRIMARY KEY, name TEXT)""") cursor.execute("""INSERT INTO stuff VALUES (null, ?)""",(info)) cursor.commit() cursor.close() connection.close() How would I properly test if table not in test.db: ? Is it something as simple as having a method of cursor check it for me, or should I just create my table in the beginning of my code(outside of this function) and leave it out of the function all together, so I can just have my function focusing on inserting data? Uhm, in the immediate example I'm using, this is a function, thats inside of a function used by a tkinter button, a save button if you will. So I want it to save whatever is in the entry widget to the database. Keeping this in mind, am I going about it the wrong way? Should I be trying to save a different way? What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (sqlite3) Testing if a table has been created.
From: Joel Goldstick To: michael scott Cc: tutor@python.org Sent: Wed, April 6, 2011 8:30:17 AM Subject: Re: [Tutor] (sqlite3) Testing if a table has been created. On Tue, Apr 5, 2011 at 9:59 PM, michael scott wrote: Hello guys, > >Since sqlite gives an error if you try to create a table that's already there, >how do I test if a table is already present? > > >for example in > >def database(info): >import sqlite3 > >connection = sqlite3.connect("test.db") >cursor = connection.cursor() >if table not in test.db: #with this being my test that I'm not sure how to >implement >cursor.execute(""" CREATE TABLE stuff (id INTEGER PRIMARY KEY, name >TEXT)""") >cursor.execute("""INSERT INTO stuff VALUES (null, ?)""",(info)) >cursor.commit() >cursor.close() >connection.close() > > >How would I properly test if table not in test.db: ? Is it something as >simple >as having a method of cursor check it for me, or should I just create my table >in the beginning of my code(outside of this function) and leave it out of the >function all together, so I can just have my function focusing on inserting >data? > >Uhm, in the immediate example I'm using, this is a function, thats inside of a >function used by a tkinter button, a save button if you will. So I want it to >save whatever is in the entry widget to the database. Keeping this in mind, am >I >going about it the wrong way? Should I be trying to save a different way? > > > > > > > >What is it about you... that intrigues me so? > > >___ >Tutor maillist - Tutor@python.org >To unsubscribe or change subscription options: >http://mail.python.org/mailman/listinfo/tutor > > Is this really a python tutor question? Oh, well, try this: http://lmgtfy.com/?q=sqlite+test+if+table+exists -- Joel Goldstick My apologies, I was not aware that there were questions I could and could not ask. I understand now that this is an unnacceptible question. But could you tell me why? Was it too simple in nature? Too difficult? Did I violate some rule in my question formatting? This was not homework or anything like that. I went back to the tutor website to make sure I did not blatantly break one of the rules. I only found this regarding participation. About Tutor English (USA) This list is for folks who want to ask questions regarding how to learn computer programming with the Python language. Python (http://www.python.org/) is a programming language which many feel is a good first language, because it makes it easy to express the fundamental concepts of programming such as data structures and algorithms with a syntax which many find easy to read and write. Folks interested in learning about programming with Python are encouraged to join, as are folks interested in helping others learn. While the list is called tutor, anyone, whether novice or expert, can answer questions. If individuals wish to start off-line conversations about a particular concept and become one-on-one tutor/tutee, that's fine. If either party wants to summarize what they learned for others to benefit, that's fine too. There is a searchable interface to archived Tutor messages on Activestate's web site and another one at Gmane. There are many on-line resources that can help you get started with Python. See the Beginners Guide for a list of some good ones. To see the collection of prior postings to the list, visit the Tutor Archives. So that I can avoid posting questions that don't belong on the tutor list, or so I can have a clearer picture of what a python tutor question is, could someone please help me?___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (sqlite3) Testing if a table has been created.
From: Andre Engels To: michael scott Cc: tutor@python.org Sent: Wed, April 6, 2011 10:19:53 AM Subject: Re: [Tutor] (sqlite3) Testing if a table has been created. On Wed, Apr 6, 2011 at 4:06 PM, michael scott wrote: Is this really a python tutor question? Oh, well, try this: http://lmgtfy.com/?q=sqlite+test+if+table+exists > >-- >Joel Goldstick > > >My apologies, I was not aware that there were questions I could and could not >ask. I understand now that this is an unnacceptible question. But could you >tell >me why? Was it too simple in nature? Too difficult? Did I violate some rule in >my question formatting? This was not homework or anything like that. I went >back to the tutor website to make sure I did not blatantly break one of the >rules. I only found this regarding participation. > I think Joel's objection is that your question is not really about Python at all, but about SQLite, -- André Engels, andreeng...@gmail.com Oh I see. That makes sense. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Help - accumulator not working (Lea)
Hi Lea, how are you today? Well please keep in mind that nothing is "wrong" with your code, its doing exactly what you asked it to do. But I would call your attention to your while loop, you want to accumulate things, but may I ask exactly what are you accumulating in your loop? Also quite by accident I entered 00 as my budget and I got a negative surplus, lol. Perhaps you should implement something that ensures that a (stupid) user like myself does not enter a 0- or negative value for the budget. Just a thought... To help me attempt to understand the small programs I write, I pretend that I'm the computer and I literally compute the program as if I was the interpreter, I follow each line of my code to truly understand it. Perhaps with these gentle nudges you will solve your problem :) What is it about you... that intrigues me so? From: Lea Parker To: tutor@python.org Sent: Fri, April 15, 2011 5:52:22 PM Subject: [Tutor] Help - accumulator not working (Lea) Hello I am trying to create this program for a uni assignment. I cannot get it to add the expenses to the accumulator I have set. Would you mind having a look and letting me know if I have something in the wrong place or indented incorrectly. Perhaps I am missing something. There could be other things wrong but I need to fix this first and then I can focus on the next thing. I have difficulty trying to fix lots of things at once so if you could just comment on the problem and I will ask again if I can’t work out the next problem I have. I like to have a go myself first. J My code is: """This program is to calculate if the user is over or under budget for the month""" def main(): # Create an accumulator total_expense = 0.0 # Ask user for the monthly budget budget = float(raw_input('Enter the amount of your budget for the month: $')) # Calculate a series of expenses expense = float(raw_input('Enter your first expense $')) # Accumlate expense total_expense = total_expense + expense # Continue processing as long as the user # does not enter 0 while expense != 0: #Get another expense expense = float(raw_input('Enter the next expense or 0 to finish $')) #Calculate surplus surplus = budget - total_expense #Display results print 'Your total expenses for the month $', total_expense print 'Your surplus amount after expenses $', surplus # Call the main function. main() Thank you.___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] python timers
Hello how do you do. Today's question has to do with the time module. I want to add a timer to my gui. As I was messing around with it I found a way to measure time... but I'm positive there is a more elegant way to deal with this than what I've thrown together. def thing(): start = time.time() while 1: now = time.time() if now == start + 10.0: print "times up" How are timers usually implemented? By the way, I'm not really asking as much about the how (because I could throw something together that will serve my purpose), I'm asking more about conventions, like is there a standard way people implement timers, like does python come with one built in? Does every programmer who wants a timer write a different one? What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] after(), how do I use it?
Hello, I asked for help in another location and it solved my problem, but the only problem is I don't fully understand the after function. Here is part of the code that was given to me. def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget("text") t += message[0] self.label.config(text=t) if len(message) > 1: self.after(500, self.print_label_slowly, message[1:]) I understand it, and the gist of how it works, but the self.after... I can not find any documentation on it (because after is such a common word), so can you guys tell me how it works. Is this a built in function (didn't see it on the built in function list)? Does it always take 3 arguements? Is this a user made function and I'm just overlooking where it was defined at? What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after(), how do I use it?
Here is the code in its entirety, it works although I don't see after() defined, so I assumed it was a built in function. I can just copy and paste parts of this code into my project, so its not imperative that I understand, but I prefer to use the weapons I've been given. So I hope that you guys can understand it a bit better after I post this. import Tkinter as tk class App(tk.Tk): def __init__(self,*args, **kwargs): tk.Tk.__init__(self, *args, **kwargs) self.label = tk.Label(self, text="", width=20, anchor="w") self.label.pack(side="top",fill="both",expand=True) self.print_label_slowly("Hello, world!") def print_label_slowly(self, message): '''Print a label one character at a time using the event loop''' t = self.label.cget("text") t += message[0] self.label.config(text=t) if len(message) > 1: self.after(500, self.print_label_slowly, message[1:]) app = App() app.mainloop() What is it about you... that intrigues me so? From: Adam Bark To: tutor@python.org Sent: Mon, April 25, 2011 8:50:16 PM Subject: Re: [Tutor] after(), how do I use it? On 26/04/11 01:36, michael scott wrote: > Hello, I asked for help in another location and it solved my problem, but the >only problem is I don't fully understand the after function. Here is part of >the >code that was given to me. > > > def print_label_slowly(self, message): > '''Print a label one character at a time using the event loop''' > t = self.label.cget("text") > t += message[0] > self.label.config(text=t) > if len(message) > 1: > self.after(500, self.print_label_slowly, message[1:]) > > I understand it, and the gist of how it works, but the self.after... I can > not >find any documentation on it (because after is such a common word), so can you >guys tell me how it works. Is this a built in function (didn't see it on the >built in function list)? Does it always take 3 arguements? Is this a user made >function and I'm just overlooking where it was defined at? The function you have shown there appears to be a class method. self.after means you are calling another method of the same function that print_label_slowly is a part of. Do you have the rest of the code? If you're still confused post it and hopefully we can clear it up for you. HTH, Adam. ___ 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] after(), how do I use it?
Now I understand what I misunderstood. Well he imported Tkinter as tk, so I thought if it belonged to Tkinter it would be tk.after(), but the after was attached to the app, so it was in actuality app.after() . app inherits from the tk class (taking with it all its methods), so its a built in function of tkinter. I read the whole thread of the first google response, but I still wasn't sure if it was a Tkinter function or a python function. I searched the actual python documentation quite extensively, but briefly glanced at the tkinter effbot page, after not seeing it I came here. I was just looking for the documentation on after(). But yea, this is what I needed id = w.after(time, callback) So I know it takes 2 arguments, and I know to use it recursively in my problem, so now I understand enough about this function to put it to good use :) Thank you. What is it about you... that intrigues me so? From: Wayne Werner To: michael scott Cc: tutor@python.org Sent: Mon, April 25, 2011 9:15:10 PM Subject: Re: [Tutor] after(), how do I use it? On Mon, Apr 25, 2011 at 8:02 PM, michael scott wrote: Here is the code in its entirety, it works although I don't see after() defined, so I assumed it was a built in function. I can just copy and paste parts of this code into my project, so its not imperative that I understand, but I prefer to use the weapons I've been given. So I hope that you guys can understand it a bit better after I post this. > That it is indeed. Do you understand classes and subclassing in Python? App is a subclass of tk.Tk. If you have done any of your own programming in Tkinter, you should know that Tk is the "main" class in Tkinter. If you do a Google search for "Tkinter after", the top two results will answer your question: http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=tkinter+after HTH, Wayne >import Tkinter as tk > >class App(tk.Tk): >def __init__(self,*args, **kwargs): >tk.Tk.__init__(self, *args, **kwargs) >self.label = tk.Label(self, text="", width=20, anchor="w") >self.label.pack(side="top",fill="both",expand=True) > self.print_label_slowly("Hello, world!") > > >def print_label_slowly(self, message): >'''Print a label one character at a time using the event loop''' >t = self.label.cget("text") >t += message[0] >self.label.config(text=t) >if len(message) > 1: >self.after(500, self.print_label_slowly, message[1:]) > >app = App() >app.mainloop() > > > > >What is it about you... that intrigues me so? > > > > > From: Adam Bark >To: tutor@python.org >Sent: Mon, April 25, 2011 8:50:16 PM >Subject: Re: [Tutor] after(), how do I use it? > > >On 26/04/11 01:36, michael scott wrote: >> Hello, I asked for help in another location and it solved my problem, but >> the >>only problem is I don't fully understand the after function. Here is part of >>the >>code that was given to me. >> >> >> def print_label_slowly(self, message): >> '''Print a label one character at a time using the event loop''' >> t = self.label.cget("text") >> t += message[0] >> self.label.config(text=t) >> if len(message) > 1: >> self.after(500, self.print_label_slowly, message[1:]) >> >> I understand it, and the gist of how it works, but the self.after... I can >> not >>find any documentation on it (because after is such a common word), so can >>you >>guys tell me how it works. Is this a built in function (didn't see it on the >>built in function list)? Does it always take 3 arguements? Is this a user >>made >>function and I'm just overlooking where it was defined at? > >The function you have shown there appears to be a class method. self.after >means >you are calling another method of the same function that print_label_slowly is >a >part of. >Do you have the rest of the code? If you're still confused post it and >hopefully >we can clear it up for you. > >HTH, >Adam. >___ >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 > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Making a script part of the terminal
Okay, my title might be undescriptive, let me try to explain it better. I want to take a script I've written and make it usable by typing its name in the terminal. Perfect example is the python interpreter. You just type in the word python to the terminal and then the interpreter runs. I know other programs can do this as well (like mozilla or nautilus or rhythmbox). So how do I make my scripts executable from the terminal? What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Making a script part of the terminal
Thank you for the reply, but thats not exactly what I mean. Perhaps I should say, how do I install a program to my computer, so that I can use it by its self without running it with python. No matter what directory I'm in I can type mozilla in and it runs, no matter what directory I'm in if I type sudo natutilus it will run, no matter what directory I'm in if I type gedit it will run. So I'm trying to achieve this with the script I wrote. I don't know the terminology to ask the question correctly, so forgive me. What is it about you... that intrigues me so? From: James Reynolds To: michael scott Cc: tutor@python.org Sent: Fri, May 20, 2011 1:57:57 PM Subject: Re: [Tutor] Making a script part of the terminal We just had a similar question yesterday. Just make sure Python is on your PATH. CD to the directory where your file is located and then you can just type "python myfile.py" where myfile is the name of your file. On Fri, May 20, 2011 at 1:43 PM, michael scott wrote: Okay, my title might be undescriptive, let me try to explain it better. I want to take a script I've written and make it usable by typing its name in the terminal. Perfect example is the python interpreter. You just type in the word python to the terminal and then the interpreter runs. I know other programs can do this as well (like mozilla or nautilus or rhythmbox). So how do I make my scripts executable from the terminal? > > >What is it about you... that intrigues me so? > > >___ >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] Making a script part of the terminal
Thank you gentlemen so much, I believe I have all that I need to do what I wish. What is it about you... that intrigues me so?___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python and the web
I want to start getting into web site development. I already know basic html and css, which will create a basic webpage. But my question is what exactly does python bring to the web? Are forums, blogs, flash sites, etc the results of web programming or can they all be achieved with standard html / css? What exactly can I do differently with python than with html and css? Or should I say, how can I use python WITH html and css to create something better? What is it about you... that intrigues me so? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Non programmer wanting to become programmer
I am a beginner so I can relate with you, although python is my first programming language, it sounds as if you are coming from another language. Either way, here are some sites I'll collected that have tutorials and are free. Alan's tutorial (alan is a very active member here) http://www.freenetpages.co.uk/hp/alan.gauld/ How to think like a computer scientist (uses python) http://openbookproject.net/thinkcs/python/english2e/index.html Learn python the hard way http://p2pu.org/webcraft/learn-python-hard-way The official python tutorial (2.7) (all the versions are available) http://docs.python.org/tutorial/index.html If you happen to be a visual / audio learner try these Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008 http://www.youtube.com/watch?v=k6U-i4gXkLM Bucky's youtube tutorial http://www.youtube.com/user/thenewboston#p/c/EA1FEF17E1E5C0DA/0/4Mf0h3HphEA Lecture 1A | MIT 6.001 Structure and Interpretation, 1986 (uses scheme, but the concepts are highly transferable) http://www.youtube.com/watch?v=2Op3QLzMgSY If you are planning to go into video game development, I recommend this tutorial http://inventwithpython.com/chapters/ These are just a fraction of the info out there, I found all these links in my journey to get better at programming, so if these links don't suit you, don't be scared to go out there and look. What is it about you... that intrigues me so? From: amt <0101...@gmail.com> To: tutor@python.org Sent: Thursday, May 26, 2011 3:36 PM Subject: [Tutor] Non programmer wanting to become programmer First of all, hello! I want to start learning programming. I'm looking into becoming more than a hobbyist programmer. I searched a lot on Google on what programming language should I learn first and I see a lot of good words about Python so I decided to go for it but have some questions: 1)What book should I start with? ( I have checked Python for non programmers but there are a lot of titles there, what should I pick first?I was thinking about Invent your own computer games with Python.) 2)Version 2 or version 3? What should I go for as a beginner and why? ( I ask because some books in the Python for non programmers section are for python 2, Invent your own computer games with Python is version 3.) 3)Algorithms, memory management, data structures, when is the right time to learn them? Regards, amt. ___ 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] Class methods
Just to add a little to Alexandre's answer. You can keep most of the code the same just add in farmlet[0].eat() farmlet[1].eat() and it will be okay... kinda. Or you could rewrite it and do it another way... I'm guessing that you are using python 3 by your print statements, so I don't think you need the int() around your input, even in python.2x input() was safe for numbers I believe (the whole list will rip my throat out if I'm wrong anyways, lol), but in your while loop around line 82 you have all the conditions responding to a string, even thought you explicitly changed the input to an integer. if choice == "0" instead of if choice == 0: so I got a continual output of ('\nSorry, but', 3, "isn't a valid choice.") Now this does not get your program running the way you want it to, but it will start you off making the corrections you need. Just some things to think about, in line 113, when did you define class f? in line 102, what are you trying to do, and are you telling it the right thing? since you have 2 (or possibly more) critters you are taking care of, how does the player know which one he is feeding / talking to / playing with in your farmlet? Anyways best of luck in your program, sounds pretty cool... What is it about you... that intrigues me so? From: Alexandre Conrad To: David Merrick Cc: tutor@python.org Sent: Wednesday, June 22, 2011 6:48 PM Subject: Re: [Tutor] Class methods David, 2011/6/22 David Merrick : > # listen to your critter > elif choice == "1": > for critter in farmlet: > farmlet.talk() You want to call .talk() on your "critter" instance which has the .talk() method, not on farmlet (which is a list as the error message states) > Traceback (most recent call last): > File "I:/Python/programs/critter_farm4.py", line 117, in > main() > File "I:/Python/programs/critter_farm4.py", line 103, in main > farmlet.talk() > AttributeError: 'list' object has no attribute 'talk' You will probably have a problem when calling talk() because it references to the "farmlet" variable which doesn't exist in the scope of your .talk() method. HTH, -- Alex | twitter.com/alexconrad ___ 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