Discussion:
[Tutor] os.path.exists(path) returns false when the path actually exists!
Iyer
2007-07-28 02:26:30 UTC
Permalink
os.path.exists(path) returns false when the path actually exists!
os.path.exists("c:\\winnt\\file_name")
False
Actually the file exists in c:\winnt, and I can confirm it exists there, but os.path.exists isn't returning True, when it should be..

Is this a bug ?

iyer


---------------------------------
Park yourself in front of a world of choices in alternative vehicles.
Visit the Yahoo! Auto Green Center.
Iyer
2007-07-28 02:42:25 UTC
Permalink
Adam wrote:
Hugo González Monteverde
2007-07-28 07:56:07 UTC
Permalink
Tiger12506
2007-07-28 15:33:36 UTC
Permalink
Thorsten Kampe
2007-07-28 09:57:49 UTC
Permalink
* Tiger12506 (Sat, 28 Jul 2007 10:33:36 -0500)
Post by Adam A. Zajac
So the better question is, does is this file a broken symbolic link or
can os.stat() be executed on it?
How do I find if it is a broken symbolic link in Windows 2000 ?
os.stat(path) returns an OSError saying that there is no such file or
directory
Wow. I've never heard of this. What are the file's attributes? What does it
say about the file when you right-click Properties? Hmmm... what's going on
here? Permission not granted to execute os.stat()? Why wouldn't anyone have
permission to do that?
A broken symbolic link... That means a hard link that has been cut-off
right?
No, symbolic links and hard links are totally different.
(Hard-links are like pointers to files in NTFS) ~ so if the file's
been moved, that hard link will point to nothing, being broken, right?
Thre are no "broken hard links"...
Adam A. Zajac
2007-07-28 02:35:41 UTC
Permalink
Post by Iyer
os.path.exists(path) returns false when the path actually exists!
os.path.exists("c:\\winnt\\file_name")
False
Actually the file exists in c:\winnt, and I can confirm it exists
there, but os.path.exists isn't returning True, when it should be..
Is this a bug ?
From the library documentation:
Return True if path refers to an existing path. Returns False for
broken symbolic links. On some platforms, this function may return
False if permission is not granted to execute os.stat() on the
requested file, even if the path physically exists.

So the better question is, does is this file a broken symbolic link or
can os.stat() be executed on it?
Iyer
2007-07-31 00:00:42 UTC
Permalink
Just to check, try to do away with the backslashes. Windows will accept
a path with forward slashes just as well:

os.path.exists("c:/winnt/file_name")

Nope, even, with the use of forward slashes in the path, it still returns false

What am I doing wrong here ?

This is driving me nuts!

-iyer


---------------------------------
Looking for a deal? Find great prices on flights and hotels with Yahoo! FareChase.
Tiger12506
2007-07-31 01:15:18 UTC
Permalink
Post by Iyer
Just to check, try to do away with the backslashes. Windows will accept
os.path.exists("c:/winnt/file_name")
Nope, even, with the use of forward slashes in the path, it still returns false
What am I doing wrong here ?
This is driving me nuts!
Not trying to insult you, but you do realize that Windows sometimes hides
file extensions right? I would assume you know that if you are in this deep,
but it's better to rule out all the possibilities before doing something
drastic like taking an axe to your computer. ;-)

For example.
mine.txt

os.path.exists("c:/winnt/mine")
False
os.path.exists("c:/winnt/mine.txt")
True

JS
John Fouhy
2007-07-31 00:58:34 UTC
Permalink
Post by Iyer
os.path.exists("c:/winnt/file_name")
Nope, even, with the use of forward slashes in the path, it still returns false
What am I doing wrong here ?
Type 'os.listdir("c:/winnt")' and see what it gives you. I haven't
looked at the code, but I presume 'os.path.exists(s)' is roughly
equivalent to 'os.path.split(s)[1] in
os.listdir(os.path.split(s)[0])'.
--
John.
Bob Gailer
2007-07-31 01:45:13 UTC
Permalink
Post by Iyer
Just to check, try to do away with the backslashes. Windows will accept
os.path.exists("c:/winnt/file_name")
Nope, even, with the use of forward slashes in the path, it still returns false
What am I doing wrong here ?
Is there any chance the file has an extension that Windows is hiding?

