[Tutor] python function to know the path of the program in execution

2010-02-05 Thread nikunj badjatya
Hi , Is there any python function to know the path of the python program under execution.? If someone executes a program , he should come to know the path of the program..!! ex. suppose a user ABC is running prog.py which is in ~ directory, the user currently is in XYZ directory. [ a...@localhost X

Re: [Tutor] python function to know the path of the program in execution

2010-02-05 Thread David Hutto
--- On Fri, 2/5/10, nikunj badjatya wrote: From: nikunj badjatya Subject: [Tutor] python function to know the path of the program in execution To: tutor@python.org Date: Friday, February 5, 2010, 5:08 AM Hi , Is there any python function to know the path of the python program under execution

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Rohit Roger$
Answer : >>> import sys >>> rohit = sys.argv[0] >>> print rohit it returns the name of the path On Fri, Feb 5, 2010 at 4:13 PM, David Hutto wrote: > Junk Score: 2 out of 10 (below your Auto Allow > threshold) > | Approve sender

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Spoorthi
sys.path[0] should be serving the purpose effectively I guess On Fri, Feb 5, 2010 at 5:29 PM, Rohit Roger$ wrote: > Answer : > >>> import sys > >>> rohit = sys.argv[0] > >>> print rohit > it returns the name of the path > > On Fri, Feb 5, 2010 at 4:13 PM, David Hutto wrote: > >> Junk Score: 2

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Rohit Roger$
sys.path[0] returns none On Fri, Feb 5, 2010 at 5:36 PM, Spoorthi wrote: > sys.path[0] should be serving the purpose effectively I guess > > > On Fri, Feb 5, 2010 at 5:29 PM, Rohit Roger$ wrote: > >> Answer : >> >>> import sys >> >>> rohit = sys.argv[0] >> >>> print rohit >> it returns the na

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Spoorthi
The below data(in blue) made me converge upon sys.path[0] for this particular problem...I dont think it returns None if a Python script is used. Can anyone please correct me if I am wrong *As initialized upon program startup, the first item of this list, path[0], is the directory containing the sc

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Rohit Roger$
it tell the path upto the python file.. On Fri, Feb 5, 2010 at 5:43 PM, Spoorthi wrote: > The below data(in blue) made me converge upon sys.path[0] for this > particular problem...I dont think it returns None if a Python script is > used. Can anyone please correct me if I am wrong > > *As initia

Re: [Tutor] Variable: From input and output

2010-02-05 Thread Kent Johnson
On Thu, Feb 4, 2010 at 5:39 PM, ssiverling wrote: > > > I uploaded a file.  I know it's not very impressive. Where did you upload it? For short programs you can just include them in your email. Also, please don't top-post, and please subscribe to the list. Kent > > > Kent Johnson wrote: >> >>

Re: [Tutor] Variable: From input and output

2010-02-05 Thread Rohit Roger$
Answer: Here is the code : >>> firstname = raw_input("\n Enter your first name : ") >>> lastname = raw_input("\n Enter your last name : ") >>> print (" Printing Your Complete name.") >>> print firstname + " " + lastname Regards, Rohit On Fri, Feb 5, 2010 at 6:04 PM, Kent Johnson wro

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread Daniel Sarmiento
- Spoorthi -- Spoorthi -- next part -- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/tutor/attachments/20100205/8272d339/attachment-0001.htm> -- I remember using the __file__ attribute in Djan

Re: [Tutor] python function to know the path of the program in execution * *

2010-02-05 Thread Rohit Roger$
o/folder/XYZ. >>>>>> >>>>>> Any suggestions? >>>>>> >>>>>> Thanks, >>>>>> Nikunj Badjatya >>>>>> Bangalore, India >>>>>> >>>>>> -Inline Attachment Follows- >

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread David Hutto
;>>>> os.getcwd() will return /path/to/folder/XYZ. >>>>> >>>>> Any suggestions? >>>>> >>>>> Thanks, >>>>> Nikunj Badjatya >>>>> Bangalore, India >>>>> >

Re: [Tutor] python function to know the path of the program in execution *

2010-02-05 Thread David Hutto
th os.getcwd() >>>>> os.getcwd() will return /path/to/folder/XYZ. >>>>> >>>>> Any suggestions? >>>>> >>>>> Thanks, >>>>> Nikunj Badjatya >>>>> Bangalore, India >>>>> >

[Tutor] Variable declaration

2010-02-05 Thread Hansen, Mike
Perl has "use strict;" to force variable declaration. My insane Perl loving co-workers think it's evil that Python doesn't have variable declaration. =) What are some of the reasons/arguments on why Python doesn't need variable declaration? I've gotten around it in Python by using Pyflakes to

