[Tutor] Question regarding Python loops

2014-04-10 Thread Conner Crowe
To whom this may concern: I am struggling on two questions: Problem 2. Suppose you are given a function leave(minute) which returns the number of students that leave an exam during its mth minute. Write a function already_left(t) that returns the number of students that left at or before minute

Re: [Tutor] When to use classes

2014-04-10 Thread Ni hung
Thank you Alan, Dave and Cameron (and folks managing this email group)! Your replies were very helpful. Regards ni On Wed, Apr 9, 2014 at 4:25 AM, Cameron Simpson c...@zip.com.au wrote: On 08Apr2014 22:58, Ni hung niih...@gmail.com wrote: I am learning programming using python. I think of

[Tutor] Desktop Notifications on Linux

2014-04-10 Thread Dharmit Shah
Hi all, I am trying to create a script that will go through the /var/log/secure file on a Linux system and provide desktop notifications for failed login attempts. Here is the code - http://pastebin.com/MXP8Yd91 And here's notification.py - http://pastebin.com/BhsSTP6H I am facing issue in the

Re: [Tutor] masking library files

2014-04-10 Thread Mark Lawrence
On 10/04/2014 02:20, uga...@talktalk.net wrote: Please write in plain English if you want to be understood. -Original Message- From: Dave Angel da...@davea.name To: tutor@python.org Sent: Thu, 10 Apr 2014 2:00 Subject: Re: [Tutor] masking library files uga...@talktalk.net Wrote in

Re: [Tutor] Question regarding Python loops

2014-04-10 Thread Peter Otten
Conner Crowe wrote: To whom this may concern: I am struggling on two questions: Problem 2. Suppose you are given a function leave(minute) which returns the number of students that leave an exam during its mth minute. Write a function already_left(t) that returns the number of students

Re: [Tutor] Desktop Notifications on Linux

2014-04-10 Thread Peter Otten
Dharmit Shah wrote: I am trying to create a script that will go through the /var/log/secure file on a Linux system and provide desktop notifications for failed login attempts. Here is the code - http://pastebin.com/MXP8Yd91 And here's notification.py - http://pastebin.com/BhsSTP6H I am

Re: [Tutor] masking library files

2014-04-10 Thread ugajin
-Original Message- From: Mark Lawrence breamore...@yahoo.co.uk To: tutor@python.org Sent: Thu, 10 Apr 2014 9:36 Subject: Re: [Tutor] masking library files On 10/04/2014 02:20, uga...@talktalk.net wrote: Please write in plain English if you want to be understood.

Re: [Tutor] masking library files

2014-04-10 Thread ugajin
-Original Message- From: uga...@talktalk.net To: tutor@python.org Sent: Thu, 10 Apr 2014 10:17 Subject: Re: [Tutor] masking library files -Original Message- From: Mark Lawrence breamore...@yahoo.co.uk To: tutor@python.org Sent: Thu, 10 Apr 2014 9:36 Subject: Re: [Tutor]

Re: [Tutor] masking library files

2014-04-10 Thread Alan Gauld
On 10/04/14 10:30, uga...@talktalk.net wrote: On 10/04/2014 02:20, uga...@talktalk.net wrote: Please write in plain English if you want to be understood. -Original Message- From: Dave Angel da...@davea.name To: tutor@python.org A message left in invisible ink. Please post in

Re: [Tutor] Question regarding Python loops

2014-04-10 Thread Alan Gauld
On 10/04/14 03:04, Conner Crowe wrote: *Problem 2.* # Here's one possible stand-in: def leave(minute): if minute 0: return minute return 0 So far for this i have: *def* *leave*(minute): *if* minute 0: *return* minute *elif* minute=0: *return* 0 Ignoring the

[Tutor] Fwd: masking library files

2014-04-10 Thread ugajin
But I must remember to cc tutor@python.org when replying to you. -Original Message- From: uga...@talktalk.net To: alan.ga...@btinternet.com Sent: Thu, 10 Apr 2014 13:15 Subject: Re: [Tutor] masking library files It is off, and I don't appear have an option to turn it on in

Re: [Tutor] Desktop Notifications on Linux

2014-04-10 Thread Dharmit Shah
Hi Peter, On Thu, Apr 10, 2014 at 2:30 PM, Peter Otten __pete...@web.de wrote: Dharmit Shah wrote: I am trying to create a script that will go through the /var/log/secure file on a Linux system and provide desktop notifications for failed login attempts. Here is the code -

[Tutor] improving speed using and recalling C functions

