Re: [Tutor] [Fwd: Re: trouble with "if"]
2007/5/30, Brian van den Broek <[EMAIL PROTECTED]>: > Another fwd, folks. > > Brian vdB > > Original Message > Subject: Re: [Tutor] trouble with "if" > Date: Tue, 29 May 2007 23:28:46 -0500 > From: Adam Urbas <[EMAIL PROTECTED]> > To: Brian van den Broek <[EMAIL PROTECTED]> > References: <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > > I'm having trouble with the parentheses after the def thing(). IDLE > says that there is something wrong with it. If I type something > between them, it says that there is something wrong with the quotation > marks. If I just leave it like (), then it says that something is > wrong with what is after the parentheses. Unless my code is supposed > to go between the parentheses. I'll try that. Between the parentheses should go the variables you use (if any) when calling the function. For example: def sayhello(): print "Hello" You don't have any parameters here, so there's nothing between the brackets def say(word): print word Now there is one parameter, namely word. def sayboth(word1,word2): print word1 print word2 Here there are two parameters, word1 and word2. The number of parameters should be the same as the number of parameters you use when calling the function: sayhello() say("One text") sayboth("One text","Another text") There is a much used method to make some of the parameters optional, but we'll not go into that. To know what is going wrong with your program, I would have to see the program (or a simplified version of it that still goes wrong) and preferably also the exact error message you are getting. -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: Re: trouble with "if"]
I can't exactly show you the error message anymore, because the program is now screwed up in so many ways that I can't even get it to do the things it used to. It says things like ERROR: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), OR 2) Your indentation mixes tabs and spaces. Then it tells me to untabify everything, which i did and it still gives this message. I've started completely over with the exact same indentation and that one works. Oh my gosh this gmail is a fricken crack head... none of this stuff was here last night. I have no idea what was going on then, but everything you guys said is right here. The plain text is right next to the Check spelling, the reply to all is right above send and save now and in the corner near the little arrow. Well, it's working now. Ok, so if i have a section of code that is: answer=(2+3): print "answer", answer so for the code above I would put: (I think I would have to have the two numbers and the addition thing in there wouldn't I; I saw something like this on Alan's tutorial last night.) def answer(2,3): answer=(2+3) print "answer",answer That is obviously not right.: There's an error in your program: invalid syntax when it says that it highlights the 2: def answer(2+3): Ok I think I understand these now. Thanks for the advice. I have this now: def answer(): print("answer") answer() It works too, yay! Thanks, Au On 5/30/07, Andre Engels <[EMAIL PROTECTED]> wrote: 2007/5/30, Brian van den Broek <[EMAIL PROTECTED]>: > Another fwd, folks. > > Brian vdB > > Original Message > Subject: Re: [Tutor] trouble with "if" > Date: Tue, 29 May 2007 23:28:46 -0500 > From: Adam Urbas <[EMAIL PROTECTED]> > To: Brian van den Broek <[EMAIL PROTECTED]> > References: <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > <[EMAIL PROTECTED]> > > I'm having trouble with the parentheses after the def thing(). IDLE > says that there is something wrong with it. If I type something > between them, it says that there is something wrong with the quotation > marks. If I just leave it like (), then it says that something is > wrong with what is after the parentheses. Unless my code is supposed > to go between the parentheses. I'll try that. Between the parentheses should go the variables you use (if any) when calling the function. For example: def sayhello(): print "Hello" You don't have any parameters here, so there's nothing between the brackets def say(word): print word Now there is one parameter, namely word. def sayboth(word1,word2): print word1 print word2 Here there are two parameters, word1 and word2. The number of parameters should be the same as the number of parameters you use when calling the function: sayhello() say("One text") sayboth("One text","Another text") There is a much used method to make some of the parameters optional, but we'll not go into that. To know what is going wrong with your program, I would have to see the program (or a simplified version of it that still goes wrong) and preferably also the exact error message you are getting. -- Andre Engels, [EMAIL PROTECTED] ICQ: 6260644 -- Skype: a_engels ___ 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] [Fwd: Re: trouble with "if"]
Ahahahahaha... I have figured these out beyond comprehension and power. Wahhaha. It feels good to get something to work correctly. Thanks much Andre. I don't quite understand the putting of things inside the parentheses, but I've discovered that I don't really need to, because def text(): works just fine with everything I've done so far. On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: I can't exactly show you the error message anymore, because the program is now screwed up in so many ways that I can't even get it to do the things it used to. It says things like ERROR: Inconsistent indentation detected! 1) Your indentation is outright incorrect (easy to fix), OR 2) Your indentation mixes tabs and spaces. Then it tells me to untabify everything, which i did and it still gives this message. I've started completely over with the exact same indentation and that one works. Oh my gosh this gmail is a fricken crack head... none of this stuff was here last night. I have no idea what was going on then, but everything you guys said is right here. The plain text is right next to the Check spelling, the reply to all is right above send and save now and in the corner near the little arrow. Well, it's working now. Ok, so if i have a section of code that is: answer=(2+3): print "answer", answer so for the code above I would put: (I think I would have to have the two numbers and the addition thing in there wouldn't I; I saw something like this on Alan's tutorial last night.) def answer(2,3): answer=(2+3) print "answer",answer That is obviously not right.: There's an error in your program: invalid syntax when it says that it highlights the 2: def answer( 2+3): Ok I think I understand these now. Thanks for the advice. I have this now: def answer(): print("answer") answer() It works too, yay! Thanks, Au On 5/30/07, Andre Engels <[EMAIL PROTECTED] > wrote: > > 2007/5/30, Brian van den Broek < [EMAIL PROTECTED]>: > > Another fwd, folks. > > > > Brian vdB > > > > Original Message > > Subject: Re: [Tutor] trouble with "if" > > Date: Tue, 29 May 2007 23:28:46 -0500 > > From: Adam Urbas <[EMAIL PROTECTED]> > > To: Brian van den Broek <[EMAIL PROTECTED]> > > References: < [EMAIL PROTECTED]> > > <[EMAIL PROTECTED]> > > < [EMAIL PROTECTED]> > > > > I'm having trouble with the parentheses after the def thing(). IDLE > > says that there is something wrong with it. If I type something > > between them, it says that there is something wrong with the quotation > > marks. If I just leave it like (), then it says that something is > > wrong with what is after the parentheses. Unless my code is supposed > > to go between the parentheses. I'll try that. > > Between the parentheses should go the variables you use (if any) when > calling the function. For example: > > def sayhello(): > print "Hello" > > You don't have any parameters here, so there's nothing between the > brackets > > def say(word): > print word > > Now there is one parameter, namely word. > > def sayboth(word1,word2): > print word1 > print word2 > > Here there are two parameters, word1 and word2. > > The number of parameters should be the same as the number of > parameters you use when calling the function: > > sayhello() > say("One text") > sayboth("One text","Another text") > > There is a much used method to make some of the parameters optional, > but we'll not go into that. > > To know what is going wrong with your program, I would have to see the > program (or a simplified version of it that still goes wrong) and > preferably also the exact error message you are getting. > > > -- > Andre Engels, [EMAIL PROTECTED] > ICQ: 6260644 -- Skype: a_engels > ___ > 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] [Fwd: Re: trouble with "if"]
Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > I can't exactly show you the error message anymore, because the program is > now screwed up in so many ways that I can't even get it to do the things it > used to. > > It says things like ERROR: Inconsistent indentation detected! > 1) Your indentation is outright incorrect (easy to fix), OR > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > everything, which i did and it still gives this message. I've started > completely over with the exact same indentation and that one works. > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > here > last night. I have no idea what was going on then, but everything you guys > said is right here. The plain text is right next to the Check spelling, > the > reply to all is right above send and save now and in the corner near the > little arrow. Well, it's working now. > > Ok, so if i have a section of code that is: > > answer=(2+3): > print "answer", answer > > so for the code above I would put: (I think I would have to have the two > numbers and the addition thing in there wouldn't I; I saw something like > this on Alan's tutorial last night.) > > def answer(2,3): >answer=(2+3) >print "answer",answer > > That is obviously not right.: > > There's an error in your program: > invalid syntax > > when it says that it highlights the 2: def answer(2+3): > > Ok I think I understand these now. Thanks for the advice. I have this > now: > > def answer(): >print("answer") > answer() > > It works too, yay! > Thanks, > > Au > Adam, Glad you are sorting out the gmail---in the long run, plain text will make this all much easier than what you had before :-) Your answer function definition above is saying something like this: make answer the name of a function that takes no parameters, and, when called, have it execute a print. This: > def answer(2,3): >answer=(2+3) >print "answer",answer doesn't work, as you are trying to set the values of the two parameters to 2 and 3 in the function definition itself. That's not how parameters work. The definition of a function sets the parameters up as named `slots' that function calls will give values to. (There are, as Andre pointed out, more details, but let those aside for now and focus on the simplest cases.) This: def answer(): answer=(2+3) print "answer",answer would work, but it isn't much different than the code that did work. Try this: def answer(my_first_parameter, my_second_parameter): value = my_first_parameter + my_second_parameter print "Answer:\t", value (I wouldn't use the cumbersome names `my_first_parameter', etc. in real code, but perhaps they help keeping track of what is going on in early stages.) That says, in effect, let answer be a function which takes two positional parameters, adds them, and prints the result in an informative way. >>> answer(40, 2) Answer: 42 >>> answer("A string", " and another string") Answer: A string and another string >>> These work because the function definition ensures that the first parameter (40, in the first case above) will, as far as the function is concerned, be called my_first_parameter. (Likewise for 2 and my_second_parameter.) Does that help? Brian vdB ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] python exercises
Anyone know where I can get some python excercises, like labs/someone's old homework assignments? I'm learning python without any prior experience in programming except for fundamental bash scripting and a lot of the terms and functionality doesn't make sense to me. I'm using Python Programming for the Absolute Beginner by Michael Dawson . -- Michael Revelle ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python exercises
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Michael Revelle > > Anyone know where I can get some python excercises, like > labs/someone's old homework assignments? There are some ideas at http://effbot.org/pyfaq/tutor-im-learning-python-what-should-i-program.h tm or http://tinyurl.com/yalvar Mike ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: Re: trouble with "if"]
I can't seem to get the type with the parameters to work. I can get def answer(): to work, but not def answer(my_first_parameter,my_second_parameter):. I'm not too concerned, as I haven't yet needed to use that. But, when I use the parameter type, it runs without error messages, but doesn't display anything. That's when I'm using your example with my_first_parameter. But when I use: def answer(40,2): answer=40+2 print "Answer:\t", value answer() it says: There's an error in your program: invalid syntax and then it highlights the first number between the parentheses, like last time. OK. New topic temporarily... I just completed a portion of my radiacir.py program, after much debugging. I still want to add that error message thing that we discussed eariler, but that's a whole nother can of worms. So I'm going to attach it. This is very exciting. Except, I renamed it and now it doesn't work. This frustrates me. How could something work one second and then not the next. Oh well, I'll still attach it and if you could help me find the problem, that would be nice. Thanks, Au On 5/30/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > > I can't exactly show you the error message anymore, because the program is > > now screwed up in so many ways that I can't even get it to do the things it > > used to. > > > > It says things like ERROR: Inconsistent indentation detected! > > 1) Your indentation is outright incorrect (easy to fix), OR > > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > > everything, which i did and it still gives this message. I've started > > completely over with the exact same indentation and that one works. > > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > > here > > last night. I have no idea what was going on then, but everything you guys > > said is right here. The plain text is right next to the Check spelling, > > the > > reply to all is right above send and save now and in the corner near the > > little arrow. Well, it's working now. > > > > Ok, so if i have a section of code that is: > > > > answer=(2+3): > > print "answer", answer > > > > so for the code above I would put: (I think I would have to have the two > > numbers and the addition thing in there wouldn't I; I saw something like > > this on Alan's tutorial last night.) > > > > def answer(2,3): > >answer=(2+3) > >print "answer",answer > > > > That is obviously not right.: > > > > There's an error in your program: > > invalid syntax > > > > when it says that it highlights the 2: def answer(2+3): > > > > Ok I think I understand these now. Thanks for the advice. I have this > > now: > > > > def answer(): > >print("answer") > > answer() > > > > It works too, yay! > > Thanks, > > > > Au > > > > > Adam, > > Glad you are sorting out the gmail---in the long run, plain text will > make this all much easier than what you had before :-) > > Your answer function definition above is saying something like this: > make answer the name of a function that takes no parameters, and, when > called, have it execute a print. > > This: > > > def answer(2,3): > >answer=(2+3) > >print "answer",answer > > doesn't work, as you are trying to set the values of the two > parameters to 2 and 3 in the function definition itself. That's not > how parameters work. The definition of a function sets the parameters > up as named `slots' that function calls will give values to. (There > are, as Andre pointed out, more details, but let those aside for now > and focus on the simplest cases.) > > This: > > def answer(): > answer=(2+3) > print "answer",answer > > would work, but it isn't much different than the code that did work. > > Try this: > > def answer(my_first_parameter, my_second_parameter): > value = my_first_parameter + my_second_parameter > print "Answer:\t", value > > (I wouldn't use the cumbersome names `my_first_parameter', etc. in > real code, but perhaps they help keeping track of what is going on in > early stages.) > > That says, in effect, let answer be a function which takes two > positional parameters, adds them, and prints the result in an > informative way. > > >>> answer(40, 2) > Answer: 42 > >>> answer("A string", " and another string") > Answer: A string and another string > >>> > > These work because the function definition ensures that the first > parameter (40, in the first case above) will, as far as the function > is concerned, be called my_first_parameter. (Likewise for 2 and > my_second_parameter.) > > Does that help? > > Brian vdB > ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: Re: trouble with "if"]
I think I may have figured it out. I just switched some things around. On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: I can't seem to get the type with the parameters to work. I can get def answer(): to work, but not def answer(my_first_parameter,my_second_parameter):. I'm not too concerned, as I haven't yet needed to use that. But, when I use the parameter type, it runs without error messages, but doesn't display anything. That's when I'm using your example with my_first_parameter. But when I use: def answer(40,2): answer=40+2 print "Answer:\t", value answer() it says: There's an error in your program: invalid syntax and then it highlights the first number between the parentheses, like last time. OK. New topic temporarily... I just completed a portion of my radiacir.py program, after much debugging. I still want to add that error message thing that we discussed eariler, but that's a whole nother can of worms. So I'm going to attach it. This is very exciting. Except, I renamed it and now it doesn't work. This frustrates me. How could something work one second and then not the next. Oh well, I'll still attach it and if you could help me find the problem, that would be nice. Thanks, Au On 5/30/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > > I can't exactly show you the error message anymore, because the program is > > now screwed up in so many ways that I can't even get it to do the things it > > used to. > > > > It says things like ERROR: Inconsistent indentation detected! > > 1) Your indentation is outright incorrect (easy to fix), OR > > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > > everything, which i did and it still gives this message. I've started > > completely over with the exact same indentation and that one works. > > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > > here > > last night. I have no idea what was going on then, but everything you guys > > said is right here. The plain text is right next to the Check spelling, > > the > > reply to all is right above send and save now and in the corner near the > > little arrow. Well, it's working now. > > > > Ok, so if i have a section of code that is: > > > > answer=(2+3): > > print "answer", answer > > > > so for the code above I would put: (I think I would have to have the two > > numbers and the addition thing in there wouldn't I; I saw something like > > this on Alan's tutorial last night.) > > > > def answer(2,3): > >answer=(2+3) > >print "answer",answer > > > > That is obviously not right.: > > > > There's an error in your program: > > invalid syntax > > > > when it says that it highlights the 2: def answer(2+3): > > > > Ok I think I understand these now. Thanks for the advice. I have this > > now: > > > > def answer(): > >print("answer") > > answer() > > > > It works too, yay! > > Thanks, > > > > Au > > > > > Adam, > > Glad you are sorting out the gmail---in the long run, plain text will > make this all much easier than what you had before :-) > > Your answer function definition above is saying something like this: > make answer the name of a function that takes no parameters, and, when > called, have it execute a print. > > This: > > > def answer(2,3): > >answer=(2+3) > >print "answer",answer > > doesn't work, as you are trying to set the values of the two > parameters to 2 and 3 in the function definition itself. That's not > how parameters work. The definition of a function sets the parameters > up as named `slots' that function calls will give values to. (There > are, as Andre pointed out, more details, but let those aside for now > and focus on the simplest cases.) > > This: > > def answer(): > answer=(2+3) > print "answer",answer > > would work, but it isn't much different than the code that did work. > > Try this: > > def answer(my_first_parameter, my_second_parameter): > value = my_first_parameter + my_second_parameter > print "Answer:\t", value > > (I wouldn't use the cumbersome names `my_first_parameter', etc. in > real code, but perhaps they help keeping track of what is going on in > early stages.) > > That says, in effect, let answer be a function which takes two > positional parameters, adds them, and prints the result in an > informative way. > > >>> answer(40, 2) > Answer: 42 > >>> answer("A string", " and another string") > Answer: A string and another string > >>> > > These work because the function definition ensures that the first > parameter (40, in the first case above) will, as far as the function > is concerned, be called my_first_parameter. (Likewise for 2 and > my_second_parameter.) > > Does that help? > > Brian vdB > #Welcome screen: def welcome(): print "Welcome to the Area Calculation Program." print welcome() #Shape choice: def shape(): print "Choose a Shape:" print "1 Circle" print
[Tutor] problem with mmap
All, I am trying to work an example that I found at http://bitworking.org/news/132/REST-Tips-URI-space-is-infinite When I try the code below I get an error and I am not able to figure it out. Thanks for any and all help. I have two png and a text file (sortzip.txt) in the same dir as this code but I do not even get to that part...the mmap call is bad. I have never used mmap before so this is new to me. I am running python 2.4 John # code from mmap import mmap import os from bisect import bisect_left import sys class Zipcodes(object): """Use mmap to treat the sorted file of zipcodes as an array""" def __init__(self): self.f = open("sortzips.txt", "r+") self.size = os.path.getsize("sortzips.txt") self.m = mmap(self.f.fileno(), self.size) def __getitem__(self, i): self.m.seek(6*i) return self.m.read(5) def __del__(self): self.m.close() self.f.close() def __len__(self): return self.size / 6 zipcodes = Zipcodes() target = os.environ.get('PATH_INFO', '/')[1:] found = ( zipcodes[bisect_left(zipcodes, target)] == target ) print "Status: " + ( found and "200 Ok" or "404 Not Found" ) print "Cache-control: max-age=172800" print "Content-type: image/png" print "" file = open(found and "good.png" or "bad.png", "r") png = file.read() file.close() sys.stdout.write(png) ## error message when I try to run this. Traceback (most recent call last): File "./zipcode.cgi", line 23, in ? zipcodes = Zipcodes() File "./zipcode.cgi", line 14, in __init__ self.m = mmap(self.f.fileno(), self.size) EnvironmentError: [Errno 22] Invalid argument Exception exceptions.AttributeError: "'Zipcodes' object has no attribute 'm'" in > ignored ### John Ertl Meteorologist FNMOC 7 Grace Hopper Ave. Monterey, CA 93943 (831) 656-5704 [EMAIL PROTECTED] <>___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Fwd: Re: trouble with "if"]
Ok I forgot to put some things on the previous one. I discovered a flaw in my loop. It is not infinite. If you select circle, radius, enter the radius, circle, radius, enter the radius, then the program stops. I want it to be able to keep going as many times as needed, infinitely. So that the user could keep using that segment of the program over and over again, without having to restart the program. Is it possible to do that? On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: I think I may have figured it out. I just switched some things around. On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > I can't seem to get the type with the parameters to work. I can get > def answer(): to work, but not def > answer(my_first_parameter,my_second_parameter):. I'm not too > concerned, as I haven't yet needed to use that. But, when I use the > parameter type, it runs without error messages, but doesn't display > anything. That's when I'm using your example with my_first_parameter. > But when I use: > > def answer(40,2): > answer=40+2 > print "Answer:\t", value > answer() > > it says: > > There's an error in your program: > invalid syntax > > and then it highlights the first number between the parentheses, like last time. > > OK. New topic temporarily... I just completed a portion of my > radiacir.py program, after much debugging. I still want to add that > error message thing that we discussed eariler, but that's a whole > nother can of worms. So I'm going to attach it. This is very > exciting. Except, I renamed it and now it doesn't work. This > frustrates me. How could something work one second and then not the > next. Oh well, I'll still attach it and if you could help me find the > problem, that would be nice. > > Thanks, > Au > On 5/30/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > > Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > > > I can't exactly show you the error message anymore, because the program is > > > now screwed up in so many ways that I can't even get it to do the things it > > > used to. > > > > > > It says things like ERROR: Inconsistent indentation detected! > > > 1) Your indentation is outright incorrect (easy to fix), OR > > > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > > > everything, which i did and it still gives this message. I've started > > > completely over with the exact same indentation and that one works. > > > > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > > > here > > > last night. I have no idea what was going on then, but everything you guys > > > said is right here. The plain text is right next to the Check spelling, > > > the > > > reply to all is right above send and save now and in the corner near the > > > little arrow. Well, it's working now. > > > > > > Ok, so if i have a section of code that is: > > > > > > answer=(2+3): > > > print "answer", answer > > > > > > so for the code above I would put: (I think I would have to have the two > > > numbers and the addition thing in there wouldn't I; I saw something like > > > this on Alan's tutorial last night.) > > > > > > def answer(2,3): > > >answer=(2+3) > > >print "answer",answer > > > > > > That is obviously not right.: > > > > > > There's an error in your program: > > > invalid syntax > > > > > > when it says that it highlights the 2: def answer(2+3): > > > > > > Ok I think I understand these now. Thanks for the advice. I have this > > > now: > > > > > > def answer(): > > >print("answer") > > > answer() > > > > > > It works too, yay! > > > Thanks, > > > > > > Au > > > > > > > > > Adam, > > > > Glad you are sorting out the gmail---in the long run, plain text will > > make this all much easier than what you had before :-) > > > > Your answer function definition above is saying something like this: > > make answer the name of a function that takes no parameters, and, when > > called, have it execute a print. > > > > This: > > > > > def answer(2,3): > > >answer=(2+3) > > >print "answer",answer > > > > doesn't work, as you are trying to set the values of the two > > parameters to 2 and 3 in the function definition itself. That's not > > how parameters work. The definition of a function sets the parameters > > up as named `slots' that function calls will give values to. (There > > are, as Andre pointed out, more details, but let those aside for now > > and focus on the simplest cases.) > > > > This: > > > > def answer(): > > answer=(2+3) > > print "answer",answer > > > > would work, but it isn't much different than the code that did work. > > > > Try this: > > > > def answer(my_first_parameter, my_second_parameter): > > value = my_first_parameter + my_second_parameter > > print "Answer:\t", value > > > > (I wouldn't use the cumbersome names `my_first_parameter', etc. in > > real code, but perhaps they help keeping track of what is going on in > > early stages.) > > > > T
Re: [Tutor] monitor other running applications with Py
Thanks for the pointers, Alan. It seems perhaps a bit beyond my abilities for now, but something to keep in mind for the future if I get that far. And yes, the legal aspects are worth noting, though rest assured my wish for such a thing is for self-monitoring rather than other-monitoring, though I can see how it could get used nefariously if not cautious. Best, Che Date: Sun, 27 May 2007 15:54:11 +0100 From: "Alan Gauld" <[EMAIL PROTECTED]> Subject: Re: [Tutor] monitor other running applications with Python? To: tutor@python.org Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Che M" <[EMAIL PROTECTED]> wrote > Hi, searched a bit for this but haven't found much. > Is it possible to use Python to monitor the use of > other applications? Yes, definitely. > At minimum, I wan't to know that the application was running Thats fairly easy using OS tools such as ps on Unix. You can dig a little deeper and use the system APIs such as the proc fiilesystem or the equivalent in the windows registry. > better would be some sense of the use or content, such > as whether the app was idle or the user was using it, > or, for a web browser, what URLs were visited and for > how long, etc. Thats possible but gets very OS specific and very low level too. On Windows you can catch Windows events and messages using some of the raw Win32 API calls from the ctypes module. (I've never used ctypes for anything this low level but it should be possible, I''ve certainly done it in C++ and Delphi on Win 9X). But its messy and fairly deep Windows magic and you will need to spend a fair bit of time experimenting and reading the docs on MSDN as well as the Win32 API help file. > Ideally I'd like a cross-platforms approach I doubt if that's possible except at the process monitoring level. For the kind of detail you want the bgestb you can do is have a common UI and pluggable modules based on the OS. Also beware legal implications. There are issues around personal privacy, data proptection etc and these vary between countries (and even states in the US). People are increasingly wary of Big Brother style monitoring. Detecting inappropriate use of the internet across a corporate firwall is generally considered OK but silently monitoring individuals brings you into murky legal waters. Finally, take a look at the stuff in the os package and the syslog module for Unix. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.freenetpages.co.uk/hp/alan.gauld -- Message: 2 Date: Sun, 27 May 2007 12:25:17 -0500 From: adam urbas <[EMAIL PROTECTED]> Subject: [Tutor] error message questions To: python tutor Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="windows-1252" Hello all,I was wondering if there would be someone who would be able to give me a list of error messages and their meanings. I've attached this test.py to illustrate my problem. When I run the program, I am able to enter all the data, yet it will not calculate.It says:can't multiply sequence by non-int of type 'str'I really would like to know how to fix this.I get a similar message with my other one, radiacir.py:can't multiply sequence by non-int of type 'float'Please help!Thanks in advance,Adam _ Change is good. See what?s different about Windows Live Hotmail. http://www.windowslive-hotmail.com/learnmore/default.html?locale=en-us&ocid=RMT_TAGLM_HMWL_reten_changegood_0507 -- next part -- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment.html -- next part -- An embedded and charset-unspecified text was scrubbed... Name: test.py Url: http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment-0001.pot -- next part -- An embedded and charset-unspecified text was scrubbed... Name: radiacir.py Url: http://mail.python.org/pipermail/tutor/attachments/20070527/167120aa/attachment-0001.asc -- Message: 3 Date: Sun, 27 May 2007 12:49:04 -0500 From: adam urbas <[EMAIL PROTECTED]> Subject: Re: [Tutor] trouble with "if" To: Brian van den Broek <[EMAIL PROTECTED]> Cc: python tutor Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="windows-1252" Thank you for the help Brian. I would like to ask you about these things. Which one of the examples you gave would be most fool proof.> Date: Wed, 23 May 2007 13:40:09 -0400> From: [EMAIL PROTECTED]> To: [EMAIL PROTECTED]> CC: tutor@python.org> Subject: Re: [Tutor] trouble with "if"> > adam urbas said unto the world upon 05/23/2007 01:04 PM:> > Sorry, I don't think Hotmail has turn off HTML. If it does I> > havn't been able to find it. I think you're going to have to> > explain your little bit of text stuff
Re: [Tutor] [Fwd: Re: trouble with "if"]
Once again this is my latest version. I know of several problems, such as the previously posted infinite looping problem. Also, if sends you to the wrong place sometimes. Ex: a second ago, I pressed 4 to exit (which does not work either) and it took me to triangle. I'm not sure how to end the program. It takes you to the def goodbye(): part, but then if you press enter again, it starts the program over. I was hoping that if I just left it blank, then it would just automatically end, like it does with simpler programs, but that was not the case, because apparently there has to be something after the def goodbye(): So If someone wouldn't mind taking a look at it, then I would be very grateful. Thanks, Au On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: Ok I forgot to put some things on the previous one. I discovered a flaw in my loop. It is not infinite. If you select circle, radius, enter the radius, circle, radius, enter the radius, then the program stops. I want it to be able to keep going as many times as needed, infinitely. So that the user could keep using that segment of the program over and over again, without having to restart the program. Is it possible to do that? On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > I think I may have figured it out. I just switched some things around. > > On 5/30/07, Adam Urbas <[EMAIL PROTECTED]> wrote: > > I can't seem to get the type with the parameters to work. I can get > > def answer(): to work, but not def > > answer(my_first_parameter,my_second_parameter):. I'm not too > > concerned, as I haven't yet needed to use that. But, when I use the > > parameter type, it runs without error messages, but doesn't display > > anything. That's when I'm using your example with my_first_parameter. > > But when I use: > > > > def answer(40,2): > > answer=40+2 > > print "Answer:\t", value > > answer() > > > > it says: > > > > There's an error in your program: > > invalid syntax > > > > and then it highlights the first number between the parentheses, like last time. > > > > OK. New topic temporarily... I just completed a portion of my > > radiacir.py program, after much debugging. I still want to add that > > error message thing that we discussed eariler, but that's a whole > > nother can of worms. So I'm going to attach it. This is very > > exciting. Except, I renamed it and now it doesn't work. This > > frustrates me. How could something work one second and then not the > > next. Oh well, I'll still attach it and if you could help me find the > > problem, that would be nice. > > > > Thanks, > > Au > > On 5/30/07, Brian van den Broek <[EMAIL PROTECTED]> wrote: > > > Adam Urbas said unto the world upon 05/30/2007 11:01 AM: > > > > I can't exactly show you the error message anymore, because the program is > > > > now screwed up in so many ways that I can't even get it to do the things it > > > > used to. > > > > > > > > It says things like ERROR: Inconsistent indentation detected! > > > > 1) Your indentation is outright incorrect (easy to fix), OR > > > > 2) Your indentation mixes tabs and spaces. Then it tells me to untabify > > > > everything, which i did and it still gives this message. I've started > > > > completely over with the exact same indentation and that one works. > > > > > > > > Oh my gosh this gmail is a fricken crack head... none of this stuff was > > > > here > > > > last night. I have no idea what was going on then, but everything you guys > > > > said is right here. The plain text is right next to the Check spelling, > > > > the > > > > reply to all is right above send and save now and in the corner near the > > > > little arrow. Well, it's working now. > > > > > > > > Ok, so if i have a section of code that is: > > > > > > > > answer=(2+3): > > > > print "answer", answer > > > > > > > > so for the code above I would put: (I think I would have to have the two > > > > numbers and the addition thing in there wouldn't I; I saw something like > > > > this on Alan's tutorial last night.) > > > > > > > > def answer(2,3): > > > >answer=(2+3) > > > >print "answer",answer > > > > > > > > That is obviously not right.: > > > > > > > > There's an error in your program: > > > > invalid syntax > > > > > > > > when it says that it highlights the 2: def answer(2+3): > > > > > > > > Ok I think I understand these now. Thanks for the advice. I have this > > > > now: > > > > > > > > def answer(): > > > >print("answer") > > > > answer() > > > > > > > > It works too, yay! > > > > Thanks, > > > > > > > > Au > > > > > > > > > > > > > Adam, > > > > > > Glad you are sorting out the gmail---in the long run, plain text will > > > make this all much easier than what you had before :-) > > > > > > Your answer function definition above is saying something like this: > > > make answer the name of a function that takes no parameters, and, when > > > called, have it execute a print. > > > > > > This: > > > > > > > def answer(2,3
Re: [Tutor] python exercises
the daniweb forum has a beginners project sticky: http://www.daniweb.com/techtalkforums/thread32007.html On 5/30/07, Mike Hansen <[EMAIL PROTECTED]> wrote: > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Michael Revelle > > Anyone know where I can get some python excercises, like > labs/someone's old homework assignments? There are some ideas at http://effbot.org/pyfaq/tutor-im-learning-python-what-should-i-program.h tm or http://tinyurl.com/yalvar Mike ___ 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] leave tutorial
i want to leave the tutorial Looking for people who are YOUR TYPE? Find them at in.groups.yahoo.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] leave tutorial
http://mail.python.org/mailman/listinfo/tutor On 5/30/07, Kriti Satija <[EMAIL PROTECTED]> wrote: i want to leave the tutorial Looking for people who are YOUR TYPE? Find them at in.groups.yahoo.com ___ 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] python exercises
> Anyone know where I can get some python excercises, like > labs/someone's old homework assignments? I'm learning python without > any prior experience in programming except for fundamental bash > scripting and a lot of the terms and functionality doesn't make sense > to me. michael, i put a *lot* of exercises into Core Python (see link below). there are exercises at the end of every chapter. the book, however, targets those with prior programming experience. since you've done shell scripting before, you aren't exactly a complete newbie. i think what would also be valuable to you would be the numerous interactive interpreter examples... you can follow along with or without a computer in front of you. seeing all those examples will hopefully clear up some of the confusion you have now. if you go to the book's website, there should be a link to download a free chapter to see if it's right for you. also, if you have any particular areas of trouble/understanding, and/or have code snippets, including errors, feel free to post them here for the tutors to look at. good luck! -- wesley - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "Core Python Programming", Prentice Hall, (c)2007,2001 http://corepython.com wesley.j.chun :: wescpy-at-gmail.com python training and technical consulting cyberweb.consulting : silicon valley, ca http://cyberwebconsulting.com ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] leave tutorial
Nobody leaves the tutorial. http://mail.python.org/mailman/listinfo/tutor (at the bottom of the page) On 5/30/07, Kriti Satija <[EMAIL PROTECTED]> wrote: i want to leave the tutorial Looking for people who are YOUR TYPE? Find them at in.groups.yahoo.com ___ 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] [Fwd: Re: trouble with "if"]
Hi Adam > flaw in my loop. It is not infinite. In fact you don't have a loop, your program is really just a simple sequence. #Welcome screen: def welcome(): print "Welcome to the Area Calculation Program." print welcome() AG:Since you only call this once there is no point in putting AG: it in a functuion #Shape choice: def shape(): print "Choose a Shape:" print "1 Circle" print "2 Square" print "3 Triangle" print "4 Exit" print shape() AG: And you call this here and again at the end of the code. AG: But its not in a loop, its just two calls to the same function. #If circle: def circle(): shape=raw_input(">") if shape in["1","circle"]: print "1 Radius" print "2 Diameter" print "3 Circumference" print "4 Area" print circle() AG: And this gets a string fom the user and prints one of the AG: values but doesn't do anything with it. Functions should AG: normally do more than just print some values. AG: You never use the menu you print. #If radius: def radius(): radius=int(raw_input("Enter Radius:")) diameter=(radius*2) circumference=(diameter*3.14) area=(radius**2*3.14) print "Diameter",diameter print "Circumference",circumference print "Area",area print print def choice(): given=raw_input(">") if given in["1","radius"]: radius() choice() AG: Now you call radius which actually does some work shape() choice() AG: Then you call shape but don't use the result then call AG: choice which only works for circles. AG:If we use the more conventional approach of defining the AG: functins first then calling them at the end your code AG: looks like this: welcome() shape() circle() choice() #--> which calls radius() shape() choice() As you see there is no loop just a sequence of function calls. Now if I rename your functions to reflect what theyactually do: printWelcomeMessage() printShapeMenu() getShapeAndIfCirclePrintCircleParameterNames() getParameterAndIfRadiuscallRadius() -> getRadiusCalculateResultsAndPrintThem() printShapeMenu() getParameterAndIfRadiuscallRadius() -> getRadiusCalculateResultsAndPrintThem() Hopefully this illustrates several things: 1) Naming your functions to reflect what they actually do helps see what the code does 2) Especially if you group the function calls together at the end of your program 3) Your functions are mixing up the presentation of menus and the getting of values. A better structure might be to do something like: shape = 0 # a variable to store the shape printWelcomeMessage() printShapeMenuAndGetValue() #---store he result in the shape variable if shape in['1','circle']: doAllCircleStuff() else: print "Only circles supported for now!" And then its easy to wrap that in a real loop shape = 0 # a variable to store the shape printWelcomeMessage() while shape == 0: printShapeMenuAndGetValue() #---store he result in the shape variable if shape in['1','circle']: doAllCircleStuff() shape = 0 # reset shape back to zero else: print "Only circles supported for now!" Can you rewrite your functions to match that? You need to change the shape() function so that it sets the shape global variable to the value input by the user. You will need to include the statement global shape at the top of the function for that to work. The other (and better) way is to use the return statement to return the value. BTW I'm not really suggesting you use those long names, they were just to point out what the functions were really doing! HTH, Alan G. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Web-based Python Training
Hello, I work as a Learning & Development Director in a mid-size technology company outside of Boston, Massachusetts. Our engineers are looking for either a web-based Python course, or an online instructor-led Python course. They already work with and know other programming languages. Do you know of any companies that offer Python via the web? Thank you, Linda Landry Linda Landry Director, Learning and Development Nuance Communications, Inc. Phone: 781/565-4950 nuance.com The experience speaks for itself (tm) ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Web-based Python Training
"Linda Landry" <[EMAIL PROTECTED]> wrote > I work as a Learning & Development Director in a mid-size technology > company outside of Boston, Massachusetts. Our engineers are looking > for > either a web-based Python course, or an online instructor-led Python > course. They already work with and know other programming languages. There are a wealth of Web resources for learning Python including the official tutorial on the python.org web site. Another good resource is the online book Dive into Python. If they are expertienced those should do to start them off and the Python mailing lists and wikis cover most areas of interest. And during the learning period this list is suited to both total novices and language switchers. -- 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
[Tutor] How can I see properly my korean.
I input the data which is from the database into array. and then I print out the array to the file but the letter I can not figure out. fileHandle = open ( '/var/chroot/www/htdocs/django/js/model.js', 'w' ) fileHandle.write( codecs.BOM_UTF8 ) print >> fileHandle, 'var blog = ' print >> fileHandle, blog fileHandle.close() this is the file model.js var blog = {'description': '\xec\xb9\xb4\xed\x86\xa8\xeb\xa6\xad \xed\x91\xb8\xeb\xa6\x84\xed\x84\xb0', 'links': [{'link': ' www.hideout.com.br', 'title': 'ggum'}, {'link': 'www.hideout.com.br', 'title': 'hideout'}, {'link': 'www.hideout.com.br', 'title': 'hideout'}, {'link': 'www.hideout.com.br', 'title': 'hideout'}], 'title': u'\uce74\ud1a8\ub9ad \ud478\ub984\ud130', 'items': [{'body': '\xeb\xaf\xbc\xec\x95\x84\xeb\x9e\x80\xe3\x85\x81\xec\x95\x8c\r\n\r\n\xed\x85\x8c\xec\x8a\xa4\xed\x8a\xb8\xec\x9e\x85\xeb\x8b\x88\xe3\x85\x8f.', 'permalink': 'perma link', 'author': 'ggum', 'title': '\xec\xb2\xab\xeb\xb2\x88 \xec\xa7\xb8 \xea\xb3\xb5\xec\xa7\x80\xec\x82\xac\xed\x95\xad', 'comments': [{'comment': 'blah', 'author': 'ygp', 'dateTime': '10:43 7/20/2004'}], 'time': '13234 23423423'}, {'body': '\xec\x98\xa4\xeb\x8a\x98\xec\x9d\x80 \xec\xa0\x95\xeb\xa7\x90 \xec\x9e\xac\xeb\xb0\x8c\xec\x97\x88\xeb\x8b\xa4.\r\n\r\n\xeb\x98\x90 \xed\x95\x9c\xeb\xb2\x88 \xeb\x8d\x94...', 'permalink': 'perma link', 'author': 'ggum', 'title': '\xec\x98\xa4\xeb\x8a\x98\xec\x9d\x98 \xec\x9d\xb4\xec\x95\xbc\xea\xb8\xb0', 'comments': [{'comment': 'blah', 'author': 'ygp', 'dateTime': '10:43 7/20/2004'}], 'time': '13234 23423423'}], 'currentPost': {'dateIndex': 0, 'postIndex': 0}, 'sections': [{'link': 'www.hideout.com.br', 'title': '\xea\xb3\xb5\xec\xa7\x80\xec\x82\xac\xed\x95\xad'}, {'link': ' www.hideout.com.br', 'title': '\xec\x9a\xb0\xeb\xa6\xac\xeb\x93\xa4\xec\x9d\x98 \xec\x9d\xb4\xec\x95\xbc\xea\xb8\xb0'}, {'link': 'www.hideout.com.br', 'title': '\xed\x9b\x84\xec\x9b\x90'}]} What I want to do is to see properly the letter not this letter '\xec\x9d' Can anyone who know solution let me know how to do kindly? Thanks a lot. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor