473,787 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

os.readlink returning value

I was reading os.readlink doc which says:

readlink( path)

Return a string representing the path to which the symbolic link
points. The result may be either an absolute or relative pathname; if
it is relative, it may be converted to an absolute pathname using
os.path.join(os .path.dirname(p ath), result). Availability: Macintosh,
Unix.

....It's not clear to me when the returning result could be absolute
and when it could be relative.
Could someone clarify this point?

Nov 2 '07 #1
4 6996
En Thu, 01 Nov 2007 22:51:14 -0300, Giampaolo Rodola' <gn****@gmail.c om>
escribió:
I was reading os.readlink doc which says:

readlink( path)

Return a string representing the path to which the symbolic link
points. The result may be either an absolute or relative pathname; if
it is relative, it may be converted to an absolute pathname using
os.path.join(os .path.dirname(p ath), result). Availability: Macintosh,
Unix.

...It's not clear to me when the returning result could be absolute
and when it could be relative.
Could someone clarify this point?
That depends on how the symlink was created. Assume the current directory
is /usr/home/giampaolo/any/dir
ln -s ../foo/bar
creates a symbolic link at /usr/home/giampaolo/any/dir/bar pointing to
.../foo/bar (relative to where the link resides). That is, actually
pointing to /usr/home/giampaolo/any/foo/bar (but this absolute path is NOT
stored on the link itself - only ../foo/bar)

Now, a program whose current directory is /usr/home/giampaolo executes
this:
readlink("any/dir/bar")
It will return the string "../foo/bar". One must resolve the .. reference
relative to where the link resides, NOT relative to the current directory.
That is, relative to any/dir. os.path.dirname ("any/dir/bar") returns
exactly that. Then, the suggested expression in the docs evaluates to
"any/dir/../foo/bar" - it's not an absolute pathname yet, one should use
abspath() on it. Or instead
os.path.join(os .path.abspath(o s.path.dirname( path)), result)

--
Gabriel Genellina

Nov 2 '07 #2
Giampaolo Rodola' <gn****@gmail.c omwrote:
>
I was reading os.readlink doc which says:

readlink( path)

Return a string representing the path to which the symbolic link
points. The result may be either an absolute or relative pathname; if
it is relative, it may be converted to an absolute pathname using
os.path.join(o s.path.dirname( path), result). Availability: Macintosh,
Unix.

...It's not clear to me when the returning result could be absolute
and when it could be relative.
Could someone clarify this point?
It will be relative if the symbolic link is relative, and absolute if the
symbolic link is absolute.

ln -s ../../over/there here1
ln -s /home/timr/spot here2

"here1" is a relative link. "here2" is an absolute link.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Nov 2 '07 #3
On 2 Nov, 05:30, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
En Thu, 01 Nov 2007 22:51:14 -0300, Giampaolo Rodola' <gne...@gmail.c om
escribió:
I was reading os.readlink doc which says:
readlink( path)
Return a string representing the path to which the symbolic link
points. The result may be either an absolute or relative pathname; if
it is relative, it may be converted to an absolute pathname using
os.path.join(os .path.dirname(p ath), result). Availability: Macintosh,
Unix.
...It's not clear to me when the returning result could be absolute
and when it could be relative.
Could someone clarify this point?

That depends on how the symlink was created. Assume the current directory
is /usr/home/giampaolo/any/dirln -s ../foo/bar

creates a symbolic link at /usr/home/giampaolo/any/dir/bar pointing to
../foo/bar (relative to where the link resides). That is, actually
pointing to /usr/home/giampaolo/any/foo/bar (but this absolute path is NOT
stored on the link itself - only ../foo/bar)

Now, a program whose current directory is /usr/home/giampaolo executes
this:
readlink("any/dir/bar")
It will return the string "../foo/bar". One must resolve the .. reference
relative to where the link resides, NOT relative to the current directory..
That is, relative to any/dir. os.path.dirname ("any/dir/bar") returns
exactly that. Then, the suggested expression in the docs evaluates to
"any/dir/../foo/bar" - it's not an absolute pathname yet, one should use
abspath() on it. Or instead
os.path.join(os .path.abspath(o s.path.dirname( path)), result)

--
Gabriel Genellina
Thanks for the examplanation.
I'd only want to do the same as what ls does in such cases.
Imho, os.readlink() should have the same behaviour of ls, isn't it?

Nov 2 '07 #4
En Fri, 02 Nov 2007 13:44:37 -0300, Giampaolo Rodola' <gn****@gmail.c om>
escribió:
On 2 Nov, 05:30, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
>En Thu, 01 Nov 2007 22:51:14 -0300, Giampaolo Rodola' <gne...@gmail.c om>
escribió:
readlink( path)
...It's not clear to me when the returning result could be absolute
and when it could be relative.

That depends on how the symlink was created. Assume the current
I'd only want to do the same as what ls does in such cases.
Imho, os.readlink() should have the same behaviour of ls, isn't it?
Yes; os.readlink shows the same as ls -l

--
Gabriel Genellina

Nov 3 '07 #5

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

Similar topics

2
2922
by: Mountain Man | last post by:
Hi, I'm having trouble with the foreach function. I'm using it twice inside a user defined function with two different arrays, and in the second instance it's returning the value of the first key for all the keys. My code is shown below and the problem areas are marked with comments. In case you're wondering, this script is for generating sticky checkboxes that include an event handler. Many thanks to anyone who can help.
9
11917
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is up to which size m would you expect vector<double> returns_by_value() {
11
1946
by: JKop | last post by:
AnyClass Blah() { AnyClass poo; return poo; } As we all know, in the above, the compiler is entitled to:
9
5214
by: Thomas Mlynarczyk | last post by:
Hi, It seems to be a generally adopted convention to have a function return FALSE in case of an error. But if a function is supposed to return a boolean anyway, one cannot distinguish anymore between the "normal" FALSE and the "error" FALSE. So why not using NULL instead to indicate an error? Are there drawbacks I am not aware of? Greetings, Thomas
17
3265
by: I.M. !Knuth | last post by:
Hi. I'm more-or-less a C newbie. I thought I had pointers under control until I started goofing around with this: ================================================================================ /* A function that returns a pointer-of-arrays to the calling function. */ #include <stdio.h> int *pfunc(void);
8
2207
by: sam | last post by:
i am starting to experiment with recursion, and decided to write a fairly trivial little program which took a float as input, then called a function to halve it recursively until it was less than 1: ____________________________________________________________________ import recursive_halve_module raw_value = raw_input('please enter the number you would like to halve: ') value = float(raw_value)
4
4363
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier Architecture. The Stored Procedures are used through TableAdaptors, which in turn are used by Class Files. I wish to be able to return this new ID value using the Stored
8
2744
by: Michal Nazarewicz | last post by:
Hi, What does returning 0 from main() mean according to C89/C90 standard? I've found that in C99 it means successful termination (7.20.4.3p5) however as I'm editing book on C at Polish Wikibooks I'd like to know what C89/C90 says about it - quotation from C89 or C90 would be nice. Moreover, in C99 main() function is somewhat special because lack of return statement is equivalent with returning zero (5.1.2.2.3p1). Is it also the case...
2
1730
by: JBW | last post by:
English is my first language, but I doesn't be very good at it. I was trying to endow my symlinked python module with the ability to divine where it actually resides when I came across os.readlink(), documented at http://docs.python.org/lib/os-file-dir.html I'm not sure readlink() lives up to its documentation. To wit: $ touch bar # Create an empty file $ ln -s bar foo # And a symlink to it.
0
10363
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.