Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54563

Re: Code suggestions?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'true,': 0.05; 'none,': 0.07; 'paths': 0.07; 'caching,': 0.09; 'feature,': 0.09; 'optimizing': 0.09; 'rewrite': 0.09; 'solution,': 0.09; 'unified': 0.09; 'python': 0.11; 'wrote': 0.14; '"=="': 0.16; '"is': 0.16; '"is"': 0.16; 'benjamin': 0.16; 'code?': 0.16; 'folks,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'interest,': 0.16; 'library),': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'simplified': 0.16; 'underscores,': 0.16; 'url:py': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'file,': 0.19; 'header:User-Agent:1': 0.23; 'specify': 0.24; 'subject:Code': 0.24; 'skip:" 30': 0.26; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'testing': 0.29; 'generally': 0.29; "i'm": 0.30; 'code': 0.31; 'usually': 0.31; 'helpful.': 0.31; 'raised': 0.31; 'anyone': 0.31; 'file': 0.32; 'class': 0.32; 'checking': 0.33; 'raw': 0.33; 'knows': 0.35; 'received:84': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'false': 0.36; 'gallery': 0.36; 'module.': 0.36; 'returning': 0.36; 'subject:?': 0.36; 'application': 0.37; 'so,': 0.37; 'level': 0.37; 'to:addr:python-list': 0.38; 'expect': 0.39; 'does': 0.39; 'bad': 0.39; 'to:addr:python.org': 0.39; 'eventually': 0.60; 'url:u': 0.61; 'entire': 0.61; "you're": 0.61; "you'll": 0.62; 'managing': 0.66; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'therefore': 0.72; 'behavior': 0.77; 'bare': 0.84; 'directories,': 0.84; 'regarded': 0.84; 'reply-to:addr:python.org': 0.84; 'differences': 0.93
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=Vd3OYjZ9 c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=0kkAYlmtguIA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=1Hs_0EbXM8AA:10 a=OgGP0Dt4AAAA:8 a=OG0TmphOghk-4KXTUf4A:9 a=wPNLvfGTeEIA:10
X-AUTH mrabarnett:2500
Date Sat, 21 Sep 2013 20:50:08 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130801 Thunderbird/17.0.8
MIME-Version 1.0
To python-list@python.org
Subject Re: Code suggestions?
References <60E7ACFB-A952-4E43-AEA7-4C76D9057B44@schollnick.net>
In-Reply-To <60E7ACFB-A952-4E43-AEA7-4C76D9057B44@schollnick.net>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
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.232.1379793004.18130.python-list@python.org> (permalink)
Lines 56
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1379793004 news.xs4all.nl 15894 [2001:888:2000:d::a6]:47483
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:54563

Show key headers only | View raw


On 21/09/2013 15:00, Benjamin Schollnick wrote:
> Folks,
>
> I am re-writing an image gallery application that I wrote in Twisted.
>
> As part of this rewrite, I am attempting to simplify the process of
> managing the directory listings.
>
> Would anyone have any suggestions on streamlining or optimizing this code?
>
> The raw version of this file, is available from dropbox.
>
> https://dl.dropboxusercontent.com/u/241415/unified.py
>
> If you are testing with RAR files, you'll need rarfile.py
>
> https://dl.dropboxusercontent.com/u/241415/rarfile.py
>
> If anyone knows a better built-in Python 2.66/2.75 solution, that would
> be helpful.
>
> I eventually expect to support caching, but I think that will be an
> application level feature, and not built-in to this module.
>
> The entire idea is to unify (thus unified.py) behavior better files,
> directories, and archives.
>
> Yes, there is differences in the data coming back, but the calling
> logic, is identical.
>
> So far, this rewrite has tremendously simplified the code for the image
> gallery.  If there is any interest, I'm willing to github unified or the
> image gallery.
>
[snip]
Some comments:-

Using "import *" is generally regarded as a Bad Thing.

Class names usually don't contain underscores, therefore
"UnifiedDirectory" would be better.

It's better to create file paths using os.path.join(...) instead of
"manually" using "+".

When checking for None, use "is" and "is not", not "==" and "!=".

It's almost NEVER a good idea to use a bare except. Specify which
exception you're trying to catch.

The function "populate_file_data_from_filesystem" can return True,
False (printing a message just before it does so, which makes it harder
to use as part of a library), or None (because there's a bare return).
It would be better if it raised an exception in the case of an error,
returning None otherwise (a bare return).

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Code suggestions? MRAB <python@mrabarnett.plus.com> - 2013-09-21 20:50 +0100

csiph-web