473,401 Members | 2,068 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,401 software developers and data experts.

Finding the relative path of a file from a dir

Hi,
a = '/home/suresh/doc/html/a1/'
b = '/home/suresh/doc/'

I am looking for a standard function which will return the location of b
relative to a i.e. '../..'

I have gone through the os and os.path modules, but could not find any
function of use. Should I write my own?

Thanks in advance,
Suresh
Jan 20 '06 #1
4 4160
Suresh Jeevanandam wrote:
a = '/home/suresh/doc/html/a1/'
b = '/home/suresh/doc/'

I am looking for a standard function which will return the location of b
relative to a i.e. '../..'

I have gone through the os and os.path modules, but could not find any
function of use. Should I write my own?


Don't write your own. This is yet another thing that Jason Orendorff's
path.py module can do easily:
from path import path
b = path('/users/peter/')
a = path('/users/peter/synergy/tiki.txt')
a.relpathto(b)

path(u'..\\..')

-Peter

Jan 20 '06 #3
Suresh Jeevanandam wrote:
Hi,
a = '/home/suresh/doc/html/a1/'
b = '/home/suresh/doc/'

I am looking for a standard function which will return the location of b
relative to a i.e. '../..'


Jason Orendorff's path module has a method for this (relpathto()).
http://www.jorendorff.com/articles/p...ath/index.html

Kent
Jan 20 '06 #4
pathutils has a function to do this (actually extracted from the path
module).

http://www.voidspace.org.uk/python/pathutils.html

All the best,

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

Jan 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...
4
by: Hal Vaughan | last post by:
I want to have a config file for my program, which means I need to know where the config file is. If I type: java myclass and it runs myclass.class, is there any way to obtain the location of...
11
by: Fuzzyman | last post by:
What's the best, cross platform, way of finding out the directory a script is run from ? I've googled a bit, but can't get a clear answer. On sys.argv the docs say : argv is the script name...
7
by: Rizaan Jappie | last post by:
is it possible to get the relative path based on a absolute path in c#? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
6
by: openleren | last post by:
Hi all, how can I use a relative path in my web.config file for an Access db?: Instead of using <configuration> <appSettings> <add key="conAccess" value="microsoft.jet.oledb.4.0;data...
18
by: Nak | last post by:
Hi there, Does anyone know what path the AssemblyKeyFile attribute is relative to? For example I currently have mine set to <Assembly: AssemblyKeyFile("..\NicksKey.snk")> Sometimes this...
1
by: metaperl.etc | last post by:
In this traceback, the path to 3 different SQL Alchemy source files is a relative directory. However, no such directory is below my current working directory. This is problematic for two...
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...
1
by: =?Utf-8?B?Sm9hY2hpbQ==?= | last post by:
I have a piece of code that looks like this: XPathNavigator l_nav = xml_document.DocumentElement.CreateNavigator(); XslCompiledTransform l_xslt = new XslCompiledTransform();...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.