strange interaction between open and cwd
Baz Walter
bazwal at ftml.net
Mon May 3 14:10:53 EDT 2010
On 03/05/10 19:05, Chris Rebert wrote:
> On Mon, May 3, 2010 at 10:45 AM, Baz Walter<bazwal at ftml.net> wrote:
>> On 03/05/10 18:12, Grant Edwards wrote:
>>> On 2010-05-03, Baz Walter<bazwal at ftml.net> wrote:
>>>>> Sort of. The file in question _has_ a full path, you just can't tell
>>>>> what it is based on the path you used to open it.
>>>>
>>>> yes, that's exactly what i was trying to demonstrate in my OP. i can
>>>> use python to open a file; but under certain circumstances, there
>>>> seems to be no guarantee that i can then use python to locate that
>>>> file in the filesystem.
>>>
>>> Exactly.
>>>
>>> In your example, it's simply not possible to determine the file's
>>> absolute path within the filesystem given the relative path you
>>> provided.
>>>
>>> You requested something that wasn't possible. It failed. What do you
>>> think should have happened?
>>
>> path = '../abc.txt'
>>
>> os.path.realpath(path) -> "OSError: [Errno 2] No such file or directory"
>>
>> therefore:
>>
>> open(path) -> "IOError: [Errno 2] No such file or directory"
>>
>> i think that if the first of these seemingly "impossible" requests fails, it
>> is reasonable to expect that the second one also fails. but the second one
>> (sometimes) doesn't.
>>
>> i think they should always either both succeed, or both fail.
>
> Well, that's Unix and Worse-is-Better[1] for ya. Inelegant
> theoretically, but probably makes some bit of the OS's job slightly
> easier and is usually good enough in practice. Pragmatism is a bitch
> sometimes. :-)
yeah, i probably should have added "in an ideal world" or something :)
More information about the Python-list
mailing list