Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #54563 > unrolled thread
| Started by | MRAB <python@mrabarnett.plus.com> |
|---|---|
| First post | 2013-09-21 20:50 +0100 |
| Last post | 2013-09-21 20:50 +0100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Code suggestions? MRAB <python@mrabarnett.plus.com> - 2013-09-21 20:50 +0100
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-09-21 20:50 +0100 |
| Subject | Re: Code suggestions? |
| Message-ID | <mailman.232.1379793004.18130.python-list@python.org> |
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 top | Article view | comp.lang.python
csiph-web