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


Groups > comp.lang.python > #18798

Re: Newbie: Looking for code review on my first Python project.

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Newbie: Looking for code review on my first Python project.
References <jeiig6$csj$1@news.albasani.net> <mailman.4621.1326246196.27778.python-list@python.org>
Date 2012-01-11 13:05 +1100
Message-ID <871ur7803x.fsf@benfinney.id.au> (permalink)
Organization Unlimited download news at news.astraweb.com

Show all headers | View raw


Chris Angelico <rosuav@gmail.com> writes:

> On Wed, Jan 11, 2012 at 10:44 AM, HoneyMonster
> <someone@someplace.invalid> wrote:
> > Hi,
> >
> > I'm new to Python and recently completed my first project. I used
> > wxPython with wxGlade to generate the GUI bits.The application seems to
> > work well, but I am entirely self-taught, so have undoubtedly committed a
> > number of howlers in terms of style, design, standards, best practice and
> > so forth.
>
> Welcome!
>
> Ian has already offered some excellent tips, so I'll not repeat him.
>
>
>     log = os.environ['HOME'] + "/log/bbc.log"
>     log = os.environ['HOMEPATH'] + "\\log\\bbc.log"
>
> Python on Windows will support / for paths

Even better, you don't need to worry about what separator to use::

    top_dir = os.environ['HOME']
    log_filepath = os.path.join(top_dir, "log", "bbc.log")

> I'd do this with a triple-quoted string:
>
> about = """Built by Walter Hurry using Python and wxPython,
> with wxGlade to generate the code for the GUI elements.
> Phil Lewis' get_iplayer does the real work.
>
> Version 1.05: January 10, 2012"""

Which you can get indented nicely in the source, and strip off the
indentation at run-time:

    import textwrap

    about = textwrap.dedent("""\
            Built by Walter Hurry using Python and wxPython,
            with wxGlade to generate the code for the GUI elements.
            Phil Lewis' get_iplayer does the real work.

            Version 1.05: January 10, 2012
            """)

>         self.add = self.file.AppendItem(wx.MenuItem(self.file,
> wx.NewId(), "&Add to Queue", "Add a programme to the queue (for
> download later)", wx.ITEM_NORMAL))

Which is a whole lot more readable using the recommendations in PEP 8::

    self.add = self.file.AppendItem(
            wx.MenuItem(
                self.file, wx.NewId(), "&Add to Queue",
                "Add a programme to the queue (for download later)",
                wx.ITEM_NORMAL))

-- 
 \       “I distrust those people who know so well what God wants them |
  `\    to do to their fellows, because it always coincides with their |
_o__)                      own desires.” —Susan Brownell Anthony, 1896 |
Ben Finney

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


Thread

Newbie: Looking for code review on my first Python project. HoneyMonster <someone@someplace.invalid> - 2012-01-10 23:44 +0000
  Re: Newbie: Looking for code review on my first Python project. Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-10 18:17 -0700
    Re: Newbie: Looking for code review on my first Python project. HoneyMonster <someone@someplace.invalid> - 2012-01-11 11:39 +0000
      Re: Newbie: Looking for code review on my first Python project. HoneyMonster <someone@someplace.invalid> - 2012-01-11 21:09 +0000
        Re: Newbie: Looking for code review on my first Python project. 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-11 16:24 -0800
  Re: Newbie: Looking for code review on my first Python project. Chris Angelico <rosuav@gmail.com> - 2012-01-11 12:43 +1100
    Re: Newbie: Looking for code review on my first Python project. Ben Finney <ben+python@benfinney.id.au> - 2012-01-11 13:05 +1100
  Re: Newbie: Looking for code review on my first Python project. Terry Reedy <tjreedy@udel.edu> - 2012-01-10 20:50 -0500
  Re: Newbie: Looking for code review on my first Python project. Terry Reedy <tjreedy@udel.edu> - 2012-01-10 22:59 -0500
    Re: Newbie: Looking for code review on my first Python project. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-11 04:24 +0000
    Re: Newbie: Looking for code review on my first Python project. Ben Finney <ben+python@benfinney.id.au> - 2012-01-11 16:23 +1100

csiph-web