2014-04-10 Thread Gabriele Brambilla
Hi, I have a program that is reading near 60 elements from a file. For each element it performs 200 times a particular mathematical operation (a numerical interpolation of a function). Now these process takes near 8 hours. Creating a C function and calling it from the code could improve the

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Martin A. Brown
Hi there Gabriele, : I have a program that is reading near 60 elements from a : file. For each element it performs 200 times a particular : mathematical operation (a numerical interpolation of a function). : Now these process takes near 8 hours. Sounds fun! Here are some thoughts

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Alan Gauld
On 10/04/14 16:58, Gabriele Brambilla wrote: For each element it performs 200 times a particular mathematical operation (a numerical interpolation of a function). Now these process takes near 8 hours. The first thing to do in such cases is check that the time is going where you think it is.

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Gabriele Brambilla
Hi, 2014-04-10 13:05 GMT-04:00 Martin A. Brown mar...@linux-ip.net: Hi there Gabriele, : I have a program that is reading near 60 elements from a : file. For each element it performs 200 times a particular : mathematical operation (a numerical interpolation of a function). : Now

Re: [Tutor] masking library files

2014-04-10 Thread ugajin
I do have a Reply All command, but as in this case, there is no recipient other than myself to be included. Also, hitting the Reply All command seems to generate an alert warning message, when recipients include a mail-list address, and some mail list replies go to the mail-list as recipient

Re: [Tutor] masking library files

2014-04-10 Thread Danny Yoo
We should get back to the topic. Did you have a Python question? Meta-discussion on mailing list etiquette must not dominate discussion on helping people learning to program with Python. ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] masking library files

2014-04-10 Thread Danny Yoo
On Wed, Apr 9, 2014 at 7:17 AM, uga...@talktalk.net wrote: Is it common for files saved to a working directory to 'mask' library files located in the Python framework? Hi ugajin, To come back to your original question: yes, unfortunately this happens. I think it's a flaw in the language.

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Mark Lawrence
On 10/04/2014 18:29, Gabriele Brambilla wrote: (I'm sorry but I don't know very well what profiling is) Take a look at these for some tips http://www.huyng.com/posts/python-performance-analysis/ and https://wiki.python.org/moin/PythonSpeed/PerformanceTips -- My fellow Pythonistas, ask

Re: [Tutor] masking library files

2014-04-10 Thread Alan Gauld
On 10/04/14 19:09, uga...@talktalk.net wrote: I do have a Reply All command, but as in this case, there is no recipient other than myself to be included. That's because I (deliberately) replied only to you. :-) commandseems to generate an alert warning message, when recipients include a

Re: [Tutor] masking library files

2014-04-10 Thread Danny Yoo
Apologies for the multiple emails. I'm still paging in from memory how Python imports are working these days. :P If you have the freedom to do so, you may also turn on the absolute import system: https://docs.python.org/2/whatsnew/2.5.html#pep-328-absolute-and-relative-imports so that

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Danny Yoo
Hi Gabriele, Have you profiled your program? Please look at: https://docs.python.org/2/library/profile.html If you can, avoid guessing what is causing performance to drop. Rather, use the tools in the profiling libraries to perform measurements. It may be that your program is taking a

Re: [Tutor] difference between expressions and statements

2014-04-10 Thread bob gailer
Caveat: I began this before there were any other responses. So this may be overkill - but I ike to be thorough. On 4/9/2014 12:49 PM, Jared Nielsen wrote: Hi Pythons, Could someone explain the difference between expressions and statements? I know that expressions are statements that produce a

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Gabriele Brambilla
I'm trying to profile it adding this code: import cProfile import re import pstats cProfile.run('re.compile(foo|bar)', 'restats') p = pstats.Stats('restats') p.strip_dirs().sort_stats('name') p.sort_stats('time').print_stats(10) but where I have to add this in my code? because I obtain Thu

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Danny Yoo
Hi Gabriele, I should probably have pointed you to: https://docs.python.org/2/library/profile.html#instant-user-s-manual instead. Here is an example that uses the cProfile module. Let's say that I'm trying to pinpoint where something is going slow in some_program():

Re: [Tutor] masking library files

2014-04-10 Thread Dave Angel
uga...@talktalk.net Wrote in message: Please write in plain English if you want to be understood Like the op, you post in html. There are a bunch of things that can wrong when you do that, so you should use text mail instead. In the case of the op, he apparently changed the text color to

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Gabriele Brambilla
Hi, I get this result: Thu Apr 10 17:35:53 2014restats 21071736 function calls in 199.883 seconds Ordered by: internal time List reduced from 188 to 10 due to restriction 10 ncalls tottime percall cumtime percall filename:lineno(function) 1 149.479 149.479