[Tutor] Simple variable type question

2010-02-05 Thread Antonio de la Fuente
Hi all, I'm trying to do exercises from: http://openbookproject.net/thinkcs/python/english2e/ch05.html exercise number 3 (slope function) and when I run it: python ch05.py -v the doctest for the slope function failed, because is expecting a floating point value and not an integer: Failed exam

Re: [Tutor] Variable declaration

2010-02-05 Thread Wayne Werner
On Fri, Feb 5, 2010 at 10:40 AM, Hansen, Mike wrote: > Perl has "use strict;" to force variable declaration. > > My insane Perl loving co-workers think it's evil that Python doesn't have > variable declaration. =) > > What are some of the reasons/arguments on why Python doesn't need variable > de

Re: [Tutor] Simple variable type question

2010-02-05 Thread Wayne Werner
On Fri, Feb 5, 2010 at 10:54 AM, Antonio de la Fuente wrote: > Hi all, > > I'm trying to do exercises from: > > http://openbookproject.net/thinkcs/python/english2e/ch05.html > > exercise number 3 (slope function) and when I run it: > > python ch05.py -v > > the doctest for the slope function faile

Re: [Tutor] Simple variable type question

2010-02-05 Thread Sander Sweers
On vr, 2010-02-05 at 16:54 +, Antonio de la Fuente wrote: > http://openbookproject.net/thinkcs/python/english2e/ch05.html > > exercise number 3 (slope function) and when I run it: > > python ch05.py -v > > the doctest for the slope function failed, because is expecting a > floating point val

Re: [Tutor] Simple variable type question

2010-02-05 Thread Luke Paireepinart
You want to promote one of your variables to float before you do the calculation, this will make all other variables automatically cast. So (float(y2) - y1) / (x2-x1). if you do the float cast after the calculation, you will do the calculation as integers and so even though you'll get "2.0" you wo

Re: [Tutor] Simple variable type question

2010-02-05 Thread Alan Gauld
"Antonio de la Fuente" wrote the doctest for the slope function failed, because is expecting a floating point value and not an integer: So convert it to a float. def slope(x1, y1, x2, y2): result_slope = ((y2 - y1) / (x2 - x1)) * 1.0 return result_slope return float(result

Re: [Tutor] Simple variable type question

2010-02-05 Thread Luke Paireepinart
On Fri, Feb 5, 2010 at 12:45 PM, Alan Gauld wrote: > > "Antonio de la Fuente" wrote > >> the doctest for the slope function failed, because is expecting a >> >> floating point value and not an integer: >> > > So convert it to a float. > > Or just > return float(y2-y1/x2-x1) > > Alan why are y

Re: [Tutor] Simple variable type question

2010-02-05 Thread ALAN GAULD
Or just return float(y2-y1/x2-x1) >> >> >Alan why are you suggesting this, surely this will cause the decimal values to >be truncated? Or does this somehow work differently in Python 3? > It would work different in v3 because / is no longer interger division. However, I just

Re: [Tutor] Simple variable type question

2010-02-05 Thread Sander Sweers
On vr, 2010-02-05 at 20:39 +, ALAN GAULD wrote: > return float(x1-y1)/(x2-y2) Does not work properly in version 2. Example is the 3rd doc test: float((3-2)/(3-1)) gives 0.0 instead of 0.5. Greets Sander ___ Tutor maillist - Tutor@python.org To u

Re: [Tutor] Simple variable type question

2010-02-05 Thread Alan Gauld
"Sander Sweers" wrote On vr, 2010-02-05 at 20:39 +, ALAN GAULD wrote: return float(x1-y1)/(x2-y2) Does not work properly in version 2. Example is the 3rd doc test: float((3-2)/(3-1)) gives 0.0 instead of 0.5. That's what I did wrong dfirst time round, I had the parens round the who