[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 XYZ ]$ python ~/prog.py
The program's location is ~/prog.py

This should be the outcome of the program.

I tried with os.getcwd()
os.getcwd() will return /path/to/folder/XYZ.

Any suggestions?

Thanks,
Nikunj Badjatya
Bangalore, India
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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.?
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 XYZ ]$ python ~/prog.py 
The program's location is ~/prog.py

This should be the outcome of the program.

I tried with os.getcwd()
os.getcwd() will return /path/to/folder/XYZ.



Any suggestions?
 
Thanks,
Nikunj Badjatya
Bangalore, India


-Inline Attachment Follows-

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


I think this is what you want:

>>> import sys
>>> sys.argv[0]
'C:\\Python26\\testingscripts\\lowdir.py'
>>> 

David



  ___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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  | Block
> sender  | Block
> domain 
>
>
>
> --- 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.?
> 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 XYZ ]$ python ~/prog.py
> The program's location is ~/prog.py
>
> This should be the outcome of the program.
>
> I tried with os.getcwd()
> os.getcwd() will return /path/to/folder/XYZ.
>
> Any suggestions?
>
> Thanks,
> Nikunj Badjatya
> Bangalore, India
>
> -Inline Attachment Follows-
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
> I think this is what you want:
>
> >>> import sys
> >>> sys.argv[0]
> 'C:\\Python26\\testingscripts\\lowdir.py'
> >>>
>
> David
>
>
>
> ___
> 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] 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 out of 10 (below your Auto Allow 
>> threshold)
>> | Approve sender  | Block
>> sender  | Block
>> domain 
>>
>>
>>
>> --- 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.?
>> 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 XYZ ]$ python ~/prog.py
>> The program's location is ~/prog.py
>>
>> This should be the outcome of the program.
>>
>> I tried with os.getcwd()
>> os.getcwd() will return /path/to/folder/XYZ.
>>
>> Any suggestions?
>>
>> Thanks,
>> Nikunj Badjatya
>> Bangalore, India
>>
>> -Inline Attachment Follows-
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>> I think this is what you want:
>>
>> >>> import sys
>> >>> sys.argv[0]
>> 'C:\\Python26\\testingscripts\\lowdir.py'
>> >>>
>>
>> David
>>
>>
>>
>> ___
>> 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
>
>


-- 
Spoorthi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 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  | 
>>> Block
>>> sender  | Block
>>> domain 
>>>
>>>
>>>
>>> --- 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.?
>>> 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 XYZ ]$ python ~/prog.py
>>> The program's location is ~/prog.py
>>>
>>> This should be the outcome of the program.
>>>
>>> I tried with os.getcwd()
>>> os.getcwd() will return /path/to/folder/XYZ.
>>>
>>> Any suggestions?
>>>
>>> Thanks,
>>> Nikunj Badjatya
>>> Bangalore, India
>>>
>>> -Inline Attachment Follows-
>>>
>>> ___
>>> Tutor maillist  -  Tutor@python.org
>>> To unsubscribe or change subscription options:
>>> http://mail.python.org/mailman/listinfo/tutor
>>>
>>>
>>> I think this is what you want:
>>>
>>> >>> import sys
>>> >>> sys.argv[0]
>>> 'C:\\Python26\\testingscripts\\lowdir.py'
>>> >>>
>>>
>>> David
>>>
>>>
>>>
>>> ___
>>> 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
>>
>>
>
>
> --
> Spoorthi
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 script that was used to invoke the Python
interpreter. If the script directory is not available (e.g. if the
interpreter is invoked interactively or if the script is read from standard
input), path[0] is the empty string, which directs Python to search modules
in the current directory first. Notice that the script directory is inserted
before the entries inserted as a result of PYTHONPATH.*

On Fri, Feb 5, 2010 at 5:38 PM, Rohit Roger$  wrote:

>
> 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 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  |
 Block sender| 
 Block
 domain 



 --- 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.?
 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 XYZ ]$ python ~/prog.py
 The program's location is ~/prog.py

 This should be the outcome of the program.

 I tried with os.getcwd()
 os.getcwd() will return /path/to/folder/XYZ.

 Any suggestions?

 Thanks,
 Nikunj Badjatya
 Bangalore, India

 -Inline Attachment Follows-

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor


 I think this is what you want:

 >>> import sys
 >>> sys.argv[0]
 'C:\\Python26\\testingscripts\\lowdir.py'
 >>>

 David



 ___
 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
