Re: [Tutor] What are *appropriate* uses for exec() and eval() ?

2015-02-16 Thread Devin Jeanpierre
On Mon, Feb 16, 2015 at 7:20 PM, Cameron Simpson wrote: > One might use exec() to use code that is valid in one python version but not > another, when you need your program to run in both i.e. to get code that is > syntacticly invalid in one version, but to use it (conditionally) in another > vers

Re: [Tutor] What are *appropriate* uses for exec() and eval() ?

2015-02-16 Thread Cameron Simpson
On 16Feb2015 19:10, Devin Jeanpierre wrote: On Mon, Feb 16, 2015 at 6:15 PM, Steven D'Aprano wrote: Here is a fork of that recipe. It uses an inner class for the new namedtuple class. The only thing which needs exec is the __new__ method. http://code.activestate.com/recipes/578918-yet-another

Re: [Tutor] What are *appropriate* uses for exec() and eval() ?

2015-02-16 Thread Devin Jeanpierre
On Mon, Feb 16, 2015 at 6:15 PM, Steven D'Aprano wrote: > Here is a fork of that recipe. It uses an inner class for the new > namedtuple class. The only thing which needs exec is the __new__ method. > > http://code.activestate.com/recipes/578918-yet-another-namedtuple/ > > This demonstrates a powe

Re: [Tutor] Help with program

2015-02-16 Thread Dave Angel
On 02/16/2015 11:27 AM, Courtney Skinner wrote: Hello, I am trying to build a program that approximates the value of cosine - this is my program so far. It is not returning the right values. Could you tell me what I am doing wrong? You've got several answers that point out several problems

Re: [Tutor] What are *appropriate* uses for exec() and eval() ?

2015-02-16 Thread Steven D'Aprano
On Mon, Feb 16, 2015 at 01:52:16PM -0600, boB Stepp wrote: > I have heard periodically about the potential evils of using exec() > and eval(), including today, on this list. I gather that the first > requirement for safely using these functions is that the passed > argument MUST be from a trusted

Re: [Tutor] Popen was deprecated since Python 2.6, now what?

2015-02-16 Thread Danny Yoo
> Thank for the translation of the hard-to-read docs. Reading the docs threw > me for a loop. I printed out your response and will be studying to try best > understand it. No problem; feel free to ask questions on anything that doesn't make sense, and we'll try to help as best as we can.

Re: [Tutor] Popen was deprecated since Python 2.6, now what?

2015-02-16 Thread Ken G.
On 02/16/2015 06:26 PM, Alan Gauld wrote: On 16/02/15 21:26, Ken G. wrote: I have not been able to figure out on how to use a subprocess in place of my former popen. I have been reading the new materials on the subprocess all day and it is still not quite understandable. Here is what the do

Re: [Tutor] Popen was deprecated since Python 2.6, now what?

2015-02-16 Thread Ken G.
On 02/16/2015 05:11 PM, Danny Yoo wrote: On Mon, Feb 16, 2015 at 1:26 PM, Ken G. wrote: Wow, just found out this morning that the following terms of: import os pr = os.popen("lpr", "w") pr.write(month), pr.write(" "), pr.write("\t\tLine ") was deprecated. In place there of, there is a subpro

Re: [Tutor] Popen was deprecated since Python 2.6, now what?

2015-02-16 Thread Alan Gauld
On 16/02/15 21:26, Ken G. wrote: I have not been able to figure out on how to use a subprocess in place of my former popen. I have been reading the new materials on the subprocess all day and it is still not quite understandable. Here is what the docs say: ###

Re: [Tutor] What are *appropriate* uses for exec() and eval() ?

2015-02-16 Thread Danny Yoo
On Mon, Feb 16, 2015 at 11:52 AM, boB Stepp wrote: > I have heard periodically about the potential evils of using exec() > and eval(), including today, on this list. I gather that the first > requirement for safely using these functions is that the passed > argument MUST be from a trusted source.

Re: [Tutor] Popen was deprecated since Python 2.6, now what?

2015-02-16 Thread Danny Yoo
On Mon, Feb 16, 2015 at 1:26 PM, Ken G. wrote: > Wow, just found out this morning that the following > terms of: > > import os > pr = os.popen("lpr", "w") > pr.write(month), pr.write(" "), > pr.write("\t\tLine ") > > was deprecated. In place there of, there is > a subprocess to use. Hi Ken, Yes

[Tutor] Popen was deprecated since Python 2.6, now what?

2015-02-16 Thread Ken G.
Wow, just found out this morning that the following terms of: import os pr = os.popen("lpr", "w") pr.write(month), pr.write(" "), pr.write("\t\tLine ") was deprecated. In place there of, there is a subprocess to use. I have not been able to figure out on how to use a subprocess in place of my f

[Tutor] What are *appropriate* uses for exec() and eval() ?

2015-02-16 Thread boB Stepp
I have heard periodically about the potential evils of using exec() and eval(), including today, on this list. I gather that the first requirement for safely using these functions is that the passed argument MUST be from a trusted source. So what would be examples where the use of these functions

Re: [Tutor] Help with program

2015-02-16 Thread Peter Otten
Courtney Skinner wrote: > Hello, > > I am trying to build a program that approximates the value of cosine - > this is my program so far. It is not returning the right values. Could you > tell me what I am doing wrong? > > > def main(): > > import math > > print("This program appro

Re: [Tutor] Help with program

2015-02-16 Thread Alan Gauld
On 16/02/15 16:27, Courtney Skinner wrote: Hello, I am trying to build a program that approximates the value of cosine def main(): import math Its usual to do the imports outside the function at the tyop of the file. Python doesn't actually care much but its 'standard practice'.

Re: [Tutor] Help with program

2015-02-16 Thread Mark Lawrence
On 16/02/2015 16:27, Courtney Skinner wrote: Hello, I am trying to build a program that approximates the value of cosine - this is my program so far. It is not returning the right values. Could you tell me what I am doing wrong? def main(): import math Not that it matters but imports

[Tutor] Help with program

2015-02-16 Thread Courtney Skinner
Hello, I am trying to build a program that approximates the value of cosine - this is my program so far. It is not returning the right values. Could you tell me what I am doing wrong? def main(): import math print("This program approximates the cosine of x by summing") print(

Re: [Tutor] Python Help with Program

2015-02-16 Thread Steven D'Aprano
Hi Tina, or Taylor, welcome! Sorry but your email "From" header says your name is Tina and your signature says Taylor so I'm not sure which name you prefer. On Sun, Feb 15, 2015 at 07:26:35PM -0600, Tina Figz wrote: > I'm having a problem with my program and I'm not sure how to correct it > (I'

Re: [Tutor] Python Help with Program

2015-02-16 Thread Mark Lawrence
On 16/02/2015 08:24, Alan Gauld wrote: On 16/02/15 01:26, Tina Figz wrote: I'm having a problem with my program and I'm not sure how to correct it (I'm in an intro programming class). My program is supposed two numbers and count the number of carry operations. This is what I have: n1 = int(ra

Re: [Tutor] Python Help with Program

2015-02-16 Thread Alan Gauld
On 16/02/15 01:26, Tina Figz wrote: I'm having a problem with my program and I'm not sure how to correct it (I'm in an intro programming class). My program is supposed two numbers and count the number of carry operations. This is what I have: n1 = int(raw_input('Number #1: ')) n2 = int(raw_inp