[Tutor] return values function
Hello I am hoping someone can put me on the right track. The code below includes the assignment question at the beginning. I seem to have been able to calculate average ok, but what I can't seem to do is sort it so it will return a grade for each result. Can you give me some advice to head me in the right direction please. My code is: """Write a program that asks the user to enter 5 sets tests scores. The program should then display the 'letter grade' (A, B, C, D, F) for each test score, and the overall average test schore. Write the following functions in the program: * Calc_average: This function should take five test scores as parameters, and return the average score. *determine_grade; this function should take a single test score as a parameter, and return a letter grade for the test. The letter grade should be on the following grade scale: 90-100: A, 80-89: B, 70-79: C, 60-69: D, <60: F.""" def main(): #Get users first test result test1 = int(raw_input('Enter the score for test 1: ')) #Get users second test result test2 = int(raw_input('Enter the score for test 2: ')) #Get users third test result test3 = int(raw_input('Enter the score for test 3: ')) #Get users forth test result test4 = int(raw_input('Enter the score for test 4: ')) #Get users fifth test result test5 = int(raw_input('Enter the score for test 5: ')) #Get the sum of the test results cal_average = sum(test1, test2, test3, test4, test5)/5 #Display the total of tests print 'Together your tests average is: ', cal_average print 'Your grade is: ', grade # The sum function to total all tests def sum(test1, test2, test3, test4, test5): result = test1 + test2 + test3 + test4 + test5 return result def determine_grade(score): #Determine the grade for each score if score <101 and score >89: score = A elif score <90 and score >79: score = B elif score <80 and score >69: score = C elif score <70 and score >59: score = D else: score = F return score # Call the main function main() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] return values function
"Lea Parker" wrote Write the following functions in the program: * Calc_average: This function should take five test scores as parameters, and return the average score. Note that you are supposed to write a function to do this not just do it inline. *determine_grade; this function should take a single test score as a parameter, and return a letter grade for the test. The letter grade should be on the following grade scale: 90-100: A, 80-89: B, 70-79: C, 60-69: D, <60: F.""" def main(): #Get users first test result test1 = int(raw_input('Enter the score for test 1: ')) test2 = int(raw_input('Enter the score for test 2: ')) test3 = int(raw_input('Enter the score for test 3: ')) test4 = int(raw_input('Enter the score for test 4: ')) test5 = int(raw_input('Enter the score for test 5: ')) Every time you see repeating code like that you should ask, can I use a loop? If you store the results in a list, it then becomes a simple job to read 5 results: for n in range(5): results.append( int(raw_input('Enter the score for test %d:" % n')) ) #Get the sum of the test results cal_average = sum(test1, test2, test3, test4, test5)/5 This is the average not the sum so your comment is wrong. It's also where you should be using the function you were asked to define. The function body would look like the line above. print 'Together your tests average is: ', cal_average print 'Your grade is: ', grade And here you need to call your other function to work out the grade. But again you need to call it for each score. You can repeat it 5 times as you did for raw_input or you could use the loop; method I showed you above. # The sum function to total all tests def sum(test1, test2, test3, test4, test5): result = test1 + test2 + test3 + test4 + test5 return result You didn't need this because Python already has a sum() function that will do this for you. def determine_grade(score): #Determine the grade for each score if score <101 and score >89: score = A elif score <90 and score >79: score = B elif score <80 and score >69: score = C elif score <70 and score >59: score = D else: score = F return score The most serious problem, and it should have thrown an error, is that the results need to be strings. Otherwise Python will look for a variable called A,B,C etc. And no such name exists in your code. Its not a good idea to use score for both the input parameter that you test and the result that you return. In this case you should get away with it because you never use score after you set it but in general you run the risk of losing access to the input value after you assign a result to score. In the comparisons Python allows you to write them like if 101 > score > 89: grade = "A" which is slightly easier to type and read. HTH, -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Problem with running Python
Hello all, I am new to programming on Python and am teaching myself. I have figured out some basics of coding, however whenever I try to run the program or check its functionality (Alt + X on my windows) it always comes back saying that "there's an error in your program: invalid syntax." However, when it returns to the IDLE page and highlights the error, it highlights the 7 in the python 2.7.1 above any coding. And if I am able to delete that text, it then links the syntax error to the multiple '>' in the code. Is this a common issue with a simple fix? Thanks Alex Butler ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem with running Python
On 22-Apr-11 07:13, Alex Butler wrote: Hello all, I am new to programming on Python and am teaching myself. I have figured Hi, Alex, welcome to programming and the Python language. If you want to get the most out of this list, it helps to ask very specific questions, showing what you have tried so far to figure out your problem, with what results. Including examples of your actual code and actual error messages is enormously helpful. out some basics of coding, however whenever I try to run the program or check its functionality (Alt + X on my windows) it always comes back saying that “there’s an error in your program: invalid syntax.” However, when it returns to the IDLE page and highlights the error, it highlights the 7 in the python 2.7.1 above any coding. And if I am able to delete that text, it then links the syntax error to the multiple ‘>’ in the code. Is this a common issue with a simple fix? Thanks It sounds to me like you're confusing the actual program code with other stuff like the >>> prompt Python's interpreter types to you. Are you cutting and pasting more into IDLE than the Python program code itself? You should not have things like "Python 2.7.1" or ">>>" showing up in your source code. -- Steve Willoughby / st...@alchemy.com "A ship in harbor is safe, but that is not what ships are built for." PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem with running Python
"Alex Butler" wrote I am new to programming on Python and am teaching myself. I have figured out some basics of coding, however whenever I try to run the program or check its functionality (Alt + X on my windows) it always comes back saying that "there's an error in your program: invalid syntax." However, when it returns to the IDLE page and highlights the error, it highlights the 7 in the python 2.7.1 above any coding. And if I am able to delete that text, it then links the syntax error to the multiple '>' in the code. Is this a common issue with a simple fix? Thanks It sounds like you may be trying to execute the code in the shell window. This won't work because of all the stuff that the interpreter prints. Thus in the interactive prompt you see: print( "hello world") But in your program file you only type: print( "hello world" ) The >>> bit is part of the interpreter not the program. From your comments thats the best that I can guess. If thats not the problem then we will neeed more detail about what exactly you are doing and the specific error messages you get printed. You might find Danny Yoo's introduction to IDLE useful for a visual reference. http://hkn.eecs.berkeley.edu/~dyoo/python/idle_intro/index.html Its for Python 2.4 but the principles of using it for later versions are exactly the same. -- Alan Gauld Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Hello, I am just learning Python 3.0 and I am working on this problem. I need to know what the output would be. Can anybody help Thanks, Brad class Bozo: def __init__(self, value): print("Creating a Boso from:" , value) self.value = 2 * value def clown(self, x): print(x * self.value) return x + self.value def main(): print("Clowning around now.") c1 = Bozo(3) c2 = Bozo(4) print(c1.clown(3)) print(c2. clown(c1.clown(2)) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Reading video streams from Internet
Hello Python gurus! I am trying to 1) Read and decode video streams from internet. 2) Store them in a buffer. 3) Eventually convert them into data that can be used in Cycling '74's Jitter. If anyone has any idea how to start with this, that would be great! I have limited experience with Python, but I have a bit of exposure to the urllib and urllib2. Any help is much appreciated! Thank you! -Ryan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Python trouble
Ok let me try to be more clear. I am trying to write code in the IDLE Python GUI of python 2.7. When I open the new python shell, there is a written header as well as the three >s on the left side. I now those are used as indents and I do not type them in. However, whenever I write any type of code and either attempt to run or click alt + x to check module, it says "there is an error in your program: invalid syntax." Then when it goes back to the page to highlight the syntax error the second > is highlighted in color as it is the problem. Before I deleted the header from this program, it would highlight the 7 after the 2. In the header. Alex Butler ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
> Hello, I am just learning Python 3.0 and I am working on this > problem. I need to know what the output would be. What happened when you ran it on your computer? You _did_ try that, right? Alan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] (no subject)
Hello, I am just learning Python 3.0 and I am working on this problem. I need to know what the output would be. Can anybody help Thanks, Brad class Bozo: def __init__(self, value): print("Creating a Boso from:" , value) self.value = 2 * value def clown(self, x): print(x * self.value) return x + self.value def main(): print("Clowning around now.") c1 = Bozo(3) c2 = Bozo(4) print(c1.clown(3)) print(c2. clown(c1.clown(2)) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] return values function thanks
D, F) for each test score, and the overall average test schore. Write the following functions in the program: * Calc_average: This function should take five test scores as parameters, and return the average score. *determine_grade; this function should take a single test score as a parameter, and return a letter grade for the test. The letter grade should be on the following grade scale: 90-100: A, 80-89: B, 70-79: C, 60-69: D, <60: F.""" def main(): #Get users first test result test1 = int(raw_input('Enter the score for test 1: ')) #Get users second test result test2 = int(raw_input('Enter the score for test 2: ')) #Get users third test result test3 = int(raw_input('Enter the score for test 3: ')) #Get users forth test result test4 = int(raw_input('Enter the score for test 4: ')) #Get users fifth test result test5 = int(raw_input('Enter the score for test 5: ')) #Get the sum of the test results cal_average = sum(test1, test2, test3, test4, test5)/5 #Display the total of tests print 'Together your tests average is: ', cal_average print 'Your grade is: ', grade # The sum function to total all tests def sum(test1, test2, test3, test4, test5): result = test1 + test2 + test3 + test4 + test5 return result def determine_grade(score): #Determine the grade for each score if score <101 and score >89: score = A elif score <90 and score >79: score = B elif score <80 and score >69: score = C elif score <70 and score >59: score = D else: score = F return score # Call the main function main() -- next part -- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/tutor/attachments/20110422/fede14a5/attach ment-0001.html> -- Message: 5 Date: Fri, 22 Apr 2011 08:32:04 +0100 From: "Alan Gauld" To: tutor@python.org Subject: Re: [Tutor] return values function Message-ID: Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original "Lea Parker" wrote > Write the following functions in the > program: > > * Calc_average: This function should take five test scores as > parameters, and return the average score. Note that you are supposed to write a function to do this not just do it inline. > *determine_grade; this function should take a single test score as a > parameter, and return a letter grade for the test. > The letter grade should be on the following grade scale: > 90-100: A, 80-89: B, 70-79: C, 60-69: D, <60: F.""" > > def main(): >#Get users first test result >test1 = int(raw_input('Enter the score for test 1: ')) >test2 = int(raw_input('Enter the score for test 2: ')) >test3 = int(raw_input('Enter the score for test 3: ')) >test4 = int(raw_input('Enter the score for test 4: ')) >test5 = int(raw_input('Enter the score for test 5: ')) Every time you see repeating code like that you should ask, can I use a loop? If you store the results in a list, it then becomes a simple job to read 5 results: for n in range(5): results.append( int(raw_input('Enter the score for test %d:" % n')) ) >#Get the sum of the test results >cal_average = sum(test1, test2, test3, test4, test5)/5 This is the average not the sum so your comment is wrong. It's also where you should be using the function you were asked to define. The function body would look like the line above. >print 'Together your tests average is: ', cal_average >print 'Your grade is: ', grade And here you need to call your other function to work out the grade. But again you need to call it for each score. You can repeat it 5 times as you did for raw_input or you could use the loop; method I showed you above. ># The sum function to total all tests def sum(test1, test2, test3, > test4, test5): >result = test1 + test2 + test3 + test4 + test5 >return result You didn't need this because Python already has a sum() function that will do this for you. > def determine_grade(score): >#Determine the grade for each score >if score <101 and score >89: >score = A >elif score <90 and score >79: >score = B >elif score <80 and score >69: >score = C >elif score <70 and score >59: >score = D >else: >score = F >return score The most serious problem, and it should have thrown an error, is that t
Re: [Tutor] (no subject)
On 22-Apr-11 15:37, Brad Desautels wrote: Hello, I am just learning Python 3.0 and I am working on this problem. I need to know what the output would be.Can anybody help What is your question? If you want to see what its output would be... run it and see the output. Is there more to your question, like what *should* the output be? (in which case, tell us what your output *is* and we can help you see why it's not what you expected). ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Ya, I did try to run it and I am getting a syntax error before it runs. -Original Message- From: tutor-bounces+outsideme99=live@python.org [mailto:tutor-bounces+outsideme99=live@python.org] On Behalf Of R. Alan Monroe Sent: Friday, April 22, 2011 6:38 PM To: tutor@python.org Subject: Re: [Tutor] (no subject) > Hello, I am just learning Python 3.0 and I am working on this > problem. I need to know what the output would be. What happened when you ran it on your computer? You _did_ try that, right? Alan ___ 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] (no subject)
On 22-Apr-11 15:48, Brad Desautels wrote: Ya, I did try to run it and I am getting a syntax error before it runs. and the message said? Where did it point to as the syntax error? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python trouble
On 22-Apr-11 11:52, Alex Butler wrote: Ok let me try to be more clear. I am trying to write code in the IDLE Python GUI of python 2.7. When I open the new python shell, there is a written header as well as the three >s on the left side. I now those are used as indents and I do not type them in. However, whenever I write any type of code and either attempt to run or click alt + x to check module, it says “there is an error in your program: invalid syntax.” Then when it goes back to the page to highlight the syntax error the second > is highlighted in color as it is the problem. Before I deleted the header from this program, it would highlight the 7 after the 2. In the header. Okay, that's pretty much what you said last time. What is the actual code you're trying to run? If it's really complaining about >>> being a syntax error, it sounds like you're confused about where you are in the tool or extra text is getting pasted. If you open a new source window (file->new) (not a "shell" window), and type some python code, that window won't have a header line or >>> prompts at all, just your code. So... start IDLE select File->New; new untitled window pops up type a python program, maybe this: print "hello" hit alt-X (although personally, I'd hit F5 instead). It should prompt you for a file to save your new program into, then run it back in the other window (the shell) that has the >>>s in it. How, exactly, does what I just described differ from what happened to you? -- Steve Willoughby / st...@alchemy.com "A ship in harbor is safe, but that is not what ships are built for." PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Hi Steve, I am getting my error on main() I think it is possibly be an indentation error -Original Message- From: tutor-bounces+outsideme99=live@python.org [mailto:tutor-bounces+outsideme99=live@python.org] On Behalf Of Steve Willoughby Sent: Friday, April 22, 2011 6:52 PM To: tutor@python.org Subject: Re: [Tutor] (no subject) On 22-Apr-11 15:48, Brad Desautels wrote: > Ya, I did try to run it and I am getting a syntax error before it runs. and the message said? Where did it point to as the syntax error? ___ 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] (no subject)
On 22-Apr-11 16:03, Brad Desautels wrote: Hi Steve, I am getting my error on main() I think it is possibly be an indentation error It should be easy to check. Make sure "def main():" is all the way to the left, and all the lines under it are the same level as each other but usually indentation errors say that they are indentation errors. Look carefully at your parentheses. Does every ( have a matching )? -- Steve Willoughby / st...@alchemy.com "A ship in harbor is safe, but that is not what ships are built for." PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
With Bash, when one needs to halt the current root filesystem, to pivot to a new filesystem, one can copy some of the command files and their dependencies to a temporary file system and execute from that code base. Is there a way to accomplish the same within a Python script? Or must I chain Python and Bash together for this? --Fred ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
On 22-Apr-11 16:54, Frederick Grose wrote: With Bash, when one needs to halt the current root filesystem, to pivot to a new filesystem, one can copy some of the command files and their dependencies to a temporary file system and execute from that code base. I'm not sure those words mean what you think they mean, or I'm missing what you're trying to do here. halting the root filesystem? pivot? code base? You're not trying to talk about jail/chroot, perhaps? -- Steve Willoughby / st...@alchemy.com "A ship in harbor is safe, but that is not what ships are built for." PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python trouble
Alex Butler wrote: Ok let me try to be more clear. I am trying to write code in the IDLE Python GUI of python 2.7. When I open the new python shell, there is a written header as well as the three >s on the left side. I now those are used as indents and I do not type them in. However, whenever I write any type of code and either attempt to run or click alt + x to check module, it says "there is an error in your program: invalid syntax." Then when it goes back to the page to highlight the syntax error the second > is highlighted in color as it is the problem. Before I deleted the header from this program, it would highlight the 7 after the 2. In the header. The >>> is called the prompt. It is not part of the code, it is just there to prompt you that the interpreter is waiting for you. If you start a command that goes over two or more lines, the prompt will change to three dots ... to remind you that you haven't finished writing the command yet. Please COPY and PASTE an example of the system error. Do not retype it, especially not from memory, but actually copy and paste the complete error, including the line it claims is invalid, and paste it into a reply. Like this: >>> x = 1 >>> y = 2 >>> if x=y: File "", line 1 if x=y: ^ SyntaxError: invalid syntax Thank you. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Brad Desautels wrote: Ya, I did try to run it and I am getting a syntax error before it runs. Then fix the syntax error. Do you need help understanding the error? If so, please COPY and PASTE the entire error here, do not try to re-type it, specially not from memory. One hint that a lot of beginners miss is that the syntax error includes a pointer to the first mistake: it uses a ^ on an otherwise blank line to point to the first part of the code that is wrong: >>> if x=y: File "", line 1 if x=y: ^ SyntaxError: invalid syntax This tells me that I can't say "if x=y" (assignment), but I need equality instead: "if x==y". Another thing that sometimes catches even experienced programmers: if you forget to close brackets (round, square or curly), you will often get the SyntaxError on the *following* line: >>> mylist = [1, 2, 3 ... for m in mylist: File "", line 2 for m in mylist: ^ SyntaxError: invalid syntax -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
On Fri, Apr 22, 2011 at 7:59 PM, Steve Willoughby wrote: > On 22-Apr-11 16:54, Frederick Grose wrote: > >> With Bash, when one needs to halt the current root filesystem, to pivot >> to a new filesystem, one can copy some of the command files and their >> dependencies to a temporary file system and execute from that code base. >> > > I'm not sure those words mean what you think they mean, or I'm missing what > you're trying to do here. halting the root filesystem? pivot? code base? > > You're not trying to talk about jail/chroot, perhaps? > > -- > Steve Willoughby / st...@alchemy.com > The particulars are that I've rebuilt a Fedora LiveOS filesystem image from a currently running instance (incorporating the filesystem changes in the device-mapper overlay into a new base filesystem image file). I'd like to halt the active rootfs, switch to its mirror, copy over the halted filesystem image file with the refreshed version, and then switch back. --Fred ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
Frederick Grose wrote: With Bash, when one needs to halt the current root filesystem, to pivot to a new filesystem, one can copy some of the command files and their dependencies to a temporary file system and execute from that code base. Is there a way to accomplish the same within a Python script? This is way off-topic for a Python tutor list. This is about learning the Python programming language, not the intricate corners of (I assume) Linux system administration. I would imagine that it would be very, very difficult in Python, because you would need somehow to end the *current* Python process and start up a *new* Python process running from executables on the new file system, without manual intervention. I strongly suggest you take this question to the main Python list, pyt...@python.org, which is also available as a news group comp.lang.python, and show the bash code you are trying to duplicate. There's no guarantee you'll get an answer there either, but it's more likely than here. Good luck! -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Reading video streams from Internet
Ryan J wrote: Hello Python gurus! I am trying to 1) Read and decode video streams from internet. 2) Store them in a buffer. 3) Eventually convert them into data that can be used in Cycling '74's Jitter. If anyone has any idea how to start with this, that would be great! I have limited experience with Python, but I have a bit of exposure to the urllib and urllib2. Do you have a URL for the video stream? Is it a http or https URL that points directly to a .mov or other video file? Then you just use urllib and/or urllib2 to connect to that URL and read data. You can write that data into either memory or directly to a file on disk. I have no idea what Cycling '74's Jitter is, or what formats it expects. I suggest you use existing tools like mencoder to convert the video into whatever format is appropriate. Re-writing a video converter tool in Python will be a huge job, and it likely too slow to be usable. If the URL is a secret, proprietary protocol like MMS or RTSP, you will need to find some library to handle the protocol, or possibly reverse engineer it yourself. Good luck with that. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
On 22-Apr-11 17:14, Frederick Grose wrote: The particulars are that I've rebuilt a Fedora LiveOS filesystem image from a currently running instance (incorporating the filesystem changes in the device-mapper overlay into a new base filesystem image file). Right, so essentially you're talking about chrooting into the LiveOS image temporarily. It's not really "halting" as such, just where the OS's idea of "root" is at the moment. That involves mounting your LiveOS filesystem as well. The short answer is that if you can do it in the shell, you can do it in Python, but there's got to be more to the story than just this. What are you trying to actually do that you need Python for this? I assume you're trying to automate the process of what you're doing? Almost probably this is possible with Python, if I understand what you're doing. If you just want to know how to write a Python script around the steps you want to accomplish, as a simple beginning Python experience, we may still be of service to you. We could, for example point you to read up on the os.chroot() function in the Python standard library. If your question has more to do with the particulars of managing chroot()ed mountpoints or preparing LiveOS images, you'd need to look to a forum devoted to that. -- Steve Willoughby / st...@alchemy.com "A ship in harbor is safe, but that is not what ships are built for." PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
On Fri, Apr 22, 2011 at 8:55 PM, Steve Willoughby wrote: > On 22-Apr-11 17:14, Frederick Grose wrote: > >> The particulars are that I've rebuilt a Fedora LiveOS filesystem image >> from a currently running instance (incorporating the filesystem changes >> in the device-mapper overlay into a new base filesystem image file). >> > > Right, so essentially you're talking about chrooting into the LiveOS image > temporarily. It's not really "halting" as such, just where the OS's idea of > "root" is at the moment. That involves mounting your LiveOS filesystem as > well. > > The short answer is that if you can do it in the shell, you can do it in > Python, but there's got to be more to the story than just this. What are > you trying to actually do that you need Python for this? I assume you're > trying to automate the process of what you're doing? > > Almost probably this is possible with Python, if I understand what you're > doing. If you just want to know how to write a Python script around the > steps you want to accomplish, as a simple beginning Python experience, we > may still be of service to you. > > We could, for example point you to read up on the os.chroot() function in > the Python standard library. > > If your question has more to do with the particulars of managing chroot()ed > mountpoints or preparing LiveOS images, you'd need to look to a forum > devoted to that. > > > -- > Steve Willoughby / st...@alchemy.com > Thank you Steve and Steven for your assistance! I misread this sentence in the list description, "While the list is called tutor, anyone, whether novice or expert, can answer questions." .. to include 'ask' as well as answer questions that may be instructive. I've posted in Python-list, as suggested. Steven's synopsis, "... you would need somehow to end the *current* Python process and start up a *new* Python process running from executables on the new file system, without manual intervention." is the situation I'm attempting. I have written the LiveOS rebuilding code in Python, and am working to complete the operation in Python, if possible, but don't know enough about how the Python shutdown and startup might be scripted within Python. --Fred ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Run a few Python commands from a temporary filesystem when the rootfs is halted
Frederick Grose wrote: I misread this sentence in the list description, "While the list is called tutor, anyone, whether novice or expert, can answer questions." .. to include 'ask' as well as answer questions that may be instructive. Well, you can *ask*, but the number of people on this list is much smaller than the main python list, and we tend to be focused more on beginner questions and learning the language rather than the more advanced stuff. So it's more about maximising your chances of getting a good answer. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python timers
Hello, my name is Brad and I am a student at Suny Plattsburgh. and Python programming is a course I am taking this semester. I find it a bit of a challenge doing all the chapter programming exercises that are assigned. We are currently in chapter 8 but some of the basics have not completely sunk in yet. This is extra hard for me because my learning capacity isn't what it used to be, 4 years ago I was in a motorcycle accident in which I sustained a traumatic brain injury and lost my left leg .The TBI affects my ability to remember short term things and my cognitive abilities are a bit off to say the least. If what I write seems a bit off Please bear with me.. I need help completing my exercises, and do work very hard to absorb this material. Thank you, Brad From: tutor-bounces+outsideme99=live@python.org [mailto:tutor-bounces+outsideme99=live@python.org] On Behalf Of michael scott Sent: Thursday, April 21, 2011 12:38 AM To: tutor@python.org Subject: [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