>>>
>>>
>>
>>
>> --
>> Spoorthi
>>
>
>


-- 
Spoorthi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 initialized upon program startup, the first item of this list, path[0],
> is the directory containing the script that was used to invoke the Python
> interpreter. If the script directory is not available (e.g. if the
> interpreter is invoked interactively or if the script is read from standard
> input), path[0] is the empty string, which directs Python to search
> modules in the current directory first. Notice that the script directory is
> inserted before the entries inserted as a result of PYTHONPATH.*
>
>
> On Fri, Feb 5, 2010 at 5:38 PM, Rohit Roger$ wrote:
>
>>
>> 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 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 | 
> Block
> sender  | Block
> domain 
>
>
>
> --- 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.?
> 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 XYZ ]$ python ~/prog.py
> The program's location is ~/prog.py
>
> This should be the outcome of the program.
>
> I tried with os.getcwd()
> os.getcwd() will return /path/to/folder/XYZ.
>
> Any suggestions?
>
> Thanks,
> Nikunj Badjatya
> Bangalore, India
>
> -Inline Attachment Follows-
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>
> I think this is what you want:
>
> >>> import sys
> >>> sys.argv[0]
> 'C:\\Python26\\testingscripts\\lowdir.py'
> >>>
>
> David
>
>
>
> ___
> 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


>>>
>>>
>>> --
>>> Spoorthi
>>>
>>
>>
>
>
> --
> Spoorthi
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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:
>>
>> On Thu, Feb 4, 2010 at 1:19 PM, ssiverling  wrote:
>>
>>> So I have been working on this example for a little while.  I looked for
>>> the
>>> answer before posting.  I tried to use two raw inputs, then use
>>> sys.stdout.write, to add them together.  However I think I might need to
>>> use
>>> a variable.  Any help would be appreciated.  Thank you in advance.
>>
>> What have you done so far? If you show us some code we can better help
>> you.
>>
>> Kent
>> ___
>> Tutor maillist  -  tu...@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
> http://old.nabble.com/file/p27460922/psy psy
> --
> View this message in context: 
> http://old.nabble.com/Variable%3A-From-input-and-output-tp27457364p27460922.html
> Sent from the Python - tutor mailing list archive at Nabble.com.
>
> ___
> Tutor maillist  -  tu...@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] 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  wrote:

> 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:
> >>
> >> On Thu, Feb 4, 2010 at 1:19 PM, ssiverling 
> wrote:
> >>
> >>> So I have been working on this example for a little while.  I looked
> for
> >>> the
> >>> answer before posting.  I tried to use two raw inputs, then use
> >>> sys.stdout.write, to add them together.  However I think I might need
> to
> >>> use
> >>> a variable.  Any help would be appreciated.  Thank you in advance.
> >>
> >> What have you done so far? If you show us some code we can better help
> >> you.
> >>
> >> Kent
> >> ___
> >> Tutor maillist  -  Tutor@python.org
> >> To unsubscribe or change subscription options:
> >> http://mail.python.org/mailman/listinfo/tutor
> >>
> >>
> > http://old.nabble.com/file/p27460922/psy psy
> > --
> > View this message in context:
> http://old.nabble.com/Variable%3A-From-input-and-output-tp27457364p27460922.html
> > Sent from the Python - tutor mailing list archive at Nabble.com.
> >
> > ___
> > 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
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2010-02-05 Thread Daniel Sarmiento




Date: Fri, 5 Feb 2010 17:43:37 +0530
From: Spoorthi 
To: "Rohit Roger$" 
Cc: tutor 
Subject: Re: [Tutor] python function to know the path of the program
in  execution *
Message-ID:
<6c9f52051002050413o57bd76bax7ac5986b17304...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

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 script that was used to invoke the Python
interpreter. If the script directory is not available (e.g. if the
interpreter is invoked interactively or if the script is read from standard
input), path[0] is the empty string, which directs Python to search modules
in the current directory first. Notice that the script directory is inserted
before the entries inserted as a result of PYTHONPATH.*

