1

I would like to call os.environ['UserProfile'] on my windows system. The value may be unicode, however the os.environ dict returns str types only, with non-ascii chars converted to question marks.

>>> os.environ['UserProfile']
'C:\\Users\\????'

How can I get the correct path of UserProfile under Windows?

  • I'm using Python 2.7.3
  • I'm working on Windows 7, but solution must work also on XP, Vista and 8.
iTayb
  • 12,373
  • 24
  • 81
  • 135
  • 1
    Perhaps you are looking for [How to find the real user home directory using python?](http://stackoverflow.com/q/2668909) – Martijn Pieters Feb 15 '13 at 16:53
  • How's this a duplicate? I looked at the purported duplicate, and the answers, and there's no mention of unicode. Using the alternative lookup may or may not resolve the character set issue (which I _have_ seen mentioned in other questions), but I have no way to tell from the other question. – alexis Feb 15 '13 at 22:09
  • @alexis True. I've used the `pywin32` solution there, because it happened to return a unicode output, but now that i think about it again - it's not more than a hack, and should be a proper cross-platform way to do it. – iTayb Feb 16 '13 at 07:56

0 Answers0