Can you get True for other files in the folder?
--
Bob Gailer
510-978-4454 Oakland, CA
919-636-4239 Chapel Hill, NC
Iyer
2007-08-02 05:55:08 UTC
Permalink
Is there any chance the file has an extension that Windows is hiding?

Can you get True for other files in the folder?


So, it was the extensions all the way ! Apparently the file extension was hidden by Windows! It now works.

Thank you all for your suggestions and help.

-iyer


---------------------------------
Shape Yahoo! in your own image. Join our Network Research Panel today!
Bob Gailer
2007-08-02 17:12:47 UTC
Permalink
Post by Iyer
So, it was the extensions all the way ! Apparently the file extension
was hidden by Windows! It now works.
I have never understood Microsoft changing things from one release to
another. In the beginning extensions were IIRC always visible.

Every time I configure a computer I have to spend a lot of time undoing
the initial settings so my users can get their work done!
--
Bob Gailer
510-978-4454 Oakland, CA
919-636-4239 Chapel Hill, NC
Tiger12506
2007-08-02 19:49:15 UTC
Permalink
Post by Bob Gailer
I have never understood Microsoft changing things from one release to
another. In the beginning extensions were IIRC always visible.
Every time I configure a computer I have to spend a lot of time undoing
the initial settings so my users can get their work done!
Even though I completely agree with you and detest Microsoft's decisions in
these matters, here are the basic reasons:

Computers are becoming more and more available for use amongst
non-tech-savy individuals. Individuals who previously did not have to work
with computers may now have to use them in their job for whatever reason.
Microsoft would make less money if so called non-user-friendly attributes
remained in their operating system. Consider:

A potential computer user looks at the listing in a folder. Not quite
understanding why things look the way they do, not quite understanding how
these so called folders and files are supposed to look like the old paper
file cabinet systems that they are used to.

He sees these files with periods and strange letters. What do they mean? A
file extension? What?! I don't get it, he says. You explain that the letters
tell Windows which program is supposed to open the file. That doesn't make
sense to him. He wonders why Windows can't just see that this is a
spreadsheet, I mean look at it. It's obviously a spreadsheet! So to
circumvent this confusion they hide the file extensions.

Consider some other UI changes. The places bar, for example. Most programs
save documents in My Documents. So where is it? Most people don't realize
where they are. The file cabinets that they knew had folders yes, but never
folders within folders. So Microsoft, in order to aid the new computer user
provided a flattened view so that they could more easily find and understand
where they are.

Granted, all of these are just visual sugar and are completely worthless.
But they have provided Microsoft with much money because more useless people
can use computers. It is because these people do not wish to learn, do not
have the capacity, or just plain would rather pay through their teeth. They
would rather have Microsoft make obfuscate things, to make it "easier" for
them, than to try to understand themselves.

JS
Kyle Brooks
2007-08-02 19:10:54 UTC
Permalink
Hi.
Post by Tiger12506
Granted, all of these are just visual sugar and are completely worthless.
But they have provided Microsoft with much money because more useless people
can use computers. It is because these people do not wish to learn, do not
have the capacity, or just plain would rather pay through their teeth. They
would rather have Microsoft make obfuscate things, to make it "easier" for
them, than to try to understand themselves.
JS
Why are you making out people and Microsoft in such a negative way?
Also, how is it "harder" for them when things like file extensions are
obfuscated?

- Kyle
Alan Gauld
2007-08-02 19:53:45 UTC
Permalink
Post by Kyle Brooks
Post by Tiger12506
would rather have Microsoft make obfuscate things, to make it
"easier" for
them, than to try to understand themselves.
Why are you making out people and Microsoft in such a negative way?
JS is reflecting a commonly held view of Microsoft and their
"contribution"
to computing among the computing community who do not use Microsoft!
I agree it is a little harsh since Microsoft are following a publickly
declared
policy to bring a PC to every home, but...
Post by Kyle Brooks
Also, how is it "harder" for them when things like file extensions are
obfuscated?
Its harder in the sense that by dumbing down the user experience
they are making Windows less predictable to use. As was seen in
this thread when a filename turned out to be bogus because there
was really an extension attached.

MS have brought this particular "problem" on themselves by insisting
on using file extensions to associate files with applications, in fact
this
is not necessary and Unix, for example, can associate files with apps
even with no extension. The technology to do that has been there for
at least 30 years but MS persist on using their own brain-dead scheme
and then trying to "fix" it for the user by hiding bits of the name.

Its a bad solution to a problem which should not exist in the first
place.
The OS should not need to use extensions, and then the users could
name the files as intuitively as they liked. I have no problem with
non techie users not liking extensions, but Microsoft should have
done a better fix. But Microsoft do not have a good track record of
adopting good ideas from elsewhere. They are very much a "Not Invented
Here" type of company and that is bad for users and bad for the
industry
because MS nearly always introiduce inferior alternatives to existing
technologies and use their marketing dominance to force them into
wide use. Leaving poor programmers like us to work with multiple
standards and the users having to deal with incompatible applications
and computers.

Microsoft like to portray themselves as a leading light of computer
development when in fact their contribution has been minimal and
frequently negative. The only positive contributions I can think
of offhand are the ergonomic keyboard (is it really an improvement?)
and the scroll-wheel control in mice (I think most accept it as a good
idea). But in software(*) and OS their added value is mostly marketing
hype!

I hope that explains some of the hostility often expressed by
programmers towards Micro$oft.

(*) Actually it could be argued that their early advocacy of Component
Based
software (ie COM) being superior to OOP based software has proved
to be correct, but there are plenty who would disagree, or at least
contend that they are complementary and not competing technologies.
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
Tiger12506
2007-08-02 21:50:26 UTC
Permalink
Post by Kyle Brooks
Post by Tiger12506
Granted, all of these are just visual sugar and are completely worthless.
But they have provided Microsoft with much money because more useless people
can use computers. It is because these people do not wish to learn, do not
have the capacity, or just plain would rather pay through their teeth. They
would rather have Microsoft make obfuscate things, to make it "easier" for
them, than to try to understand themselves.
JS
Why are you making out people and Microsoft in such a negative way?
Also, how is it "harder" for them when things like file extensions are
obfuscated?
They would rather have Microsoft obfuscate things, to make it "easier" for
*the people* not Microsoft.
Why am I being negative about it? Very simply:

The necessary code and provisions it takes to implement UI devices like
Hiding file extensions is a waste of space, time, resources, and too many
other things to count. Windows Vista is the newest OS out from Microsoft.
One look at the size of the installation should be enough to tell anyone
that enough is enough.

Another problem I have with Windows is the paradigm "There are only 500,000
ways to do it." For example, you can change network adapter configuration by
going to Control Panel, by using the SysTray icon, by using the StartMenu
shortcut, by navigating to the program itself, by using Device Manager, add
especially dangerous - indirectly by using the network setup wizard, etc.
All of these routes waste space, and only provide minimal advantage, but
manage to provide serious breaches of understanding. I know I am not the
only one who has tried to find why a network adapter doesn't work, only to
find that an important setting was comprimised when running one of the handy
"It does everything!" UIs.

I don't know if you are one of those people that loves those all-in-one
screwdrivers, but I find that pieces of them get lost, they are bulky, and
when it comes right down to it, all I want to do is use the simple, light,
and specialised screwdrivers. Why? Because they are faster, stronger, and
more stable. Is that good enough?

Why am I upset with people? Because they want "ease of use", I must buy
bigger hard drives, and more ram. Because Microsoft has determined that
media is more important to the mass population than performance, I have to
fight to get my Windows installation to stop initiating the time-consuming
Autoplay feature, or I have to jump through hoops to cut off the Windows
Messenger just because I don't want to use it. Or I have to search through
numerous wizards and settings to try to find where I can shut-up Windows
Update. Yes, maybe I want it to update, but I don't want it to bother me! I
have work to do. No I don't need "troubleshooting help". Give me a damn RFC.
No, there is no big massive error, I just need to find where my program is
using an invalid pointer. Why can't these changes be something useful? A
great example. Such and such module is linked to missing export such and
such. Okay. But you are preventing me from using the program! The Windows
Loader provides API addresses at load time anyway, so why isn't there an
option to redirect the API? It would take a hell of a lot less resource
space than implementing some of the visual junk that makes "managing media"
"so easy".