On Fri, Feb 5, 2010 at 5:38 PM, Rohit Roger$  wrote:



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 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<https://www.boxbe.com/mail-screening>)
| Approve sender <https://www.boxbe.com/anno?tc=1529381613_418589136> |
Block sender<https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b>| Block
domain <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b&dom>



--- 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.?
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 XYZ ]$ python ~/prog.py
The program's location is ~/prog.py

This should be the outcome of the program.

I tried with os.getcwd()
os.getcwd() will return /path/to/folder/XYZ.

Any suggestions?

Thanks,
Nikunj Badjatya
Bangalore, India

-Inline Attachment Follows-

___
Tutor maillist  -  Tutor@python.org<http://mc/compose?to=tu...@python.org>
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


I think this is what you want:


import sys
sys.argv[0]

'C:\\Python26\\testingscripts\\lowdir.py'




David



___
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





--
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 Django once. I don't know if 
that's what you are looking for. You might want to take a loook at 
http://pyref.infogami.com/__file__


HTH

Daniel
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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

2010-02-05 Thread Rohit Roger$
ok..

On Fri, Feb 5, 2010 at 6:23 PM, Daniel Sarmiento wrote:

>  Junk Score: 2 out of 10 (below your Auto Allow 
> threshold<https://www.boxbe.com/mail-screening>)
> | Approve sender <https://www.boxbe.com/anno?tc=1530328725_1435846689> | Block
> sender <https://www.boxbe.com/anno?tc=1530328725_1435846689&disp=b> | Block
> domain <https://www.boxbe.com/anno?tc=1530328725_1435846689&disp=b&dom>
>
>
>
>  Date: Fri, 5 Feb 2010 17:43:37 +0530
>> From: Spoorthi 
>> To: "Rohit Roger$" 
>> Cc: tutor 
>> Subject: Re: [Tutor] python function to know the path of the program
>>in  execution *
>> Message-ID:
>><6c9f52051002050413o57bd76bax7ac5986b17304...@mail.gmail.com>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> 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 script that was used to invoke the Python
>> interpreter. If the script directory is not available (e.g. if the
>> interpreter is invoked interactively or if the script is read from
>> standard
>> input), path[0] is the empty string, which directs Python to search
>> modules
>> in the current directory first. Notice that the script directory is
>> inserted
>> before the entries inserted as a result of PYTHONPATH.*
>>
>> On Fri, Feb 5, 2010 at 5:38 PM, Rohit Roger$ 
>> wrote:
>>
>>
>>> 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 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<
>>>>>> https://www.boxbe.com/mail-screening>)
>>>>>> | Approve sender <https://www.boxbe.com/anno?tc=1529381613_418589136>
>>>>>> |
>>>>>> Block sender<
>>>>>> https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b>| Block
>>>>>> domain <https://www.boxbe.com/anno?tc=1529381613_418589136&disp=b&dom
>>>>>> >
>>>>>>
>>>>>>
>>>>>>
>>>>>> --- 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.?
>>>>>> 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 XYZ ]$ python ~/prog.py
>>>>>> The program's location is ~/prog.py
>>>>>>
>>>>>> This should be the outcome of the program.
>>>>>>
>>>>>> I tried with os.getcwd()
>>>>>> os.getcwd() will return /path/to/folder/XYZ.
>>>>>>
>>>>>> Any suggestions?
>>>>>>
>>>>>> Thanks,
>>>>>> Nikunj Badjatya
>>>>>> Bangalore, India
>>>>>>
>>>>>> -Inline Attachment Follows-
>>>>>>
>>>>>> ___
>>>>>> Tutor maillist  -  Tutor@python.org<
>>>>>> http://mc/com

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

