Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'from:addr:yahoo.co.uk': 0.05; 'subject:getting': 0.07; 'path)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'src': 0.09; 'properly': 0.15; '"set': 0.16; 'idle,': 0.16; 'open(src,': 0.16; 'quits': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'runs.': 0.16; 'subject:windows': 0.16; 'wrote:': 0.16; 'directory.': 0.18; 'thoughts': 0.18; 'language': 0.19; 'windows': 0.20; 'fix': 0.21; 'lawrence': 0.22; 'tkinter': 0.22; 'trying': 0.22; 'defined': 0.23; 'seems': 0.23; 'absolute': 0.23; 'tried': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'skip:- 40': 0.25; "i've": 0.25; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'command': 0.26; 'header:X-Complaints-To:1': 0.26; 'error': 0.27; 'moved': 0.27; 'fine': 0.28; 'dialog': 0.29; "i'm": 0.30; 'code': 0.30; 'call.': 0.30; 'users.': 0.31; 'post': 0.31; 'language.': 0.32; 'run': 0.33; 'problem': 0.33; 'message.': 0.33; 'open': 0.33; 'file': 0.34; 'trouble': 0.35; 'could': 0.35; 'saved': 0.35; 'comment': 0.35; "isn't": 0.35; 'problem.': 0.35; 'but': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:org': 0.37; 'mac': 0.37; 'doing': 0.38; "won't": 0.38; 'stuff': 0.38; 'to:addr:python.org': 0.40; 'mark': 0.40; 'ever': 0.60; 'documents': 0.61; 'show': 0.62; 'charset:windows-1252': 0.62; 'our': 0.64; 'python-list': 0.66; 'box,': 0.67; 'home': 0.67; 'click': 0.76; 'discovered': 0.83; '8.1': 0.84; 'fin': 0.84; 'mac.': 0.84; 'pythonistas,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Trouble getting to windows My Documents directory Date: Fri, 10 Jul 2015 15:47:11 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-92-24-216-60.ppp.as43234.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436539657 news.xs4all.nl 2951 [2001:888:2000:d::a6]:41332 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:93642 On 10/07/2015 15:27, Mark Storkamp via Python-list wrote: > I'm just learning Python, and I've run into trouble trying to change > directory to the windows My Documents directory. There's likely a better > way to do this, but this is what I've tried so far: > > --------------------------------------------- > from tkinter import Tk > from tkinter.filedialog import askopenfilename > > import os > > Tk().withdraw() > > sourcedir = os.environ['HOME']+"/Documents/" > os.chdir(sourcedir) > src = askopenfilename() > if src == '' : > sys.exit() > fin = open(src, mode='r') > ## do stuff > fin.close() > ----------------------------------------------- > > When this is run from IDLE, it works fine. But when I double click on > the saved file to run it, it quits without ever showing the open file > dialog box, and doesn't show any error message. > > The problem is with the os.environ['HOME'] call. If I comment it out > (and fix up the surrounding code with an absolute path) then it runs. > But then it won't work properly for other users. > > Interestingly enough, when I moved this to a Mac so I could post to > Usenet, I discovered it works fine on the Mac. Only Windows seems to be > the problem. Windows 7. > > Any thoughts or suggestions? > Home isn't defined in Windows but somehow is in IDLE? From a command line enter "set home". Doing that on my Windows 8.1 box shows:- HOMEDRIVE=C: HOMEPATH=\Users\Mark -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence