Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Forcing Python to detect DocumentRoot

Reply
Thread Tools

Forcing Python to detect DocumentRoot

 
 
Ferrous Cranus
Guest
Posts: n/a
 
      01-16-2013
When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html

f = open( '../' + page )

How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself?
 
Reply With Quote
 
 
 
 
Joel Goldstick
Guest
Posts: n/a
 
      01-16-2013
On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus <(E-Mail Removed)>wrote:

> When trying to open an html template within Python script i use a relative
> path to say go one folder back and open index.html
>
> f = open( '../' + page )
>
> How to say the same thing in an absolute way by forcing Python to detect
> DocumentRoot by itself?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


I don't think I understand your question. But, I think your answer is
here: http://docs.python.org/2/library/os.path.html

--
Joel Goldstick
http://joelgoldstick.com

 
Reply With Quote
 
 
 
 
Ferrous Cranus
Guest
Posts: n/a
 
      01-16-2013
Τη Τετάρτη, 16 Ιανουαρίου 2013 4:01:07 μ.μ. UTC+2, ο χρήστης Joel Goldstick *γραψε:
> On Wed, Jan 16, 2013 at 8:51 AM, Ferrous Cranus <(E-Mail Removed)> wrote:
>
> When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html
>
>
>
>
> f = open( '../' + page )
>
>
>
> How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself?
>
> --
>
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
> I don't think I understand your question.* But, I think your answer is here:


Nowhere that page says something about python detecting documentroot directory (www or public_html) that is.
 
Reply With Quote
 
Ferrous Cranus
Guest
Posts: n/a
 
      01-17-2013
Document Root for me is /home/nikos/public_html
Is where Apache store the user www files.

How to tell it my using a variable?

 
Reply With Quote
 
rusi
Guest
Posts: n/a
 
      01-17-2013
On Jan 16, 6:51*pm, Ferrous Cranus <(E-Mail Removed)> wrote:
> When trying to open an html template within Python script i use a relative path to say go one folder back and open index.html
>
> f = open( '../' + page )
>
> How to say the same thing in an absolute way by forcing Python to detect DocumentRoot by itself?


Is this what you want?
import os
os.getcwd()
 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      01-17-2013
In article <(E-Mail Removed)>,
Ferrous Cranus <(E-Mail Removed)> wrote:

> When trying to open an html template within Python script i use a relative
> path to say go one folder back and open index.html
>
> f = open( '../' + page )
>
> How to say the same thing in an absolute way by forcing Python to detect
> DocumentRoot by itself?


Can you give us more details of what you're doing. Is there some web
framework you're using? Can you post some code that's not working for
you?
 
Reply With Quote
 
Joel Goldstick
Guest
Posts: n/a
 
      01-17-2013
On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith <(E-Mail Removed)> wrote:

> In article <(E-Mail Removed)>,
> Ferrous Cranus <(E-Mail Removed)> wrote:
>
> > When trying to open an html template within Python script i use a

> relative
> > path to say go one folder back and open index.html
> >
> > f = open( '../' + page )
> >
> > How to say the same thing in an absolute way by forcing Python to detect
> > DocumentRoot by itself?

>
> Can you give us more details of what you're doing. Is there some web
> framework you're using? Can you post some code that's not working for
> you?
> --
> http://mail.python.org/mailman/listinfo/python-list
>


Import os

Then read os.environ['HOME']

This will give you the home directory of the user. in my case:

>>> os.environ['HOME']

'/home/jcg'
>>>


This is probably linux only, but that seems to be the environment you are
working in .



--
Joel Goldstick
http://joelgoldstick.com

 
Reply With Quote
 
Ferrous Cranus
Guest
Posts: n/a
 
      01-18-2013
Τη **μπτη, 17 Ιανουαρίου 2013 5:14:19 μ.μ. UTC+2, ο χρήστης Joel Goldstick *γραψε:
> On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith <(E-Mail Removed)> wrote:
>
> In article <(E-Mail Removed)>,
>
>
>
> *Ferrous Cranus <(E-Mail Removed)> wrote:
>
>
>
> > When trying to open an html template within Python script i use a relative

>
> > path to say go one folder back and open index.html

>
> >

>
> > f = open( '../' + page )

>
> >

>
> > How to say the same thing in an absolute way by forcing Python to detect

>
> > DocumentRoot by itself?

>
>
>
> Can you give us more details of what you're doing. *Is there some web
>
> framework you're using? *Can you post some code that's not working for
>
> you?
>
> --
>
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
> Import os
>
> Then read os.environ['HOME']
>
>
> This will give you the home directory of the user.* in my case:
>
>
> >>> os.environ['HOME']

