Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59155
| Path | csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'explicitly': 0.05; 'insert': 0.05; 'true,': 0.05; 'float': 0.07; 'paths': 0.07; 'exception,': 0.09; 'exception.': 0.09; 'function,': 0.09; 'mercurial': 0.09; 'so?': 0.09; 'sure,': 0.09; 'terminated': 0.09; 'whole.': 0.09; 'developer': 0.10; 'python': 0.11; 'def': 0.12; "'w')": 0.16; 'ah,': 0.16; 'assumptions': 0.16; 'concurrency': 0.16; 'concurrent': 0.16; 'confirm:': 0.16; 'disc': 0.16; 'exception?': 0.16; 'exist.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'garbage': 0.16; 'happily': 0.16; 'hmm.': 0.16; 'hypothetical': 0.16; 'ignoring': 0.16; 'omitting': 0.16; 'porting': 0.16; 'qualifying': 0.16; 'signaled': 0.16; 'simplicity.': 0.16; 'slash.': 0.16; 'stored.': 0.16; 'truncating': 0.16; 'typo': 0.16; 'unexpected': 0.16; 'why,': 0.16; 'words.': 0.16; 'exception': 0.16; 'prevent': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'trying': 0.19; 'passing': 0.19; 'things.': 0.19; '>>>': 0.22; 'platforms': 0.22; 'import': 0.22; 'python?': 0.22; 'saying': 0.22; 'exists': 0.24; 'source': 0.25; 'script': 0.25; 'world,': 0.26; 'header:In-Reply- To:1': 0.27; 'tried': 0.27; 'testing': 0.29; 'chris': 0.29; 'am,': 0.29; "doesn't": 0.30; 'errors': 0.30; 'relative': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; 'comments': 0.31; 'are.': 0.31; 'directory,': 0.31; 'letter.': 0.31; 'file': 0.32; 'quite': 0.32; 'open': 0.33; 'monday,': 0.33; 'maybe': 0.34; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'common': 0.35; 'except': 0.35; 'johnson': 0.35; 'test': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'doing': 0.36; 'method': 0.36; 'wrong': 0.37; 'too': 0.37; 'two': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'problems': 0.38; 'depends': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'pm,': 0.38; 'anything': 0.39; 'expect': 0.39; 'does': 0.39; '12,': 0.39; 'supporting': 0.39; 'volume': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'most': 0.60; 'skip:o 30': 0.61; 'facebook': 0.61; "you're": 0.61; 'you.': 0.62; 'save': 0.62; "you'll": 0.62; 'today': 0.64; 'skip:n 10': 0.64; 'situation': 0.65; 'between': 0.67; 'believe': 0.68; 'yes': 0.68; 'production.': 0.68; 'day': 0.76; 'protect': 0.79; '"just': 0.84; 'comment.': 0.84; 'confirming': 0.84; 'console,': 0.84; 'entertaining': 0.84; 'lived': 0.84; 'seeing,': 0.84; 'snake': 0.84; 'technically': 0.84; 'thrown,': 0.84; 'forever.': 0.91; 'opens': 0.91; 'probe': 0.91; 'recover': 0.91; 'regret': 0.91; 'why?': 0.91; 'from.': 0.93; 'remember,': 0.93; 'rick': 0.93; 'race': 0.95; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Tg0GkWljk4AXkf2yivAs8wSHkERh2ojUuneVoymFJ5o=; b=oMMFTuzfx3+VdbjT0cxTVmZc3bfwAdVbjRD7li9iH+k8/nAse3efH9mCePpoPG7T3Q 5TetB/63+F259HK3/ikep+2DrKnUpnNOulHdJ/K6zySCyMnXATPBfUGlmGMkAg9jggcu ZFd+y7uGG0fqkNNF21Ok82X6hqfnqSNp4Yt6cJEkHShcSqH8gbGA7BL6scm7SJOcpnm4 i9ResFMXWeiFQ63lmIClpcxPDl7o0lmdutZhUpypKrjq5y9x7I+cXuJ0q2nrFRbK2yZD tV7TJzJf+h5iEOGUwtlVl2SFiYBVNLNF6g08iG3WEpuFozCnj/SSi+CgEzPxJ/RgknRL Vudg== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.96.130 with SMTP id ds2mr33541015pbb.99.1384236159813; Mon, 11 Nov 2013 22:02:39 -0800 (PST) |
| In-Reply-To | <5eb204a3-b35e-4cb2-bc28-57cb1a525363@googlegroups.com> |
| References | <521ed3d4-e2f7-4196-947d-61f94573a8ce@googlegroups.com> <adf24d2c-1974-4c09-9ff2-bc82b31a09f4@googlegroups.com> <mailman.2408.1384211515.18130.python-list@python.org> <5eb204a3-b35e-4cb2-bc28-57cb1a525363@googlegroups.com> |
| Date | Tue, 12 Nov 2013 17:02:39 +1100 |
| Subject | Re: Creating a function for a directory |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| 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.2428.1384236163.18130.python-list@python.org> (permalink) |
| Lines | 104 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1384236163 news.xs4all.nl 15938 [2001:888:2000:d::a6]:44442 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:59155 |
Show key headers only | View raw
On Tue, Nov 12, 2013 at 4:42 PM, Rick Johnson
<rantingrickjohnson@gmail.com> wrote:
> On Monday, November 11, 2013 5:11:52 PM UTC-6, Chris Angelico wrote:
>> On Tue, Nov 12, 2013 at 9:51 AM, Rick Johnson
>> > 1. i believe win32 file paths require a qualifying volume
>> > letter.
>> They do not; omitting the drive letter makes the path relative to the
>> current drive (and since it doesn't start with a directory specifier,
>> the current directory).
>
> Hmm. Let's confirm:
>
> >>> import os
> >>> os.path.exists("C:/Windows/System32")
> True
> >>> os.path.exists("/Windows/System32")
> True
>
> Yep, it's official. "Implicit File Path Resolution"
> I need to author a PyWart on this soon!
That's not a Python issue at all. And are you seriously going to decry
relative pathnames?!?
>> > 2. Never, ever, *EVER* write data to disc before confirming
>> > the paths your passing are pointing to the location you
>> > intended to write the data. Use os.path.exists(path) to test
>> > your paths BEFORE trying to write data.
>> Why? Why, oh why? If there's a problem, it'll be signalled
>> with an exception.
>
> Except when there's a problem that won't be signaled by an
> EXCEPTION, but will be signaled by EMOTIONS; like for
> instance removing the wrong directory or truncating the
> wrong file because of a typo in your source code.
Which os.path.exists will not protect you from. So?
>> Testing that the path exists opens you up to race
>> problems, so you won't see anything now, but some day your
>> code will be in a concurrent situation and you'll get
>> unexpected exceptions. Why not just expect the exception?
>
> Because today i'm not facing a concurrent situation, so i'm
> not going to bother and protect from it. Just like i'm not
> facing a snake bite, so i won't bother to lug around a vial
> of antidote. Your attempts to discredit me via hypothetical
> scenarios is entertaining however.
>> > 6 For OS compatibility always use os.path.join() to join
>> > path parts into a whole. This method will insert the proper
>> > separator for you depending on the OS.
>> Technically true. However, most modern OSes will accept a
>> slash. There'll be a few situations where that's not true,
>> but the OP an happily just use slashes for simplicity.
>
> Many a developer have lived to regret those words.
(Reordered to bring together two comments getting one response) Do you
care about what you currently are seeing, or what you might some day
see? Concurrency is a common problem on many platforms; platforms not
supporting slashes between paths are rare, and most of them will have
other porting issues. Why are you ignoring the likely, while trying to
prevent the unlikely?
>> They won't float around forever. The garbage collector
>> will get to them.
>
> That depends on how they are stored. You make too many
> assumptions Chris. I don't have an problems with GC's, but
> i'm not about to write sloppy code and "assume" the GC is
> going to swoop in and save me like a feline trapped in a
> tree.
Ah, actually yes you are. When have you ever explicitly disposed of an
object in Python? You just let the GC deal with it for you.
>> > 5. Remember, you cannot write a file into a directory that
>> > does not exist.
>> So? Exception thrown, traceback printed to console,
>> process terminated cleanly. I'm not seeing a problem here.
>
> Now you're just trolling!
Mercurial signals some errors by dumping an exception to stderr. This
works quite nicely, even in production. If your script can't recover
from being given a non-writeable directory, don't catch the exception.
> def firstdev(file):
> in_file = open("desktop/%s.txt") % file
> indata = in_file.read()
> out_file = open("desktop/newfolder/%s.txt", 'w') % file
>
> Just from reading that code NO ONE could know for sure if
> "newfolder" even existed BEFORE the OP tried to open the
> "out_file". Maybe the OP thinks that missing sub-directories
> are auto-created by the open function, but there's no way to
> know for sure, hence my comment.
And the OP might have thought that it would automatically publish that
to the world, tweet the URL, and create a Facebook status saying "just
opened a file lolol" and get five people to Like it. Doesn't mean we
need to probe before doing things.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Creating a function for a directory Matt <mattgraves7@gmail.com> - 2013-11-11 14:26 -0800
Re: Creating a function for a directory Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-11 17:36 -0500
Re: Creating a function for a directory Chris Angelico <rosuav@gmail.com> - 2013-11-12 09:38 +1100
Re: Creating a function for a directory bob gailer <bgailer@gmail.com> - 2013-11-11 17:42 -0500
Re: Creating a function for a directory Joel Goldstick <joel.goldstick@gmail.com> - 2013-11-11 17:44 -0500
Re: Creating a function for a directory Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-11-11 22:45 +0000
Re: Creating a function for a directory Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-11 14:51 -0800
Re: Creating a function for a directory Chris Angelico <rosuav@gmail.com> - 2013-11-12 10:11 +1100
Re: Creating a function for a directory Rick Johnson <rantingrickjohnson@gmail.com> - 2013-11-11 21:42 -0800
Re: Creating a function for a directory Chris Angelico <rosuav@gmail.com> - 2013-11-12 17:02 +1100
Re: Creating a function for a directory Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-12 00:33 +0000
Re: Creating a function for a directory Neil Cerutti <neilc@norwich.edu> - 2013-11-12 13:42 +0000
Re: Creating a function for a directory Matt <mattgraves7@gmail.com> - 2013-11-11 15:05 -0800
Re: Creating a function for a directory Chris Angelico <rosuav@gmail.com> - 2013-11-12 09:51 +1100
Re: Creating a function for a directory unknown <unknown@unknown.com> - 2013-11-12 10:07 +0000
Re: Creating a function for a directory Peter Otten <__peter__@web.de> - 2013-11-12 11:24 +0100
Re: Creating a function for a directory unknown <unknown@unknown.com> - 2013-11-12 11:26 +0000
csiph-web