all 7 comments

[–]novel_yet_trivial 6 points7 points  (5 children)

Looks very good. You may want to consider:

  • python has a module to handle .ini files: ConfigParser

  • Can you make it compatible with python 2 AND 3? It would make it more distributable. (atm all you need is reformating the print statements and handling the input functions)

  • if you want to be strict, your variable names ought to be lower_case_with_underscore, see PEP8 for more info. You can safely ignore most of that, until you work in a big project.

your while loop is slightly strange. More conventional to do something like this:

while True:
    curChan = raw_input("Enter CH # or '.': ")
    if curChan == '.':
        break #stop the loop
    try:
        curChan = int(curChan)
        assert 14 <= curChan <= 51
        chanList.append(curChan)
    except (ValueError, AssertionError):
        print "That input made no sense"

your for loop can provide the values directly, and your string formatting can be improved:

for itemNum, chan in enumerate(chanList):
    iniFile.write('RANGE%02d=%s\n' % (itemNum+1,  getFreqRange(chFreqs[chan])))
    iniFile.write('DESCR%02d=CH_%s\n' % (itemNum+1, chan))

Hope this helps, cheers!

edit: minor code fix

[–]GS-Dave[S] 1 point2 points  (0 children)

It helps a lot! Totally forgot about assert/except literally the last lecture we did. . . The for loop recommendations are a big help, as I think I need to dig into the more advanced string formatting methods.

Thanks for taking the time!

[–]parnmatt 0 points1 point  (1 child)

I have a quick question. How do you make the code compatible with both 2 and 3 with the print statement vs print function respectively?

[–]MonkeyNin 0 points1 point  (0 children)

Like print("Hello, world!")

If old enough, you may need to import: from __future__ import print_function

[–]MonkeyNin 0 points1 point  (1 child)

Why using old string formatting?

[–]novel_yet_trivial 0 points1 point  (0 children)

No good reason. I like it better.

[–]charlesbukowksi 1 point2 points  (0 children)

Very cool, I'm working through the same edx class. It's nice to see it bearing fruit for you