> '/home/jcg'
> >>>

>
>
> This is probably linux only, but that seems to be the environment you areworking in .


Yes my Python scripts exist in a linux web host.

os.environ['HOME'] will indeed give the home directory of the user.

to me /home/nikos/

but i want a variable to point to

/home/nikos/public_html whice is called DocumentRoot.

is there avariable for that? i can't seem to find any...
 
Reply With Quote
 
Ferrous Cranus
Guest
Posts: n/a
 
      01-18-2013
Τη **μπτη, 17 Ιανουαρίου 2013 5:14:19 μ.μ. UTC+2, ο χρήστης Joel Goldstick *γραψε:
> On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith <(E-Mail Removed)> wrote:
>
> In article <(E-Mail Removed)>,
>
>
>
> *Ferrous Cranus <(E-Mail Removed)> wrote:
>
>
>
> > When trying to open an html template within Python script i use a relative

>
> > path to say go one folder back and open index.html

>
> >

>
> > f = open( '../' + page )

>
> >

>
> > How to say the same thing in an absolute way by forcing Python to detect

>
> > DocumentRoot by itself?

>
>
>
> Can you give us more details of what you're doing. *Is there some web
>
> framework you're using? *Can you post some code that's not working for
>
> you?
>
> --
>
> http://mail.python.org/mailman/listinfo/python-list
>
>
>
> Import os
>
> Then read os.environ['HOME']
>
>
> This will give you the home directory of the user.* in my case:
>
>
> >>> os.environ['HOME']

> '/home/jcg'
> >>>

>
>
> This is probably linux only, but that seems to be the environment you areworking in .


Yes my Python scripts exist in a linux web host.

os.environ['HOME'] will indeed give the home directory of the user.

to me /home/nikos/

but i want a variable to point to

/home/nikos/public_html whice is called DocumentRoot.

is there avariable for that? i can't seem to find any...
 
Reply With Quote
 
Joel Goldstick
Guest
Posts: n/a
 
      01-18-2013
On Fri, Jan 18, 2013 at 8:02 AM, Ferrous Cranus <(E-Mail Removed)>wrote:

> Τη **μπτη, 17 Ιανουαρίου 2013 5:14:19 μ.μ. UTC+2, ο χρήστης Joel Goldstick
> *γραψε:
> > On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith <(E-Mail Removed)> wrote:
> >
> > In article <(E-Mail Removed)>,
> >
> >
> >
> > Ferrous Cranus <(E-Mail Removed)> wrote:
> >
> >
> >
> > > When trying to open an html template within Python script i use a

> relative
> >
> > > path to say go one folder back and open index.html

> >
> > >

> >
> > > f = open( '../' + page )

> >
> > >

> >
> > > How to say the same thing in an absolute way by forcing Python to

> detect
> >
> > > DocumentRoot by itself?

> >
> >
> >
> > Can you give us more details of what you're doing. Is there some web
> >
> > framework you're using? Can you post some code that's not working for
> >
> > you?
> >
> > --
> >
> > http://mail.python.org/mailman/listinfo/python-list
> >
> >
> >
> > Import os
> >
> > Then read os.environ['HOME']
> >
> >
> > This will give you the home directory of the user. in my case:
> >
> >
> > >>> os.environ['HOME']

> > '/home/jcg'
> > >>>

> >
> >
> > This is probably linux only, but that seems to be the environment you

> are working in .
>
> Yes my Python scripts exist in a linux web host.
>
> os.environ['HOME'] will indeed give the home directory of the user.
>
> to me /home/nikos/
>
> but i want a variable to point to
>
> /home/nikos/public_html whice is called DocumentRoot.
>
> is there avariable for that? i can't seem to find any...
> --
> http://mail.python.org/mailman/listinfo/python-list
>



DocumentRoot = os.environ['HOME'] + 'public_html'
--
Joel Goldstick
http://joelgoldstick.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python statements not forcing whitespace is messy? buffi Python 14 09-17-2007 05:35 AM
forcing one connection Blacklab Wireless Networking 5 10-08-2005 01:21 AM
Forcing password manager to save usernames/passwords for secure sites Jim Firefox 1 05-08-2005 12:04 PM
Forcing links to open in tab instead of new window? fety Firefox 7 03-04-2005 08:34 AM
Forcing native 802.1x supplicant to re-auth??! Tony Wireless Networking 3 07-07-2004 11:35 PM



Advertisments