First python project : Tuner

Discussion in 'Python' started by Jérôme, Jan 17, 2012.

  1. Jérôme

    Jérôme Guest

    Hi all.

    Like others before me, I'd like to show you my first python attempt, in the
    hope in can get advices on how to improve my coding.

    I started learning python and pyGTK last november. I had had a short
    experience of GTK with C, but had given up as I lacked time and I found it
    more difficult than I expected. python makes things more easy. Yet, after
    starting with pyGTK, I switched to PyGObject, and lack of documentation made
    small things a bit hard sometimes...

    The project I chose as an exercise is some sort of guitar tuner. It can be
    found here :
    http://devs.jolimont.fr/tuner/

    The choice of the sound backends was already discussed on this list. Next
    step would be to switch to a python audio library and use threads instead of
    processes.

    I added flags to avoid race conditions, perhaps with a little bit of
    clumsyness. This makes the code more complicated than it deserved to be.

    Any comment is welcome, be it about code optimization, coding style,
    pythonification, good practices, or simply program features and usability.

    Thanks.

    --
    Jérôme
    Jérôme, Jan 17, 2012
    #1
    1. Advertising

  2. Jérôme

    Rick Johnson Guest

    On Jan 17, 8:16 am, Jérôme <> wrote:

    > Any comment is welcome, be it about code optimization, coding style,
    > pythonification, good practices, or simply program features and usability..


    Step one would be to show a screen shot in both English AND French
    language. Besides, not everyone in this community is a "card carrying"
    pacifist.
    Rick Johnson, Jan 17, 2012
    #2
    1. Advertising

  3. Jérôme

    Jérôme Guest

    Tue, 17 Jan 2012 08:48:13 -0800 (PST)
    Rick Johnson a écrit:

    > On Jan 17, 8:16 am, Jérôme <> wrote:
    >
    > > Any comment is welcome, be it about code optimization, coding style,
    > > pythonification, good practices, or simply program features and usability.

    >
    > Step one would be to show a screen shot in both English AND French
    > language.


    The screenshot was a dissatisfying mix of english and french because until
    I18n is done (next in TODO list) all the strings are in english, but the stock
    buttons are localized as my system is in french. Yet the inconsistency.

    I didn't know it was as easy as

    LANGUAGE=EN ./tuner_v2_0.py

    to re-localize a program. Now the screenshot is english only.

    Anyway, I was trying to bring people's attention to the python program
    itself :
    http://devs.jolimont.fr/tuner/downloads/tuner_v2_0.py

    > Besides, not everyone in this community is a "card carrying"
    > pacifist.


    ?

    --
    Jérôme
    Jérôme, Jan 17, 2012
    #3
  4. Jérôme

    Jérôme Guest

    Tue, 17 Jan 2012 12:28:11 -0500
    Rodrick Brown a écrit:

    > You would get more responses if you used one of those sites that displayed
    > the code right in the browser.


    Thanks for the tip.

    I thought people would rather open it in their own editor. (And I tend to
    avoid third-party hosting.)

    Here's an html rendering :

    http://devs.jolimont.fr/tuner/downloads/tuner_v2_0.py.html

    This is done with gvim. Too bad it lacks line numbering.

    --
    Jérôme
    Jérôme, Jan 17, 2012
    #4
  5. Jérôme

    gst Guest

    On 17 jan, 15:16, Jérôme <> wrote:
    > Hi all.
    >


    hi,

    just my 2 cents:

    you have quite lot of such test:

    > if self._index is 0:


    I think it's better to compare with equality against 0 (or other
    needed value) ; that is:

    if self._index == 0:

    otherwise your code looks very nice to me, though I just had a very
    quick look ;)

    regards,

    GS.
    gst, Jan 17, 2012
    #5
  6. Jérôme

    Jérôme Guest

    Tue, 17 Jan 2012 10:16:02 -0800 (PST)
    gst a écrit:

    > you have quite lot of such test:
    >
    > > if self._index is 0:

    >
    > I think it's better to compare with equality against 0 (or other
    > needed value) ; that is:
    >
    > if self._index == 0:


    Yes, I just saw that thanks to Alex Willmer's e-mail.

    I used to have ==, until for some strange reason I figured is was more
    pythonic, so I replaced all == I could with is. I shouldn't have.

    I appended this issue on top of my TODO list.

    Although I try to read as much documentation as I can to do things clean,
    there is still a lot of trial and error and sometimes my criterion ends up
    being "does it works or does it not", whithout comprehensive understanding.

    > otherwise your code looks very nice to me, though I just had a very
    > quick look ;)


    Thank you for the feedback.

    --
    Jérôme
    Jérôme, Jan 17, 2012
    #6
  7. Jérôme

    Rick Johnson Guest

    On Jan 17, 1:38 pm, Ben Finney <> wrote:
    > Jérôme <> writes:
    > > Rick Johnson a écrit:
    > > > Besides, not everyone in this community is a "card carrying"
    > > > pacifist.

    > > ?

    > You have attracted the attention of a troll.


    What is worse: A wolf, or a wolf in sheep's clothing?

    There is no "trolling" in my reply. A nice quip, yes. Trolling, no.
    The fact remains that English is very important to Python. In fact,
    English is SO important that the great Guido van Rossum himself
    mentioned English explicitly in PEP8. And as we know, English is NOT
    his first language!

    GvR said: """Python coders from non-English speaking countries: please
    write your comments in English, unless you are 120% sure that the code
    will never be read by people who don't speak your language."""

    GvR said: """All identifiers in the Python standard library MUST use
    ASCII-only identifiers, and SHOULD use English words wherever feasible
    (in many cases, abbreviations and technical terms are used which
    aren't English)."""
    Rick Johnson, Jan 17, 2012
    #7
  8. On Wed, Jan 18, 2012 at 7:38 AM, Rick Johnson
    <> wrote:
    > On Jan 17, 1:38 pm, Ben Finney <> wrote:
    >> You have attracted the attention of a troll.

    >
    > What is worse: A wolf, or a wolf in sheep's clothing?
    >
    > There is no "trolling" in my reply. A nice quip, yes. Trolling, no.


    Well, as we learn from Innistrad, worse is a wolf in shepherd's
    clothing. (Look up 'Gatstaf Shepherd'.)

    Ben didn't say there was "trolling" in your reply. He said that the OP
    had attracted the attention of a troll. That said, though, I would
    have to say that your post was trollish.

    ChrisA
    Chris Angelico, Jan 17, 2012
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. matt
    Replies:
    9
    Views:
    402
    Andrew Thompson
    Oct 27, 2004
  2. alessandro
    Replies:
    9
    Views:
    6,040
    John Harrison
    Sep 14, 2004
  3. KDawg44

    Learning Python - First Project

    KDawg44, Apr 23, 2007, in forum: Python
    Replies:
    10
    Views:
    454
  4. Paul Scott
    Replies:
    4
    Views:
    235
    Paul Scott
    Apr 8, 2008
  5. Jérôme

    Re: First python project : Tuner

    Jérôme, Jan 19, 2012, in forum: Python
    Replies:
    3
    Views:
    174
    Jérôme
    Jan 26, 2012
Loading...

Share This Page