2010-02-05 Thread David Hutto
t;>>> 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 XYZ ]$ python ~/prog.py
>>>>> The program's location is ~/prog.py
>>>>>
>>>>> This should be the outcome of the program.
>>>>>
>>>>> I tried with os.getcwd()
>>>>> os.getcwd() will return /path/to/folder/XYZ.
>>>>>
>>>>> Any suggestions?
>>>>>
>>>>> Thanks,
>>>>> Nikunj Badjatya
>>>>> Bangalore, India
>>>>>
>>>>> -Inline Attachment Follows-
>>>>>
>>>>> ___
>>>>> Tutor maillist  -  Tutor@python.org<http://mc/compose?to=tu...@python.org>
>>>>> To unsubscribe or change subscription options:
>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>>>
>>>>> I think this is what you want:
>>>>>
>>>>>>>> import sys
>>>>>>>> sys.argv[0]
>>>>> 'C:\\Python26\\testingscripts\\lowdir.py'
>>>>>>>>
>>>>>
>>>>> David
>>>>>
>>>>>
>>>>>
>>>>> ___
>>>>> 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
>>>>
>>>>
>>>
>>>
>>> --
>>> 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 Django once. I don't know if 
that's what you are looking for. You might want to take a loook at 
http://pyref.infogami.com/__file__

HTH

Daniel
___
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] python function to know the path of the program in execution *

2010-02-05 Thread David Hutto
gt;>
>>>>> 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 XYZ ]$ python ~/prog.py
>>>>> The program's location is ~/prog.py
>>>>>
>>>>> This should be the outcome of the program.
>>>>>
>>>>> I tried with os.getcwd()
>>>>> os.getcwd() will return /path/to/folder/XYZ.
>>>>>
>>>>> Any suggestions?
>>>>>
>>>>> Thanks,
>>>>> Nikunj Badjatya
>>>>> Bangalore, India
>>>>>
>>>>> -Inline Attachment Follows-
>>>>>
>>>>> ___
>>>>> Tutor maillist  -  Tutor@python.org<http://mc/compose?to=tu...@python.org>
>>>>> To unsubscribe or change subscription options:
>>>>> http://mail.python.org/mailman/listinfo/tutor
>>>>>
>>>>>
>>>>> I think this is what you want:
>>>>>
>>>>>>>> import sys
>>>>>>>> sys.argv[0]
>>>>> 'C:\\Python26\\testingscripts\\lowdir.py'
>>>>>>>>
>>>>>
>>>>> David
>>>>>
>>>>>
>>>>>
>>>>> ___
>>>>> 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
>>>>
>>>>
>>>
>>>
>>> --
>>> 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 Django once. I don't know if 
that's what you are looking for. You might want to take a loook at 
http://pyref.infogami.com/__file__

HTH

Daniel
___
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


[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 check my code 
and catch those silly mis-spelling of a variable.

Mike

 



 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[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 example:
slope(2, 4, 1, 2)
Expected:
2.0
Got:
2

This is the function, and how I modified so it would return a floating
point value (multiply by 1.0). But this doesn't feel the right way to
do things, or is it?

def slope(x1, y1, x2, y2):
"""
>>> slope(5, 3, 4, 2)
1.0
>>> slope(1, 2, 3, 2)
0.0
>>> slope(1, 2, 3, 3)
0.5
>>> slope(2, 4, 1, 2)
2.0
"""
result_slope = ((y2 - y1) / (x2 - x1)) * 1.0
return result_slope

Another question is, anybody knows if these questions from this online
book are answered somewhere? I can't manage to find them?

Thank you for your time.
Antonio.

-- 
-
Antonio de la Fuente Martínez
E-mail: t...@muybien.org
-

Guarda que comer y no que hacer. 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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
> declaration? I've gotten around it in Python by using Pyflakes to check my
> code and catch those silly mis-spelling of a variable.


I've never had any serious problems (though I've never worked on huge
projects with Python), but here are some of the reasons that pop into my
mind:

1) We're big boys and girls - we're responsible enough to pay attention to
our variables

2) I have no clue, but it may make it easier on the garbage collection -
once a value/object no longer has a reference it can probably be cleared up.
But those c variables you declared way back in the beginning of your
program? Still there (though an anti-argument would be that you're not using
scope properly in this case)

3) If you're writing a small program you should be able to see everything,
but if you're using a big enough program you should be using an IDE that
keeps track of that sort of thing.

I don't know how valid those reasons would be considered... but I, for one,
like the freedom of not having to type:

int a = 0;