I apologize for my bringing up these beliefs on this list. They are better
placed in a blog somewhere, or more efficiently, in a zip file of ASCII text
as small and as neat as possible.

JS
Kent Johnson
2007-08-02 21:57:28 UTC
Permalink
Post by Tiger12506
I apologize for my bringing up these beliefs on this list. They are better
placed in a blog somewhere, or more efficiently, in a zip file of ASCII text
as small and as neat as possible.
Yes, thanks. Could we stop the Microsoft bashing - or whatever you want
to call it - please? There are plenty of other places for such discussions.

Thanks,
Kent
Terry Carroll
2007-08-02 19:43:02 UTC
Permalink
Post by Tiger12506
But they have provided Microsoft with much money because more useless
people can use computers.
That's a little harsh, isn't it? A person using a computer is not useless
by virtue of not wanting to program or understand technical details, but
rather just wanting to use it for its functional purpose. There are
people in my Finance department who know much more about finance than I
do, and more, I suspect, than you do. They are very useful to me and my
employer by virtue of that knowledge, and if some of them don't know
about Microsoft Windows file extension, well, quite frankly, who cares?
They know what's important.

I don't want to have to know the details of what makes my car run. All I
want to do is drive it from one location to another.
Post by Tiger12506
It is because these people do not wish to learn, do not have the
capacity,
Why should they have to learn? They just want to use the spreadsheet, for
example. Why should they have to learn that the magic sequence of ".XLS",
when appended to a file name, make the file work a certain way? In most
contexts, the name of a thing does not determine how it works. The name
is just a name.

I suppose I could have a television that would require me to know to tune
it to a frequency of about 69Mhz to watch a particular program; but it's
just so much more convenient to me to turn to channel 4. I see that
hiding of the technical details as an improvement, not a hindrance.

Why should people adapt themselves to software instead of having the
software adapt to them? I'm cribbing a bit from George Bernard Shaw here,
who wrote something like, "The reasonable man adapts to the world; the
unreasonable man adapts the world to himself. Therefore, all progress
depends on the unreasonable man."
Tiger12506
2007-08-02 22:35:21 UTC
Permalink
Post by Terry Carroll
Post by Tiger12506
But they have provided Microsoft with much money because more useless
people can use computers.
That's a little harsh, isn't it? A person using a computer is not useless
by virtue of not wanting to program or understand technical details, but
rather just wanting to use it for its functional purpose. There are
people in my Finance department who know much more about finance than I
do, and more, I suspect, than you do. They are very useful to me and my
employer by virtue of that knowledge, and if some of them don't know
about Microsoft Windows file extension, well, quite frankly, who cares?
They know what's important.
Very well.
Post by Terry Carroll
I don't want to have to know the details of what makes my car run. All I
want to do is drive it from one location to another.
And one day your car doesn't start. So you blindly take it to a car mechanic
(or even the dealership~shudder) where they hook it up to a battery charger,
send it back and charge you $300. Right. Not important to you. I wish I
could throw away that kind of security.
Post by Terry Carroll
Post by Tiger12506
It is because these people do not wish to learn, do not have the
capacity,
Why should they have to learn? They just want to use the spreadsheet, for
example. Why should they have to learn that the magic sequence of ".XLS",
when appended to a file name, make the file work a certain way? In most
contexts, the name of a thing does not determine how it works. The name
is just a name.
Why? Because it's a good idea. The name of the thing does not determine how
it works. But it does determine how it works in Windows. I do not expect
them to understand *why* the magic sequence of .xls causing this file to
open in Excel. I expect them to overlook it. I expect them to accept them. I
do not think it's appropriate that Microsoft should baby them by hiding the
extensions by default.
Post by Terry Carroll
I suppose I could have a television that would require me to know to tune
it to a frequency of about 69Mhz to watch a particular program; but it's
just so much more convenient to me to turn to channel 4. I see that
hiding of the technical details as an improvement, not a hindrance.
Did I say I wanted people to know just what extension is what? Did I say
that they have to parse the .xls file for Excel? No. I ask that they learn
to accept it. Just like I would ask them to accept a slip of paper taped to
the TV that lists all of the frequencies mapped to the channels. I would not
ask them to use the table of frequencies to tune the TV. They may use the
channels. But the table would be there, visible, not hidden away where
potentially someone who needs it might not be able to find it.

