473,387 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Relative paths in mod_python

I was wondering if I could use relative paths in a mod_python script. At
the moment I am defining a constant string
"/path/to/dir/where/script/resides". The problem with this is that when
I move the script including files I use to get metadata I have to change
this variable. The same problem occurs when I distribute the script; the
person using it will first have to modify it, which is not what I want. Is
it possible that a mod_python script has as current working directory
the directory where the script resides? At the moment os.getcwd()
returns '/'.
Mar 19 '06 #1
4 2145
Ivo van der Sangen wrote:
I was wondering if I could use relative paths in a mod_python script. At
the moment I am defining a constant string
"/path/to/dir/where/script/resides".
[snip]


You can use Python's built-in __file__ variable. It is set to the absolute
location of your script. You can then use one of the built-in functions in
the `os' module (I forgot which) to extract the directory your script
resides.

Jochem.

--
E-mail address encrypted using ROT13.
Mar 19 '06 #2
Ivo van der Sangen a écrit :
I was wondering if I could use relative paths in a mod_python script. At
the moment I am defining a constant string
"/path/to/dir/where/script/resides". The problem with this is that when
I move the script including files I use to get metadata I have to change
this variable. The same problem occurs when I distribute the script; the
person using it will first have to modify it, which is not what I want. Is
it possible that a mod_python script has as current working directory
the directory where the script resides? At the moment os.getcwd()
returns '/'.


You could set this constant in the apache conf as a PythonOption. And/Or
you could post this question to mod_python's mailing list !-)
Mar 19 '06 #3
Ivo van der Sangen wrote:
I was wondering if I could use relative paths in a mod_python script. At
the moment I am defining a constant string
"/path/to/dir/where/script/resides". The problem with this is that when
I move the script including files I use to get metadata I have to change
this variable. The same problem occurs when I distribute the script; the
person using it will first have to modify it, which is not what I want. Is
it possible that a mod_python script has as current working directory
the directory where the script resides? At the moment os.getcwd()
returns '/'.


import os
req.write(os.path.abspath(__file__))

seems to give you the absolute path to the module you are executing. You
can use the other os.path primitives to extract the directory from that
and use it to locate the associated data files.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

Mar 19 '06 #4
On 2006-03-19, Bruno Desthuilliers <bd*****************@free.quelquepart.fr>
wrote:
Ivo van der Sangen a écrit :
I was wondering if I could use relative paths in a mod_python script. At
the moment I am defining a constant string
"/path/to/dir/where/script/resides". The problem with this is that when
I move the script including files I use to get metadata I have to change
this variable. The same problem occurs when I distribute the script; the
person using it will first have to modify it, which is not what I want. Is
it possible that a mod_python script has as current working directory
the directory where the script resides? At the moment os.getcwd()
returns '/'.


You could set this constant in the apache conf as a PythonOption. And/Or
you could post this question to mod_python's mailing list !-)


I wasn't aware of the mod_python list. The next time I will post my
question there, but I don't think I will get a better answer there; the
solutions given here so far are fine.
Mar 20 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Doug | last post by:
If I were to write an include with a relative path like include("../conf/config.php"); What is the use? As far as I understand it, the path is relative to the first script that is called by...
7
by: mark | last post by:
I am designing a website at the moment and looking at the difference between relative and absolute url links which is driving me crazy! I would like to use relative paths, but it is proving very...
5
by: jason | last post by:
Can anyone help me find a solution to quickly working out relative paths to a folder in the root of my server... Although it easy when you go - say - two levels down: .../includes it...
2
by: Joe | last post by:
Hi, can someone tell me how to set up relativ paths in VS2003 C++ ? I have some source with a tree directory structure that segments include files in various directories: #include...
2
by: Alex | last post by:
Hi. I need some help on this. I have a user control (a header) in my root directory, and all my pages use that control. Then a created a folder (in my root directory) and put a new page inside it,...
8
by: JJ | last post by:
I'm confused about paths. I have a functionn that uses the mappath method, which I think requires a virtual path (is that the same as a relative path?). But this doesn't always work as the...
15
by: Lars Eighner | last post by:
Aside from the deaths of a few extra electrons to spell out the whole root relative path, is there any down side? It seems to me that theoretically it shouldn't make any difference, and it would...
2
by: BD | last post by:
Hi there. Using 8.2 on Windows. I have a situation where I have a db backup, which I want to deploy to a group of developer workstations. The target directory for the database files will be...
2
by: Peted | last post by:
Hi i have a circumstance where a user unzips a file, with a certain layer of directories to get to a textfile. So in any directory on the HDD they may end up with something like ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.