473,287 Members | 1,709 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,287 software developers and data experts.

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

Nov 2 '07 #1
4 6965
En Thu, 01 Nov 2007 22:51:14 -0300, Giampaolo Rodola' <gn****@gmail.com>
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(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?
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(os.path.dirname(path) ), result)

--
Gabriel Genellina

Nov 2 '07 #2
Giampaolo Rodola' <gn****@gmail.comwrote:
>
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(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.arwrote:
En Thu, 01 Nov 2007 22:51:14 -0300, Giampaolo Rodola' <gne...@gmail.com
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(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?

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(os.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.com>
escribió:
On 2 Nov, 05:30, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
>En Thu, 01 Nov 2007 22:51:14 -0300, Giampaolo Rodola' <gne...@gmail.com>
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
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...
9
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...
11
by: JKop | last post by:
AnyClass Blah() { AnyClass poo; return poo; } As we all know, in the above, the compiler is entitled to:
9
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...
17
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: ...
8
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...
4
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...
8
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...
2
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.