Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #81051
| X-Received | by 10.66.237.66 with SMTP id va2mr6291482pac.28.1416454970659; Wed, 19 Nov 2014 19:42:50 -0800 (PST) |
|---|---|
| X-Received | by 10.140.40.20 with SMTP id w20mr1627161qgw.2.1416454970608; Wed, 19 Nov 2014 19:42:50 -0800 (PST) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!h15no4045139igd.0!news-out.google.com!w7ni50qay.0!nntp.google.com!w8no1004127qac.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Wed, 19 Nov 2014 19:42:50 -0800 (PST) |
| In-Reply-To | <mailman.15905.1416174334.18130.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=70.196.70.232; posting-account=h3aEwQoAAACiuqX-oR3gvCVFm8lLHoWj |
| NNTP-Posting-Host | 70.196.70.232 |
| References | <mailman.15905.1416174334.18130.python-list@python.org> |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <12e83ca0-4ecc-467c-9069-98be261595c4@googlegroups.com> (permalink) |
| Subject | Re: What does this line of code mean? |
| From | Rick Johnson <rantingrickjohnson@gmail.com> |
| Injection-Date | Thu, 20 Nov 2014 03:42:50 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| X-Received-Bytes | 3031 |
| X-Received-Body-CRC | 1163452110 |
| Xref | csiph.com comp.lang.python:81051 |
Show key headers only | View raw
On Sunday, November 16, 2014 3:45:58 PM UTC-6, Abdul Abdul wrote:
> I just came across the following line of code:
>
> outputfile = os.path.splitext(infile)[0] + ".jpg"
>
> Can you kindly explain to me what those parts mean?
What that line of code "means" is:
The author is far too dependent on authority (Python) and
either lacks the *motivation* to improve the situation, or
lacks the *skill* to improve the situation -- or both!
It is my strong opinion that path munging like the type
displayed here should be avoided when all possible. The
author is doing more work than he needs to do and he's doing
the work in an overly cryptic manner. Sure, any Python coder
worth his SALT can grok the code, but Python code like this
should never be celebrated, it should be excommunicated!
Instead of calling a function that splits a file-path, *THEN*
indexing the return value of the split to fetch a subsection
(YUCK!), *THEN* concatenating the fetched subsection with a
new extension (PUKE!)... he should have called one simple
*SELF-EXPLANATORY* method:
os.path.substitute_extension(inPath, ".jpg")
But of course that method does not exists in *YOUR* Python!
No, you're forced to drink the cheap, "powdery tasting",
bitterly-under-sugared kool-aide that the os.path module has
demanded of you.
"Oh Yeah!"
Urm,
Oh *NO THANKS*!
To further aid in memory recall, the os.path module should
have many "get_*" and "substitute_*" methods, however, it
should have *ONLY* one "split" method which breaks a path
into *ALL* of it's atomic parts:
drive, folder, filename, extension = os.path.split(path)
Of course the author also failed to use intuitive "self
documenting" names. "infile" suggest a file *object*, when
"inPath" and "outPath" are better suited to suggesting file
paths as *strings*.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
What does this line of code mean? Abdul Abdul <abdul.sw84@gmail.com> - 2014-11-16 22:45 +0100 Re: What does this line of code mean? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-11-16 23:07 +0100 Re: What does this line of code mean? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-11-19 19:42 -0800
csiph-web