or

int a;

MyClass(){
a = 0;
}

or any other waste of keystrokes. If I want a new variable, I'll make it
responsibly - whether I need it here or there...

but that's my two cents
-Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 failed, because is expecting a
> floating point value and not an integer:
>

try to cast your values as float instead:

try:
x1 = float(x1)
x2 = float(x2)
y1 = float(y1)
y2 = float(y2)
except ValueError:
print "Error, not a floating point!"
raise

Then you don't need to worry about the * 1.0

HTH,
Wayne


>
> Failed example:
>slope(2, 4, 1, 2)
> Expected:
>2.0
> Got:
>2
>
> This is the function, and how I modified so it would return a floating
> point value (multiply by 1.0). But this doesn't feel the right way to
> do things, or is it?
>
> def slope(x1, y1, x2, y2):
>"""
>>>> slope(5, 3, 4, 2)
>1.0
>>>> slope(1, 2, 3, 2)
>0.0
>>>> slope(1, 2, 3, 3)
>0.5
>>>> slope(2, 4, 1, 2)
>2.0
>"""
>result_slope = ((y2 - y1) / (x2 - x1)) * 1.0
>return result_slope
>
> Another question is, anybody knows if these questions from this online
> book are answered somewhere? I can't manage to find them?
>
> Thank you for your time.
> Antonio.
>
> --
> -
> Antonio de la Fuente Martínez
> E-mail: t...@muybien.org
> -
>
> Guarda que comer y no que hacer.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 value and not an integer:
> 
> Failed example:
> slope(2, 4, 1, 2)
> Expected:
> 2.0
> Got:
> 2

Python handles integers a bit counter intuitive. It does not
automatically converts you devision from an int to a float number. 

>>> 1 / 2
0
>>> 3 / 2
1

You would expect this to become 0.5 and 1.5.

> This is the function, and how I modified so it would return a floating
> point value (multiply by 1.0). But this doesn't feel the right way to
> do things, or is it?

Not is is not, if you would type this into a python shell or idle you
will still fail the 3rd test.

>>> (3-2)/(3-1) * 1.0
0.0

> def slope(x1, y1, x2, y2):
> """
> >>> slope(5, 3, 4, 2)
> 1.0
> >>> slope(1, 2, 3, 2)
> 0.0
> >>> slope(1, 2, 3, 3)
> 0.5
> >>> slope(2, 4, 1, 2)
> 2.0
> """
> result_slope = ((y2 - y1) / (x2 - x1)) * 1.0
> return result_slope

You will need to find a way to convert your int numbers to float numbers
*before* doing the calculation.

Greets
Sander

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 won't ever be able to get "2.2" for
example.

On 2/5/10, 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 failed, because is expecting a
> floating point value and not an integer:
>
> Failed example:
> slope(2, 4, 1, 2)
> Expected:
> 2.0
> Got:
> 2
>
> This is the function, and how I modified so it would return a floating
> point value (multiply by 1.0). But this doesn't feel the right way to
> do things, or is it?
>
> def slope(x1, y1, x2, y2):
> """
> >>> slope(5, 3, 4, 2)
> 1.0
> >>> slope(1, 2, 3, 2)
> 0.0
> >>> slope(1, 2, 3, 3)
> 0.5
> >>> slope(2, 4, 1, 2)
> 2.0
> """
> result_slope = ((y2 - y1) / (x2 - x1)) * 1.0
> return result_slope
>
> Another question is, anybody knows if these questions from this online
> book are answered somewhere? I can't manage to find them?
>
> Thank you for your time.
> Antonio.
>
> --
> -
> Antonio de la Fuente Martínez
> E-mail: t...@muybien.org
> -
>
> Guarda que comer y no que hacer.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>

-- 
Sent from my mobile device
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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_slope)

Or just 


 return float(y2-y1/x2-x1)

You might want to use a try/except to catch a zero division error too?


--
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


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 you suggesting this, surely this will cause the decimal values
to be truncated?  Or does this somehow work differently in Python 3?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 misplaced the ) It should have been after y1.

return float(x1-y1)/(x2-y2)

Sorry about that.

Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


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 whole, it should only be round the first expression.


Alan G.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor