Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93646
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'subject:getting': 0.07; 'path)': 0.09; 'src': 0.09; 'properly': 0.15; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'idle,': 0.16; 'message- id:@mrabarnett.plus.com': 0.16; 'open(src,': 0.16; 'quits': 0.16; 'received:192.168.1.4': 0.16; 'runs.': 0.16; 'subject:windows': 0.16; 'wrote:': 0.16; 'directory.': 0.18; 'skip:a 60': 0.18; 'thoughts': 0.18; 'windows': 0.20; 'fix': 0.21; 'tkinter': 0.22; 'trying': 0.22; '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; 'error': 0.27; 'moved': 0.27; 'idea': 0.28; 'fine': 0.28; 'dialog': 0.29; "i'm": 0.30; 'code': 0.30; 'call.': 0.30; 'users.': 0.31; 'post': 0.31; '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; 'problem.': 0.35; 'but': 0.36; '(and': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'mac': 0.37; "won't": 0.38; 'stuff': 0.38; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'ever': 0.60; 'documents': 0.61; 'show': 0.62; 'python-list': 0.66; 'box,': 0.67; 'click': 0.76; 'discovered': 0.83; 'fin': 0.84; 'mac.': 0.84 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=JOrGyJ+b c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=EBOSESyhAAAA:8 a=AGkejYDSTmIA:10 a=IkcTkHD0fZMA:10 a=f8JYIXheacdQ3mx_YtUA:9 a=QEXdDO2ut3YA:10 |
| X-AUTH | mrabarnett@:2500 |
| Date | Fri, 10 Jul 2015 16:12:17 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Trouble getting to windows My Documents directory |
| References | <mstorkamp-154B4A.09272010072015@88-209-239-213.giganet.hu> |
| In-Reply-To | <mstorkamp-154B4A.09272010072015@88-209-239-213.giganet.hu> |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.402.1436541332.3674.python-list@python.org> (permalink) |
| Lines | 43 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1436541332 news.xs4all.nl 2897 [2001:888:2000:d::a6]:53709 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:93646 |
Show key headers only | View raw
On 2015-07-10 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? > Try os.path.expanduser(r'~\Documents'). It's a bad idea to use os.chdir; it's better to use absolute paths: src = askopenfilename(initialdir=os.path.expanduser(r'~\Documents'))
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Trouble getting to windows My Documents directory Mark Storkamp <mstorkamp@yahoo.com> - 2015-07-10 09:27 -0500
Re: Trouble getting to windows My Documents directory Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-10 15:47 +0100
Re: Trouble getting to windows My Documents directory Laura Creighton <lac@openend.se> - 2015-07-10 17:11 +0200
Re: Trouble getting to windows My Documents directory MRAB <python@mrabarnett.plus.com> - 2015-07-10 16:12 +0100
Re: Trouble getting to windows My Documents directory Mark Storkamp <mstorkamp@yahoo.com> - 2015-07-10 10:25 -0500
Re: Trouble getting to windows My Documents directory Rustom Mody <rustompmody@gmail.com> - 2015-07-10 10:48 -0700
Re: Trouble getting to windows My Documents directory Rustom Mody <rustompmody@gmail.com> - 2015-07-10 10:56 -0700
Re: Trouble getting to windows My Documents directory Tim Chase <python.list@tim.thechases.com> - 2015-07-10 09:46 -0500
Re: Trouble getting to windows My Documents directory random832@fastmail.us - 2015-07-10 20:24 -0400
Re: Trouble getting to windows My Documents directory Chris Warrick <kwpolska@gmail.com> - 2015-07-11 09:28 +0200
Re: Trouble getting to windows My Documents directory Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-07-11 11:47 -0400
Re: Trouble getting to windows My Documents directory random832@fastmail.us - 2015-08-01 02:50 -0400
csiph-web