On Thu, Sep 1, 2011 at 8:49 AM, Tim Golden <m...@timgolden.me.uk> wrote: > On 01/09/2011 13:39, Kevin Walzer wrote: >> >> Hi, >> I’m getting feedback from a Windows user that says my Tkinter app won’t >> write data to an app temporary directory. Here’s my code: >> sys.stderr=open(os.path.join(os.path.expanduser('~'), 'Application >> Data', 'QuickWho', 'QuickWho_errors.txt'), 'w') > > This is a little brittle. I imagine it will at least break > from non-English versions of Windows. It will also break > for versions of Python prior to 2.5? when expanduser was > expanded to include Windows. It also breaks if the user has set the HOME environment variable (not uncommon for Cygwin users) > > The simplest approach is to use the APPDATA env var which > goes back a few versions (certainly to XP, probably Win 2000). i.e., os.environ['APPDATA']
Also, 'open' will not create the 'QuickWho' directory for you. You may need: os.mkdir(os.path.join(os.environ['APPDATA'], 'QuickWho')) > > Alternatively, you can use the Windows Shell API to query the > same thing -- this should go back even further if you've got > someone using something truly prehistoric. _______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32