Roger Binns wrote:
...
Robin Dunn wrote:
Also, if it's not an english version of Windows then it won't be
spelled "My Documents" even if it is in the USERPROFILE location. The proper way to find it is to get the value from the registry, but
I don't know the location off the top of my head...
There is only one correct way to get the path, and using environment
variables is not correct, nor is using the registry. The amusing
history behind that is at:
Correct, way to get it, true. Available with core Python, no .
Still, good to read the logic laid out in full as a history.
For applications programmers, it's fine to say 'well, I'll include win32all in my application' for doing this, but library programmers need to be able to deal with a missing dependency (especially when the dependency is such a large package and would only be used for this one function). You'll note that the OpenGLContext module uses the correct method *if possible*, and only degrades to using the registry if the shell-folder functions aren't available.
The proper way to deal with this, of course, is, I suppose, something similar to the _winreg module in Python, i.e. a very small DLL that provides just the "get shell folder" functions (but have one for all platforms). Until that happens, I'd be inclined to have the backup code available. After all, if it fails, you're no worse off than before (since you don't have the shell functions, and much as they whine about it , Microsoft will continue to support those common registry entries because their bread-and-butter is backwards compatibility), but if it succeeds, your library can continue to function as expected. Yes, yes, I know "refuse the temptation to guess", but "practicality beats purity".
Though come to think of it, OpenGLContext could probably use even more guarding for cases where _winreg is available but not the keys (thanks for reminding me about that). Maybe could use a ctypes version of the shell-folder code as well, just to provide "opportunistic" success as much as possible.
Enjoy yourselves,
Mike
···
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com