Re: newbee
On Aug 13, 2014 9:34 PM, Terry Reedy tjre...@udel.edu wrote: Have you verified that Idle *does* (not just *should*) run on RPi? (That would mean having tcl/tk running, with whatever *it* requires on linux.) I am working on Idle and the idea of people (especially hobbyists, students, and other amateurs) running it on microsystems would really please me. I don't have a RPi, but I know it is just a glorified ARM computer with terrible specs. But it is enough to run LXDE or other lightweight graphical environments, which means tcl/tk is VERY likely to work. You could also look up packages for Raspbian or other RPi-friendly distros and see python-tk there, or various Python tutorials for the device: http://davidbriddock.blogspot.com/2013/04/learn-python-installing-tkinter.html -- Chris “Kwpolska” Warrick http://chriswarrick.com/ Sent from my SGS3. -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
in 726715 20140813 103037 Chris Angelico ros...@gmail.com wrote: On Wed, Aug 13, 2014 at 9:57 AM, Frank Scafidi fpscaf...@gmail.com wrote: I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? These sound like RPi questions, rather than Python questions. You may find knowledgeable people here on this list, but if not, I would advise hunting down an RPi mailing list or newsgroup and asking there. Most of us here use full computers, where questions like how do I save a file? are trivially easy... you may find, actually, that starting on a PC and then pushing the file to the RPi is the easiest way to work. comp.sys.rapberry-pi -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
On Wed, 13 Aug 2014 15:31:37 -0400, Terry Reedy wrote: On 8/13/2014 7:55 AM, alister wrote: I am not in the same league as many of the posters here when it comes to Python but fortunately i do have two Raspberry Pi's :-) Great! We really someone with hands-on experience. I Hope the missing word there is welcome :-) if you are running the Pi connected to a TV/Monitor with the Gui enabled then you should have access to Idle Have you verified that Idle *does* (not just *should*) run on RPi? (That would mean having tcl/tk running, with whatever *it* requires on linux.) I am working on Idle and the idea of people (especially hobbyists, students, and other amateurs) running it on microsystems would really please me. Yes it does, but i tend to run mine headless (X forwarding is still an option though) but I prefer Geany, which i do run on the pi (with x forwarding) with no issues, just remember the Pi is not a particularly fast device. If you have any more questions post them back I hope I can help (Maybe I can become useful to this group as the R-Pi expert, Answering questions, sometimes after experiment and research, is a great way to learn. I would say it is the ONLY way to really learn, you never really understand something until you have broken it and then fixed it or tried to teach it to someone. -- Dungeons and Dragons is just a lot of Saxon Violence. -- https://mail.python.org/mailman/listinfo/python-list
newbee
I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? Thanks Frank -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
On Tue, Aug 12, 2014 at 7:57 PM, Frank Scafidi fpscaf...@gmail.com wrote: I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? I've not worked with Rasberry Pi, but it has some kind of linux on it. So find a text editor (maybe vim is on it). Write your code with text editor and save. To run it type: python my_program.py See python.org website and read the tutorial Thanks Frank -- https://mail.python.org/mailman/listinfo/python-list -- Joel Goldstick http://joelgoldstick.com -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
On Wed, Aug 13, 2014 at 9:57 AM, Frank Scafidi fpscaf...@gmail.com wrote: I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? These sound like RPi questions, rather than Python questions. You may find knowledgeable people here on this list, but if not, I would advise hunting down an RPi mailing list or newsgroup and asking there. Most of us here use full computers, where questions like how do I save a file? are trivially easy... you may find, actually, that starting on a PC and then pushing the file to the RPi is the easiest way to work. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
Frank Scafidi wrote: I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? You can use any text editor to write a python script. A simple editor which might be present ont the Pi is called nano. It shows the hotkeys to store the text and quit the editor, and thus should be self-explanatory: $ nano helloworld.py Once you have written your simple script you can look at it with the cat command: $ cat helloworld.py #!/usr/bin/env python print Hello world Invoke it with: $ python helloworld.py Hello world You can also make your script executable which means that the first line controls which program is used to run it: $ chmod +x helloworld.py $ ./helloworld.py Hello world $ If the script is in a directory listed in the PATH environment variable you can omit the path (the ./ in the above example): $ mv helloworld.py ~/bin $ helloworld.py Hello world PS: I ran the above demo on a Linux system, but not on the Raspberry Pi, so if something doesn't work as shown above it's probably due to the difference between the two systems. -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
Peter Otten __pete...@web.de wrote: Frank Scafidi wrote: I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? You can use any text editor to write a python script. A simple editor which might be present ont the Pi is called nano. It shows the hotkeys to store the text and quit the editor, and thus should be self-explanatory: $ nano helloworld.py Once you have written your simple script you can look at it with the cat command: $ cat helloworld.py #!/usr/bin/env python print Hello world Invoke it with: $ python helloworld.py Hello world You can also make your script executable which means that the first line controls which program is used to run it: $ chmod +x helloworld.py $ ./helloworld.py Hello world $ If the script is in a directory listed in the PATH environment variable you can omit the path (the ./ in the above example): $ mv helloworld.py ~/bin $ helloworld.py Hello world PS: I ran the above demo on a Linux system, but not on the Raspberry Pi, so if something doesn't work as shown above it's probably due to the difference between the two systems. All of the above should work just fine on a Pi. The only thing I thing you could have added is that you also have the option of using Idle to edit and run Python programs. If you are running Raspian on your Pi then you will find an icon to run Idle sitting on the initial desktop. There's an introduction to using Idle on the Raspberry Pi at http://www.raspberrypi.org/documentation/usage/python/ -- Duncan Booth -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
On Tue, 12 Aug 2014 19:57:14 -0400, Frank Scafidi wrote: I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? Thanks Frank div dir=ltrdiv class=gmail_default style=font-family:georgia,serif;font-size:small;color:#3366ffI just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60#39;s amp; 70#39;s and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I#39;ve written, reload it in Python, list the program once it#39;s loaded? How do I edit a program? Are these command line functions? /div div class=gmail_default style=font-family:georgia,serif;font-size:small;color:#3366ffbr/ divdiv class=gmail_default style=font-family:georgia,serif;font-size:small;color:#3366ffThanks/ divdiv class=gmail_default style=font-family:georgia,serif;font-size:small;color:#3366ff Frank/divdiv class=gmail_default style=font-family:georgia,serif;font-size:small;color:#3366ffbr/ div/div I am not in the same league as many of the posters here when it comes to Python but fortunately i do have two Raspberry Pi's :-) if you are running the Pi connected to a TV/Monitor with the Gui enabled then you should have access to Idle as well as a number of text editors (Geany works well if installed) if you are using it from the commands line then as previously stated you need to use a text editor to write the code (Nano is part of the basic Raspian Distro and easier to use than VI/Vim) once you have created your code file type python file Name at the command prompt remember if you are connecting to the Pi remotely Via SSH it is useful to have multiple connections open, one for the text editor 1 to enable you to run the code or execute other Linux commands. If you have any more questions post them back I hope I can help (Maybe I can become useful to this group as the R-Pi expert, hopefully more productively than some of the groups other 'Experts') -- Expect the worst, it's the least you can do. -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
Am 13.08.2014 13:55, schrieb alister: [snip] A related question: How could one write a Python program and have it run on a mobile phone in general (independent of a PC)? M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
On Wed, 13 Aug 2014 15:13:34 +0200, Mok-Kong Shen wrote: Am 13.08.2014 13:55, schrieb alister: [snip] A related question: How could one write a Python program and have it run on a mobile phone in general (independent of a PC)? M. K. Shen you would need a python interpreter for that device, IIRC there is one available for android, I do not know about IOS -- It's not hard to admit errors that are [only] cosmetically wrong. -- J.K. Galbraith -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
On Aug 13, 2014, at 9:57 AM, alister alister.nospam.w...@ntlworld.com wrote: On Wed, 13 Aug 2014 15:13:34 +0200, Mok-Kong Shen wrote: Am 13.08.2014 13:55, schrieb alister: [snip] A related question: How could one write a Python program and have it run on a mobile phone in general (independent of a PC)? M. K. Shen you would need a python interpreter for that device, IIRC there is one available for android, I do not know about IOS There are several for iOS, but because of Apple’s sandboxing they don’t have as much reach as you might want. -Bill -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
On 8/13/2014 7:55 AM, alister wrote: I am not in the same league as many of the posters here when it comes to Python but fortunately i do have two Raspberry Pi's :-) Great! We really someone with hands-on experience. if you are running the Pi connected to a TV/Monitor with the Gui enabled then you should have access to Idle Have you verified that Idle *does* (not just *should*) run on RPi? (That would mean having tcl/tk running, with whatever *it* requires on linux.) I am working on Idle and the idea of people (especially hobbyists, students, and other amateurs) running it on microsystems would really please me. If you have any more questions post them back I hope I can help (Maybe I can become useful to this group as the R-Pi expert, Answering questions, sometimes after experiment and research, is a great way to learn. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
On 08/12/2014 04:57 PM, Frank Scafidi wrote: I just acquired a Raspberry Pi and want to program in Python. I was a PL/1 programmer back in the 60's 70's and Python is similar. I am struggling with some very fundamental things that I am not finding in the documentation. Can someone help me with the basics like how do I save a program I've written, reload it in Python, list the program once it's loaded? How do I edit a program? Are these command line functions? Thanks Frank You've already received a lot of suggestions, but I'll add one more... If you don't mind shelling out for some dead-tree documentation, there is a book in the Sam's Teach Yourself in 24 Hours series -- Python Programming for Raspberry Pi. It is a pretty good basic tutorial for Python in general, and specifically written for the RPi. You might check it out. (Current Amazon price -- $25.81) -=- Larry -=- -- https://mail.python.org/mailman/listinfo/python-list
Newbee question about running a script
Hello, I've just installed Python 2.7 on Windows 7 I've been able to write and run a script Hello world I wonder how I could specify a parameter on the command line from within the interpreter. Specifying a parameter on the DOS command line is no problem. Any hint, please ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee question about running a script
On Sunday, January 6, 2013 8:03:43 AM UTC-8, marc.assin wrote: I wonder how I could specify a parameter on the command line from within the interpreter. Guido wrote some advice a while back - http://www.artima.com/weblogs/viewpost.jsp?thread=4829 Import your module and call its main. The other way is to execute in another process: from subprocess import check_call import sys check_call([sys.executable, 'myscript.py', 'arg1', 'arg2']) -- http://mail.python.org/mailman/listinfo/python-list
newbee: Simple Backend Python Script Question
I need to create python script that is threaded. So the main program will run in infinite loop and just retrieving messages and putting them in a queue. (Main thread) I need child threads from a pool to process the queue. When there is no stuff in the queue, they go to the pool and become available but they don't terminate. This has to be done continuously. Main program need to keep putting stuff in the queue, when there are no messages, then it sleeps for short time and check back to see any messages. To do this, I guess you don't write joinAll(), so that the main threads just don't wait for the child but goes to work. am I right? Also, child threads (a function that is threaded) will make connecitons to the database. I am planning to use threadpool, so that threads reuse the connections. So do you close the database connection at the end of the function? If not then the connection will be opened forever? Joe -- http://mail.python.org/mailman/listinfo/python-list
Re: newbee: Simple Backend Python Script Question
joe shoemaker wrote: I need to create python script that is threaded. So the main program will run in infinite loop and just retrieving messages and putting them in a queue. (Main thread) I need child threads from a pool to process the queue. When there is no stuff in the queue, they go to the pool and become available but they don't terminate. This has to be done continuously. Main program need to keep putting stuff in the queue, when there are no messages, then it sleeps for short time and check back to see any messages. To do this, I guess you don't write joinAll(), so that the main threads just don't wait for the child but goes to work. am I right? Pretty much. The way I usually do this is to start a number of threads reading work items of some sort from a Queue.Queue. The thread will block automatically if there's nothing on the queue, resuming when something appears (and if I want orderly termination I use None as a dummy work unit, and the threads terminate when they receive a None, but any sentinel value would do). Also, child threads (a function that is threaded) will make connecitons to the database. I am planning to use threadpool, so that threads reuse the connections. So do you close the database connection at the end of the function? If not then the connection will be opened forever? You don't want a thread pool, you want a connection pool, but there's little advantage to having one that is only shared between your threads. You really need a system-wide connection pool. Alternatively, you might find that your database module is thread-safe to the extent that different threads can use cursors created on the same connection without interference. If you want each thread to be able to process transactions that are invisible to the other threads before they are committed you should ensure that you have a sufficient isolation level, which might imply the need for a connection-per-thread architecture, in which case you might expect some benefit from connection pooling. regards Steve regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden Sorry, the dog ate my .sigline -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
Oh well since a few solutions have already been posted I thought I might add another, just so you at the very least you have to do some work making up your mind which one to choose. Using an incremental approach just to be different ... from decimal import Decimal normal = Decimal('0.04') over = Decimal('1.40) def calcStopPay (stops) : pay = Decimal('0.00') while stops : incr = normal if stops 23 else over pay += incr stops -= 1 return pay #testing: for x in range(50) : print Stop pay for %s stops: $%s % (x, calcStopPay(x)) -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 21, 5:41 pm, Asun Friere [EMAIL PROTECTED] wrote: over = Decimal('1.40) oops, that should of course be: over = Decimal('1.40') -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 21, 5:51 pm, Asun Friere [EMAIL PROTECTED] wrote: On Aug 21, 5:41 pm, Asun Friere [EMAIL PROTECTED] wrote: over = Decimal('1.40) oops, that should of course be: over = Decimal('1.40') oh boy ... and it should also be normal = Decimal('0.40') I really need to test before posting ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 20, 11:47 pm, [EMAIL PROTECTED] wrote: ... Thanks for the help. By the way I am trying to learn the python after work and on weekends. If it was a dumb question, to this group, I will not bother you all again. It's not so much that it was a dumb question, but that it was asked in a dumb way :-) You'll get the most help in this group if you can show some evidence that you've had a go (the size of this thread ironically trounces that argument of course ;-) .) It's better to learn if people give you a critique of your own attempt at the code, rather than looking at other peoples efforts. There's a guide on how to ask good questions here: http://www.catb.org/~esr/faqs/smart-questions.html For what it's worth, here's a gratuitous version using generators, and one you should come back to once you've mastered the basics of Python: def counter(std_rate, over_rate, limit): stops = 0 while True: stops += 1 wage = stops * std_rate + max(0, stops - limit) * (over_rate - std_rate) yield stops, wage truck = counter(0.4, 1.4, 22) for i in range(30): print Stopped %s times, with accumulated wage of $%s % truck.next() -- Ant... http://antroy.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
[EMAIL PROTECTED] wrote: [...] Thanks for the help. By the way I am trying to learn the python after work and on weekends. If it was a dumb question, to this group, I will not bother you all again. Without help it will take me longer to learn. Thanks Don't worry about it. There is also a list specifically for learners, which you can find out about at http://mail.python.org/mailman/listinfo/tutor Welcome to the Python community! regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden --- Asciimercial -- Get on the web: Blog, lens and tag the Internet Many services currently offer free registration --- Thank You for Reading - -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 21, 4:38 am, Ant [EMAIL PROTECTED] wrote: On Aug 20, 11:47 pm, [EMAIL PROTECTED] wrote: ... Thanks for the help. By the way I am trying to learn the python after work and on weekends. If it was a dumb question, to this group, I will not bother you all again. It's not so much that it was a dumb question, but that it was asked in a dumb way :-) You'll get the most help in this group if you can show some evidence that you've had a go (the size of this thread ironically trounces that argument of course ;-) .) It's better to learn if people give you a critique of your own attempt at the code, rather than looking at other peoples efforts. There's a guide on how to ask good questions here:http://www.catb.org/~esr/faqs/smart-questions.html For what it's worth, here's a gratuitous version using generators, and one you should come back to once you've mastered the basics of Python: def counter(std_rate, over_rate, limit): stops = 0 while True: stops += 1 wage = stops * std_rate + max(0, stops - limit) * (over_rate - std_rate) yield stops, wage truck = counter(0.4, 1.4, 22) for i in range(30): print Stopped %s times, with accumulated wage of $%s % truck.next() -- Ant... http://antroy.blogspot.com/ I tryed your code and got an error message #I use Wing IDE: Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] Type help, copyright, credits or license for more information. Evaluating lines 1-16 from truckStops.py string:7: Warning: 'yield' will become a reserved keyword in the future Could not execute because an error occurred: invalid syntax: string, line 7, pos 19: yield stops, wage -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 21, 11:52 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I tryed your code and got an error message #I use Wing IDE: Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] Type help, copyright, credits or license for more information. Evaluating lines 1-16 from truckStops.py string:7: Warning: 'yield' will become a reserved keyword in the future Could not execute because an error occurred: invalid syntax: string, line 7, pos 19: yield stops, wage Python 2.2.3 is three versions behind. Generators only work in 2.2 by saying: from __future__ import generators And by default in anything from 2.3 on. Fred -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 21, 2:57 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote: [...] pay = min(num, 22) * 0.4 + max(num-22, 0) * 1.4 pay = num*0.4 + (num22)*(num-22) ;-) -=Dave -- http://mail.python.org/mailman/listinfo/python-list
Newbee Question
This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 20, 9:23 am, HD1956 [EMAIL PROTECTED] wrote: This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. def calc(num): if num 23: return 0.4 * num else: overtime = num - 22 x = 0.4 * 22 x += overtime * 1.4 return x # Use your own brain next time Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
#!/usr/bin/env python normalPay = 0.4 overPay = 1.4 normalLimit = 22 def calcPay(numStops): pay = 0 if numStops normalLimit: pay = overPay * (numStops - normalLimit) numStops = normalLimit return pay + (numStops * normalPay) if __name__ == __main__: print Pay for 1 stops: %.2f. % calcPay(1) print Pay for 10 stops: %.2f. % calcPay(10) print Pay for 17 stops: %.2f. % calcPay(17) print Pay for 25 stops: %.2f. % calcPay(25) print Pay for 30 stops: %.2f. % calcPay(30) print Pay for 31 stops: %.2f. % calcPay(31) -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On 8/20/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Aug 20, 9:23 am, HD1956 [EMAIL PROTECTED] wrote: This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. def calc(num): if num 23: return 0.4 * num else: overtime = num - 22 x = 0.4 * 22 x += overtime * 1.4 return x # Use your own brain next time Mike -- http://mail.python.org/mailman/listinfo/python-list Mike, I wonder if we were both just duped into helping someone with their homework... Shawn -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
HD1956 schrieb: This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. Sounds a bit like homework. Which usually isn't simply delivered here. Can you show us some code you worked on, then we might suggest enhancements. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 20, 9:58 am, Shawn Milochik [EMAIL PROTECTED] wrote: On 8/20/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Aug 20, 9:23 am, HD1956 [EMAIL PROTECTED] wrote: This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. def calc(num): if num 23: return 0.4 * num else: overtime = num - 22 x = 0.4 * 22 x += overtime * 1.4 return x # Use your own brain next time Mike -- http://mail.python.org/mailman/listinfo/python-list Mike, I wonder if we were both just duped into helping someone with their homework... Shawn I like to write code, so it's not a big deal when it's something so simple. Still, that is beyond dumb! Nice code, by the way. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
I like to write code, so it's not a big deal when it's something so simple. Still, that is beyond dumb! Nice code, by the way. Mike Yeah, it was fun to write anyway. Thanks for the compliment on the code. I still consider myself a Python newbie, so it's good to know I'm not trying to write it like Perl or VBScript anymore. ^_^ Shawn -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
Diez B. Roggisch wrote: Sounds a bit like homework. Which usually isn't simply delivered here. Wrong! Usually that happens pretty quickly here (as proven again in this case). Not that it should, but only the seniors seem to detect lazy learners. /W -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 20, 9:23 am, HD1956 [EMAIL PROTECTED] wrote: This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. You'll get top marks for turning in the shortest program! norm = 0.4 ot = 1.4-norm otStart = 22 calcPay = lambda stops : norm*stops+ot*max(stops-otStart,0) -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On 2007-08-20, HD1956 [EMAIL PROTECTED] wrote: This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. I wish *I* could make a deal like that. I stop working all the time! -- Neil Cerutti Customers who consider our waitresses uncivil ought to see the manager --sign at New York restaurant -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
On Aug 20, 11:06 am, [EMAIL PROTECTED] wrote: On Aug 20, 9:58 am, Shawn Milochik [EMAIL PROTECTED] wrote: On 8/20/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Aug 20, 9:23 am, HD1956 [EMAIL PROTECTED] wrote: This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. def calc(num): if num 23: return 0.4 * num else: overtime = num - 22 x = 0.4 * 22 x += overtime * 1.4 return x # Use your own brain next time Mike -- http://mail.python.org/mailman/listinfo/python-list Mike, I wonder if we were both just duped into helping someone with their homework... Shawn I like to write code, so it's not a big deal when it's something so simple. Still, that is beyond dumb! Nice code, by the way. Mike- Hide quoted text - - Show quoted text - Thanks for the help. By the way I am trying to learn the python after work and on weekends. If it was a dumb question, to this group, I will not bother you all again. Without help it will take me longer to learn. Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee Question
[EMAIL PROTECTED] wrote: On Aug 20, 11:06 am, [EMAIL PROTECTED] wrote: On Aug 20, 9:58 am, Shawn Milochik [EMAIL PROTECTED] wrote: On 8/20/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Aug 20, 9:23 am, HD1956 [EMAIL PROTECTED] wrote: This is probably a simple code. I am a truck driver who gets paid by stops and cases. I am trying to figure out how to code my stop pay. I get 40 cents per stop up to 22 stops, and $1.40 per stops after that. def calc(num): if num 23: return 0.4 * num else: overtime = num - 22 x = 0.4 * 22 x += overtime * 1.4 return x # Use your own brain next time Mike -- http://mail.python.org/mailman/listinfo/python-list Mike, I wonder if we were both just duped into helping someone with their homework... Shawn I like to write code, so it's not a big deal when it's something so simple. Still, that is beyond dumb! Nice code, by the way. Mike- Hide quoted text - - Show quoted text - Thanks for the help. By the way I am trying to learn the python after work and on weekends. If it was a dumb question, to this group, I will not bother you all again. Without help it will take me longer to learn. Thanks Throw out an example of what you tried with an error message and/or unexpected results. Ask particulars--this will keep you from giving truck drivers a bad name. Sticking-my-fist-out-window-and-making-pulling-down-gesture-ly yours, James -- James Stroud UCLA-DOE Institute for Genomics and Proteomics Box 951570 Los Angeles, CA 90095 http://www.jamesstroud.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: newbee I have an object how to check what's his class?
This doesn't answer your whole post because it asked a lot of questions. But as to finding out whether something is an instance of a class: class X(object): # ... defined as in your post x = X('Fred') x class X contains: type(x) is X True isinstance(x,X) True x.__class__.__name__ 'X' Now for subclasses: class Y(X): extrastuffinY = 1 y = Y('Joe') type(y) is X False isinstance(y,X) True consternation: I can't find neither in tutorial nor with google It's all about isinstance, or __class__. How to test that an object is an instance of my X class?? -- http://mail.python.org/mailman/listinfo/python-list
Re: newbee I have an object how to check what's his class?
Thank You for reply but I found solution suggested by You in a tutorial yesterday. For some reason it doesn't work in my case. code: #mem-dictionary in Y class for storing objects #Y doesn't inherit from X for (i,v) in self.mem.items(): print isinstance(x,X) print isinstance(v,X) print type(x) is X print type(v) is X print v.__class__.__name__ print v.__class__ result: isinstance(x,X) False type(x) is X False type 'list' list Well I can handle my problem. I will give an extra field in class with it's name. But I thought that when a language has tools to learn a class of an object one should use it. [EMAIL PROTECTED] wrote: This doesn't answer your whole post because it asked a lot of questions. But as to finding out whether something is an instance of a class: class X(object): # ... defined as in your post x = X('Fred') x class X contains: type(x) is X True isinstance(x,X) True x.__class__.__name__ 'X' Now for subclasses: class Y(X): extrastuffinY = 1 y = Y('Joe') type(y) is X False isinstance(y,X) True consternation: I can't find neither in tutorial nor with google It's all about isinstance, or __class__. How to test that an object is an instance of my X class?? -- http://mail.python.org/mailman/listinfo/python-list
Re: newbee I have an object how to check what's his class?
In [EMAIL PROTECTED], consternation wrote: Thank You for reply but I found solution suggested by You in a tutorial yesterday. For some reason it doesn't work in my case. code: #mem-dictionary in Y class for storing objects #Y doesn't inherit from X for (i,v) in self.mem.items(): print isinstance(x,X) print isinstance(v,X) print type(x) is X print type(v) is X print v.__class__.__name__ print v.__class__ result: isinstance(x,X) False type(x) is X False type 'list' list Define doesn't work. Obviously lists are not instances of your `X` class. So where's the problem? What did you expect and why? Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: newbee I have an object how to check what's his class?
On 11/10/06, consternation [EMAIL PROTECTED] wrote: result:isinstance(x,X)Falsetype(x) is XFalsetype 'list'listI think you need to show us more of your code. Your variable, v, is not of type X in this example. Instead, it is of type list. What is self.mem.items()? It isn't a dictionary like your comment seems to imply, or you would get a TypeError on that line because dictionaries aren't callable.Please give us enough sample code that we can actually run it and see what you're seeing. -- Jerry -- http://mail.python.org/mailman/listinfo/python-list
Re: newbee I have an object how to check what's his class?
I think I know now where my problems come from. I spare you boring implementation code. The case look like this: I parse xml file something a like X id=0 a1 \a a 2 \a X id=1 a3 \a b 4\b \X /X X id=2 a \a a \a X id=3 a \a b \b \X /X I succesfully constructlop-level X objects - I see all components when i print X0, X1 out with _repr_. I store my X's in memory. I had some problems with this. I googled, red newsgoup ad foud a solution that seemd to be perfect for me (...till now). In the parser- Y class a have a dictionary def __init__ self.mem={} I googled a way how to add elements to dict, I have read the code not the description below ##copied from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66516 def addItem(self,word,pagenumber): self.mem.setdefault(word,[]).append(pagenumber) So my dict looks like{ (id of top-level X) 0 : (the X itself) X0, 2 :X2, 4.. } I wrote it some time and I was tired I haven't pay attention to the breackets at he beginning of outprint TOP LEVEL X WITH ID=0 [class X a1\a a2\a class X a 3\a a 4\a \class X \class X] One can clearly see it's a list :( Shame on me. I did a trick. If my X object is stored in a list and it's the only element of the list I can simply use it like: print v[0] print isinstance(x,X) print isinstance(v[0],X) print type(x) is X print type(v[0]) is X print v[0].__class__ print v[0].__class__.__name__ and results class X no [ a1\a a2\a class X a 3\a a 4\a \class X \class X isinstance(x,X) True:-) type(x) is X False:( ?? __main__.X X temporarily it solves my probblems I'm just curious why type can't handle the test. Thank you for help, and making me think :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: newbee I have an object how to check what's his class?
At Friday 10/11/2006 18:05, consternation wrote: def __init__ self.mem={} I googled a way how to add elements to dict, I have read the code not the description below self.mem[key] = value I strongly suggest you read some introductory Python docs, like http://docs.python.org/tut/tut.html or http://www.diveintopython.org isinstance(x,X) True:-) type(x) is X False:( ?? __main__.X X temporarily it solves my probblems I'm just curious why type can't handle the test. You still didn't show enough code, but I bet that X is an old-style class, that is, you wrote: class X: blablabla instead of class X(object): blablabla For old-style class instances, type(x) is InstanceType, not the actual class. -- Gabriel Genellina Softlab SRL __ Correo Yahoo! Espacio para todos tus mensajes, antivirus y antispam ¡gratis! ¡Abrí tu cuenta ya! - http://correo.yahoo.com.ar -- http://mail.python.org/mailman/listinfo/python-list
jython newbee general question docu / os.fstat
Hi there, unfortunately I am new to Jython and my Jython Essentials book is still in the mail. I looked into the Jython API Doc but could not find the information. I am porting a Python library to Jython and some parts are missing. My question basically is where do I find information on what to use instead. E.g. I could not find information on the os module. I do not find the sys module docu either. The concrete problem is I have something like os.fstat(infile.fileno()) which provokes: IOError: fileno() is not supported in jpython. If this question is already documented somewhere please point me to this direction. I was not able to find it. Best Regards, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: jython newbee general question docu / os.fstat
Mark Fink schrieb: Hi there, unfortunately I am new to Jython and my Jython Essentials book is still in the mail. I looked into the Jython API Doc but could not find the information. I am porting a Python library to Jython and some parts are missing. My question basically is where do I find information on what to use instead. E.g. I could not find information on the os module. I do not find the sys module docu either. The concrete problem is I have something like os.fstat(infile.fileno()) which provokes: IOError: fileno() is not supported in jpython. If this question is already documented somewhere please point me to this direction. I was not able to find it. The general problem lies within JAVA. Instead of python that tries to incorporate os-specific modules, it focuses of a common subset - excluding lots of functionality. fstat and lots of functions in os are not available - for example, you can't change the current working directory. fstat is a posix-call, which is also not available. The general rule of thumb is: whenever you encounter something missing, try to find a solution for java. That could e.g. be a JNI-interfaced special library to access the com-port or something else. If such a solution exists, use that (its easy enough from jython). If not - bad luck. Diez -- http://mail.python.org/mailman/listinfo/python-list
Python Exercises for Newbee
http://www.upriss.org.uk/python/PythonCourse.html -- http://mail.python.org/mailman/listinfo/python-list
sudo open() ? (python newbee question)
hello, i am writing a python script that will be run by a non root user the script needs to open a file in write mode that is owned by root file = open('/etc/apt/sources.list', 'r+') returns permission error how can i call sudo on open()? thanks alot slava -- http://mail.python.org/mailman/listinfo/python-list
Re: sudo open() ? (python newbee question)
The script could be SUID Root, and you could use os.setuid immediately after having performed the task to switch to a non-priviledged user. May be a big security risk, if someone can alter the script, he gains root access to the system... [EMAIL PROTECTED] wrote: hello, i am writing a python script that will be run by a non root user the script needs to open a file in write mode that is owned by root file = open('/etc/apt/sources.list', 'r+') returns permission error how can i call sudo on open()? thanks alot slava -- http://mail.python.org/mailman/listinfo/python-list
Re: sudo open() ? (python newbee question)
On Tue, 14 Jun 2005 11:52:13 +0200, Denis WERNERT [EMAIL PROTECTED] wrote: The script could be SUID Root, and you could use os.setuid immediately after having performed the task to switch to a non-priviledged user. May be a big security risk, if someone can alter the script, he gains root access to the system... I am *not* advocating suid scripts, and *ESPECIALLY NOT* suid Python programs, but if a user can modify an unwriteable suid script owned by root in a an unwriteable directory, then they already have root access to the system (unless there's' a kernel or filesystem bug, in which case all bets are off anyway). Regards, Dan -- Dan Sommers http://www.tombstonezero.net/dan/ -- http://mail.python.org/mailman/listinfo/python-list
Re: sudo open() ? (python newbee question)
On 14 Jun 2005 08:12:17 -0400, rumours say that Dan Sommers [EMAIL PROTECTED] might have written: On Tue, 14 Jun 2005 11:52:13 +0200, Denis WERNERT [EMAIL PROTECTED] wrote: The script could be SUID Root, and you could use os.setuid immediately after having performed the task to switch to a non-priviledged user. May be a big security risk, if someone can alter the script, he gains root access to the system... I am *not* advocating suid scripts, and *ESPECIALLY NOT* suid Python programs, but if a user can modify an unwriteable suid script owned by root in a an unwriteable directory, then they already have root access to the system (unless there's' a kernel or filesystem bug, in which case all bets are off anyway). I believe that the suid bit on scripts (either *sh or python) is completely ignored on most *nix systems. Try this in a shell (bash or ksh) as a sudo-capable user: echo hello /tmp/tmp sudo chown root /tmp/tmp sudo chmod 600 /tmp/tmp cat /tmp/ax.py @ #!/usr/bin/env python x = open(/tmp/tmp, w) x.write(there) x.close() @ sudo chown root /tmp/ax.py sudo chmod a=rx,u+s /tmp/ax.py ls -l /tmp/ax.py /tmp/tmp /tmp/ax.py I get: -r-sr-xr-x 1 root users 75 2005-06-14 16:15 /tmp/ax.py -rw--- 1 root users 6 2005-06-14 16:15 /tmp/tmp Traceback (most recent call last): File /tmp/ax.py, line 2, in ? x = open(/tmp/tmp, w) IOError: [Errno 13] Permission denied: '/tmp/tmp' -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Re: sudo open() ? (python newbee question)
On Tue, 14 Jun 2005 16:18:19 +0300, Christos TZOTZIOY Georgiou [EMAIL PROTECTED] wrote: I believe that the suid bit on scripts (either *sh or python) is completely ignored on most *nix systems. Most *modern* systems, yes. ;-) I must be getting old. :-( Regards, Dan -- Dan Sommers http://www.tombstonezero.net/dan/ -- http://mail.python.org/mailman/listinfo/python-list
Newbee question : List of packages
Hello, I'm quite new in Python and I discover every day very interesting new packages in this newsgroup : Is there somewhere on the web a list (as complete as possible) in which main features of external packages are listed ? Sebastien -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbee question : List of packages
On 6/1/05, Sébastien V. [EMAIL PROTECTED] wrote: I'm quite new in Python and I discover every day very interesting new packages in this newsgroup : Is there somewhere on the web a list (as complete as possible) in which main features of external packages are listed Try http://www.python.org/pypi, or the (older) http://www.vex.net/parnassus/. That said, these days I usually just google for whatever I'm looking for. -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Python Exercises for Newbee
Hi ALL, I am Windows Administrator, moving little ahead from batch files and scripts I started learning Python. I found that Python is very easy and is very well documented. Still I am looking more than examples. As a beginner i want to do lot of excersice from simple addition to complex ...which help me to understand the concepets more clearly. I appreciate if any one can give me such exersices or any link for the same. Thank You , Kanthi Kiran -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Exercises for Newbee
Kanthi Kiran Narisetti [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] | Hi ALL, Hi to you too! | | I am Windows Administrator, moving little ahead from batch files and | scripts I started learning Python. I found that Python is very easy and | is very well documented. Still I am looking more than examples. As a | beginner i want to do lot of excersice from simple addition to complex | ...which help me to understand the concepets more clearly. have you already perused the Python Cookbook? http://aspn.activestate.com/ASPN/Python/Cookbook/ As a Windows admin, you may also be interested in looking at Tim Golden's Python Stuff: http://tgolden.sc.sabren.com/python/index.html Enjoy! -- Vincent Wehren | | I appreciate if any one can give me such exersices or any link for the | same. | | | Thank You , | Kanthi Kiran | -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Exercises for Newbee
Kanthi Kiran Narisetti a écrit : Hi ALL, I am Windows Administrator, moving little ahead from batch files and scripts I started learning Python. I found that Python is very easy and is very well documented. Still I am looking more than examples. As a beginner i want to do lot of excersice from simple addition to complex ...which help me to understand the concepets more clearly. I appreciate if any one can give me such exersices or any link for the same. You may want to try Dive into Python http://diveintopython.org/ -- http://mail.python.org/mailman/listinfo/python-list