On the other hand, do you want a neural transmitter installed in you so that
you can more easily change the channel? Hey ~ you wouldn't even have to know
which channel you want to watch. All you would have to do is know *what* you
want to watch. Wouldn't that be excellent? It's like looking all over the
living room for the TV remote because you don't know how to change the
channel using the TV.
Post by Terry Carroll
Why should people adapt themselves to software instead of having the
software adapt to them? I'm cribbing a bit from George Bernard Shaw here,
who wrote something like, "The reasonable man adapts to the world; the
unreasonable man adapts the world to himself. Therefore, all progress
depends on the unreasonable man."
Why should computer people have to adapt to user-friendly software?
Luke Paireepinart
2007-08-03 13:23:18 UTC
Permalink
Post by Tiger12506
Post by Terry Carroll
I don't want to have to know the details of what makes my car run. All I
want to do is drive it from one location to another.
And one day your car doesn't start. So you blindly take it to a car mechanic
(or even the dealership~shudder) where they hook it up to a battery charger,
send it back and charge you $300. Right. Not important to you. I wish I
could throw away that kind of security.
That's not really the same at all.
In the context of a large company, there is almost definitely
an IT staff on retainer set up to fix the computers at all times with no
cost to the individual.
So the finance people's computer breaks, and someone comes to fix it for
them.

Yes, you could argue that if the staff were trained enough, the IT
department wouldn't need to be as large, etc. etc.
but the basic fact is that there are certain people who it's not
cost-effective for companies to train to the level where they can fix
any problem that arises in their use of the computer, and it's much
cheaper to just train one guy (who can learn quickly) how to do the
repairs quickly and efficiently and then have everyone defer to him.
Post by Tiger12506
Post by Terry Carroll
Post by Tiger12506
It is because these people do not wish to learn, do not have the
capacity,
Why should they have to learn? They just want to use the spreadsheet, for
example. Why should they have to learn that the magic sequence of ".XLS",
when appended to a file name, make the file work a certain way? In most
contexts, the name of a thing does not determine how it works. The name
is just a name.
Why? Because it's a good idea. The name of the thing does not determine how
it works. But it does determine how it works in Windows. I do not expect
them to understand *why* the magic sequence of .xls causing this file to
open in Excel. I expect them to overlook it. I expect them to accept them. I
do not think it's appropriate that Microsoft should baby them by hiding the
extensions by default.
I think this is similar to the backslash thing in Windows.
First-time Windows developers get tripped up because backslashes are the
chosen escape-sequence for strings, to encode ascii values in them.
But forward-slashes could've been the escape sequence too. It's pretty
arbitrary. They used backslashes in DOS, so they continued to use them
in future versions of their OS.
Or the carriage returns. \r means return to the beginning of the line,
\n means go to the next line. So \r\n is a logical way to make a
backslash, because it goes to the next line, and returns to the
beginning (so you don't start typing off in space.) That's how Windows
does it, but *nix does it using just \n, and Mac does it using just \r.
People argue that Windows' way of doing it is worse, but really, it
makes the most sense as far as the ascii control codes go. Yes, it's a
few characters longer, but it's mostly irrelevant.
Then, for file extensions: Microsoft chose to use file extensions to
determine which program would run a given type of file.

All of these things could be considered design flaws, but the point is
that they were used in every version of Microsoft's operating system,
and thus they need to continue to be consistent, or a whole lot of
software will break.

So Microsoft realizes that a majority of their users don't need to see
the extensions. So they hide them by default in the GUI.

That doesn't mean that developers don't have access to the full
filename. Sure we do. It doesn't affect how our programs run. The
only fault is believing that the GUI is a completely accurate
representation of the filesystem. Which it's not.
You might say "OH, BUT IT SHOULD BE!"
well, when you're using a GUI file browser on a Linux system, it may not
show you the write permissions to every file and directory.
Or it may not differentiate between symbolic links and actual files.
That's because, to the extent that the GUI is used, this knowledge is
largely unnecessary. If you try to delete a file you don't have
permission to, a little popup will come up saying "Sorry, you don't have
permission to delete this file!"

As for Windows, it may be easier for people to see launching a shortcut
to 'Notepad' and then clicking 'File > Open' and choosing their file as
analogous to just double-clicking the file in their GUI. And in this
environment, this is represented by an icon of a notepad, just as the
'Notepad' shortcut is.
Do you think that the 'Notepad' shortcut should say
"%SystemRoot%\system32\notepad.exe" instead?
I think that would confuse a lot of people!

So a developer gets confused about the file path. This is an
unfortunate side-effect. But if thousands of people find the computer
more accessible in exchange for one developer getting confused and then
realizing his mistake and never making it again, well, the choice is
obviously (from a business standpoint) to hide the extension.
Post by Tiger12506
Post by Terry Carroll
I suppose I could have a television that would require me to know to tune
it to a frequency of about 69Mhz to watch a particular program; but it's
just so much more convenient to me to turn to channel 4. I see that
hiding of the technical details as an improvement, not a hindrance.
Did I say I wanted people to know just what extension is what? Did I say
that they have to parse the .xls file for Excel? No. I ask that they learn
to accept it. Just like I would ask them to accept a slip of paper taped to
the TV that lists all of the frequencies mapped to the channels. I would not
ask them to use the table of frequencies to tune the TV. They may use the
channels. But the table would be there, visible, not hidden away where
potentially someone who needs it might not be able to find it.
And should my stereo system come with a manual attached to it at all
times that details soldering transistors and an explanation of
electrical theory?
Your argument can be extended to gross extremes, and it doesn't hold up.
The interface I use to interact with my stereo, a system of knobs and
such, is what I need to know in order to get my stereo to do what I need
it to. If it breaks, maybe I go buy a service manual and fix it, or
maybe I recognize that the time it would take me to learn the
intricacies of the electronics is greater than the cost if I have a
professional fix it.
But largely, I just need to understand the interface. Not the technical
implementation.

Note that I just don't like your argument, not that I disagree with you.
Post by Tiger12506
On the other hand, do you want a neural transmitter installed in you so that
you can more easily change the channel? Hey ~ you wouldn't even have to know
which channel you want to watch. All you would have to do is know *what* you
want to watch. Wouldn't that be excellent? It's like looking all over the
living room for the TV remote because you don't know how to change the
channel using the TV.
You know, I can see a lot of people going for that. Hey, if I could
just hook directly to a computer and 'think' what I wanted to program,
and I didn't have to rapidly press a series of buttons for the computer
to understand me, I'd be all for it. (The assumption here is that it's
safe, etc.)