Re: [Tutor] difference between expressions and statements

2014-04-10 Thread Jared Nielsen
Thanks for the thorough answer, Bob. I now understand the difference. On Apr 10, 2014 2:11 PM, bob gailer bgai...@gmail.com wrote: Caveat: I began this before there were any other responses. So this may be overkill - but I ike to be thorough. On 4/9/2014 12:49 PM, Jared Nielsen wrote: Hi

[Tutor] Refining Code

2014-04-10 Thread Saba Usmani
My task is :A food vending machine accepts 10p, 20p, 50p and £1 coins. One or more coins are inserted and the current credit is calculated and displayed. A product is selected from those available. The system checks to see if there is enough credit to purchase the product chosen. If there is

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Martin A. Brown
Gabriele, 21071736 function calls in 199.883 seconds The 21 million function calls isn't really a surprise to me, given 18 million calls to file.write(). Given that the majority of the time is still spent in skymaps5.py, I think you'll need to instrument that a bit more to figure

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Danny Yoo
ncalls tottime percall cumtime percall filename:lineno(function) 1 149.479 149.479 199.851 199.851 skymaps5.py:16(mymain) 18101000 28.6820.000 28.6820.000 {method 'write' of 'file' objects} 330445.4700.0006.4440.000

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Gabriele Brambilla
but main is the program that contains everything. I used the profile in this way: import cProfile import pstats def mymain(): #all the code #end of main indentation cProfile.run('mymain()', 'restats', 'time') p = pstats.Stats('restats') p.strip_dirs().sort_stats('name')

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Gabriele Brambilla
sure. def mymain(): def LEstep(n): Emin=10**6 Emax=5*(10**10) Lemin=log10(Emin) Lemax=log10(Emax) stepE=(Lemax-Lemin)/n return (stepE, n, Lemin, Lemax) if __name__ ==

Re: [Tutor] difference between expressions and statements

2014-04-10 Thread bob gailer
On 4/10/2014 5:48 PM, Jared Nielsen wrote: Thanks for the thorough answer, Bob. I now understand the difference. Thanks for the ACK. It helps me remember I have something to contribute. ___ Tutor maillist - Tutor@python.org To unsubscribe or

Re: [Tutor] Refining Code

2014-04-10 Thread Alan Gauld
On 10/04/14 23:26, Saba Usmani wrote: My task is : A food vending machine accepts 10p, 20p, 50p and £1 coins */I have designed the following code, but would like to know how to make it more efficient without making it too complex as I am a beginner Have you covered functions yet? If so you

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Martin A. Brown
Gabriele, but main is the program that contains everything. And, that is precisely the point of profiling the thing that contains 'everything'. Because the bottleneck is almost always somewher inside of 'everything'. But, you have to keep digging until you find it. I saw that you

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Steven D'Aprano
On Thu, Apr 10, 2014 at 11:58:30AM -0400, Gabriele Brambilla wrote: Hi, I have a program that is reading near 60 elements from a file. For each element it performs 200 times a particular mathematical operation (a numerical interpolation of a function). Now these process takes near 8

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Steven D'Aprano
On Fri, Apr 11, 2014 at 10:59:05AM +1000, Steven D'Aprano wrote: It might help if you show us your code. Oops, never mind, I see you have done so. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options:

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Danny Yoo
Ok, good. There's a few things you'll want to fix in your mymain() in order for the profiler to work more effectively in pinpointing issues. 1. Move functionality outside of if __name__ == '__main__': At the moment, you've put the entire functionality of your program in the body of that if

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Danny Yoo
Comment: You are looping over your sliced eel five times. Do you need to? I like eel salad a great deal, as well, but, how about: for k in eel: MYMAP1[i, j, k] = MYMAP1[i, j, k] + myinternet[oo] MYMAP2[i, j, k] = MYMAP2[i, j, k] + myinternet[oo]

Re: [Tutor] Refining Code

2014-04-10 Thread Danny Yoo
Hi Saba, Do you see any similarities between each of the snack choices? Do you see any differences? (Did you happen to use copy-and-paste at any time when you wrote the program?) ___ Tutor maillist - Tutor@python.org To unsubscribe or change

Re: [Tutor] improving speed using and recalling C functions

2014-04-10 Thread Gabriele Brambilla
Hi Danny, I followed your suggestion. Tomorrow morning I will run this new version of the code. Now using a sample of 81 elements (instead of 60) the profile returns: Thu Apr 10 23:25:59 2014restats 18101188 function calls in 1218.626 seconds Ordered by: internal time