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


Groups > comp.lang.python > #64876

Re: buggy python interpretter or am I missing something here?

References <pan$57cb8$37426877$4ff183f7$e46f1ba0$1@all.net> <mailman.6020.1390800839.18130.python-list@python.org> <52e5f658$0$29583$862e30e2@ngroups.net> <mailman.6025.1390805261.18130.python-list@python.org> <52e60817$0$29774$862e30e2@ngroups.net>
From Zachary Ware <zachary.ware+pylist@gmail.com>
Date 2014-01-27 10:23 -0600
Subject Re: buggy python interpretter or am I missing something here?
Newsgroups comp.lang.python
Message-ID <mailman.6050.1390839851.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jan 27, 2014 at 1:17 AM, me <noone@all.net> wrote:
> It's the intendation specific requirements that throw me.  I haven't seen
> such a hork since RPG. ;^)

Best I can tell, the only thing RPG and Python have in common is the
fact that they're "programming languages", though I'm being a little
generous to RPG there.  I'll note that RPG (IV) is the only language
I've ever been formally trained in, unfortunately.  I've mostly
forgotten it though, so that's a plus :)

Python's significant indentation is really quite nice and intuitive.
The basic rule of thumb is if a line ends in a colon, the next line
needs to be indented one more level.  If you're continuing the same
logical block, keep the same indention level.  When a logical block is
finished (whether by a raise, continue, break, or return statement, or
just by "falling off the end" of the block), indent the next line one
level less.  Parentheses () (and brackets [] and braces {}) create
what amounts to a 'virtual line', \n characters are basically ignored
until the closing parenthesis is found (as long as they aren't in a
non-triple-quoted string literal).

As long as you don't try to mix tabs and spaces for your indentation
(either is fine on its own, but spaces are generally preferred), it's
very straightforward and allows you to better see the flow of the
program with no question as to whether there is anything hidden within
a block.  I've been using C more in the past two weeks than I really
expected to all this year, and have been bitten more than once by
missing braces.  Indenting intentionally is just a much cleaner,
clearer way to do things (in my opinion, of course).

>> Also, you can iterate over a (sys.argv) in a for
>> loop, replacing 'l', 'idx', and the while loop; something like
>>
>> for arg in a:
>>     if arg == '-h':
>>         print help # help being defined elsewhere...
>>     elif arg == '-hh':
>>         # no really, print help
>>         print 'help'
>
> Understood, except that some parameters take multiple elements...thus why
> I manually reference the indexes.

Try this on for size, then:

a_iter = iter(a)
for arg in a_iter:
    print('current', arg)
    if arg == '-#':
        print('next', next(a_iter))

> Yup.  Every language and platform has multiple arg parsing libraries.
> Didn't feel like taking the time to research any since most of my python
> ramblings are usually pyQT4 bindings to QT4 gui and postgresql apps.

As with most modules in the standard library, I would bet you can get
started using argparse in probably 15 minutes or less.  The online
documentation of the language and standard library is already quite
good, and there is constant effort going into improving it.  You might
also want to play around with the 'help()' function in the interactive
interpreter, it may have answered your original question without ever
having had to ask here:

>>> help(sys.exit)
Help on built-in function exit in module sys:

exit(...)
    exit([status])

    Exit the interpreter by raising SystemExit(status).
    If the status is omitted or None, it defaults to zero (i.e., success).
    If the status is numeric, it will be used as the system exit status.
    If it is another kind of object, it will be printed and the system
    exit status will be one (i.e., failure).

> Pointing out that sys.exit() raises a low level exception was the point I
> was missing.  Thx!

You're welcome, I'm glad I could help :)


As a general reply to the 'attitude' portion of this thread: "mutual
respect" is the name of the game here.  If you show respect (whether
you've already received it or not), you're likely to receive respect.
If not, don't be surprised by heated responses.  This applies equally
to everyone, I'm not pointing fingers at anyone in particular.

Regards,

-- 
Zach

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


Thread

buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 03:42 +0000
  buggy python interpretter or am I missing something here? - "TCdaemon.py"  yEnc me <noone@all.net> - 2014-01-27 03:42 +0000
  Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 21:04 -0800
    Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:17 +0000
      Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 23:03 -0800
        Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:20 +0000
  Re:buggy python interpretter or am I missing something here? Dave Angel <davea@davea.name> - 2014-01-27 00:36 -0500
    Re:buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:02 +0000
      Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 00:47 -0600
        Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:17 +0000
          Re: buggy python interpretter or am I missing something here? Alister <alister.ware@ntlworld.com> - 2014-01-27 12:19 +0000
          Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 13:48 +0000
          Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 10:23 -0600
            Re: buggy python interpretter or am I missing something here? Dan Sommers <dan@tombstonezero.net> - 2014-01-27 16:38 +0000
          Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 16:45 +0000
  Re: buggy python interpretter or am I missing something here? Terry Reedy <tjreedy@udel.edu> - 2014-01-27 01:21 -0500
    Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:42 +0000
      Re: buggy python interpretter or am I missing something here? Ethan Furman <ethan@stoneleaf.us> - 2014-01-26 23:08 -0800
  Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 06:46 +0000
    Re: buggy python interpretter or am I missing something here? Zachary Ware <zachary.ware+pylist@gmail.com> - 2014-01-27 00:55 -0600
    Re: buggy python interpretter or am I missing something here? Gary Herron <gary.herron@islandtraining.com> - 2014-01-26 23:12 -0800
      Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:30 +0000
        Re: buggy python interpretter or am I missing something here? Peter Otten <__peter__@web.de> - 2014-01-27 09:45 +0100
    Re: buggy python interpretter or am I missing something here? Ethan Furman <ethan@stoneleaf.us> - 2014-01-26 23:17 -0800
      Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 07:44 +0000
        Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-27 20:01 +1100
          Re: buggy python interpretter or am I missing something here? me <noone@all.net> - 2014-01-27 09:32 +0000
            Re: buggy python interpretter or am I missing something here? Neil Cerutti <neilc@norwich.edu> - 2014-01-27 12:56 +0000
            Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-27 13:56 +0000
            Re: buggy python interpretter or am I missing something here? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-01-27 07:33 -0800
              Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-28 02:53 +1100
                Re: buggy python interpretter or am I missing something here? Rick Johnson <rantingrickjohnson@gmail.com> - 2014-01-27 12:22 -0800
                Re: buggy python interpretter or am I missing something here? Chris Angelico <rosuav@gmail.com> - 2014-01-28 07:29 +1100
                Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-27 22:25 +0000
                Re: buggy python interpretter or am I missing something here? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-30 18:13 +1300
                Re: buggy python interpretter or am I missing something here? Terry Reedy <tjreedy@udel.edu> - 2014-01-30 04:44 -0500
                Re: buggy python interpretter or am I missing something here? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-31 04:06 +0000
                Re: buggy python interpretter or am I missing something here? Kushal Kumaran <kushal.kumaran@gmail.com> - 2014-01-31 10:37 +0530
                Re: buggy python interpretter or am I missing something here? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-31 19:59 +1300
              Re: buggy python interpretter or am I missing something here? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-27 16:22 +0000
            Re: buggy python interpretter or am I missing something here? Michael Torrie <torriem@gmail.com> - 2014-01-27 10:52 -0700

csiph-web