But that's not the issue here.
The reason you hate the extension-hiding is because it makes interacting
with the computer at a lower level than the GUI confusing to you, when
you are viewing the system at the level of the GUI.
If you view the system at the same level as you're interacting with it,
there is no issue here.

That's the key idea. You're making faulty assumptions based on a view
of the filesystem that's different from the view your program sees when
it's running. Base your view on what your program sees and there will be
no problem.
Post by Tiger12506
Post by Terry Carroll
Why should people adapt themselves to software instead of having the
software adapt to them? I'm cribbing a bit from George Bernard Shaw here,
who wrote something like, "The reasonable man adapts to the world; the
unreasonable man adapts the world to himself. Therefore, all progress
depends on the unreasonable man."
Why should computer people have to adapt to user-friendly software?
Because you (singular) program the software for them (plural.) There are
more users than developers. They are the ones who need to understand it.

Why should the computer have to be able to compile your C++ code or
interpret your Python code? Why shouldn't you have to speak to it in
machine language?
Terry's quote embodies these. The early Computer Science pioneers were
disdainful of FORTRAN. "It'll never be able to craft assembly that's
nearly as efficient as what WE write by hand." Then it turned out it
did. Then when Python came along, some C programmers were heard saying
"Ah, but it'll never run as fast as our C programs will!" But then the
world came to realize that the fact remains that the computers are
constantly increasing in speed of execution, and humans are not. So
we've reached the level where the shift occurs from increasing computing
efficiency to increasing user efficiency. And the more user-friendly
the software is, the more user-efficient the resulting interaction will be.

P.S. Why don't I ever see Linux-bashing on this list?
-Luke

Continue reading on narkive:
Loading...