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


Groups > comp.lang.python > #197784

Hack or beauty?

From "Michael F. Stemper" <michael.stemper@gmail.com>
Newsgroups comp.lang.python
Subject Hack or beauty?
Date 2026-05-13 13:58 -0500
Organization A noiseless patient Spider
Message-ID <10u2hla$2tnlr$1@dont-email.me> (permalink)

Show all headers | View raw


I have a program that does some calculations for multiple
different values of a certain quantity. I wanted to either
write a second program that would hold the first quantity
fixed and loop over a different one, or to extend the
first to do either of those based on a command-line option.

While noodling around, I thought "what about --" and came up
with the following idea:

============================================================
if options.angle:
   angles = [0.05*k for k in range(7)]
else:
   comps = [0.1*k for k in range(6)]

for variable in angles if options.angle else comps:
   if options.angle:
     angle = variable
   else:
     X_C = variable * -X_L

   junk = sys.stdout.write( "%4.2f  %4.3f\n" % (angle,X_C) )
   # Hard part elided for clarity
============================================================

I was surprised to see that one could actually write a
for-loop like that, although it tickled my inner hacker.

What I'd like to know is: Is this an egregious abuse of the
language, or is it perfectly pythonic?

Opinions, and even violent disagreement, are solicited.

-- 
Michael F. Stemper
Always use apostrophe's and "quotation marks" properly.

Back to comp.lang.python | Previous | NextNext in thread | Find similar


Thread

Hack or beauty? "Michael F. Stemper" <michael.stemper@gmail.com> - 2026-05-13 13:58 -0500
  Re: Hack or beauty? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-05-13 19:33 +0000
    Re: Hack or beauty? ram@zedat.fu-berlin.de (Stefan Ram) - 2026-05-13 21:04 +0000
      Re: Hack or beauty? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-14 01:06 +0000
    Re: Hack or beauty? "Michael F. Stemper" <michael.stemper@gmail.com> - 2026-05-14 13:25 -0500
  Re: Hack or beauty? Mark Bourne <nntp.mbourne@spamgourmet.com> - 2026-05-13 21:52 +0100
    Re: Hack or beauty? "Michael F. Stemper" <michael.stemper@gmail.com> - 2026-05-14 08:06 -0500
  Re: Hack or beauty? Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-05-13 21:37 +0000

csiph-web