Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

This is a follow up to Log probe requests of WiFi devices focussing on a specific element of the code.

How can I indent this code to make it look great and be well formatted?

parser = argparse.ArgumentParser(description='Collect WiFi probe requests')
parser.add_argument('-i', '--interface',
                    default=default_interface,
                    help='the interface used for monitoring')
parser.add_argument('--tshark-path',
                    default=distutils.spawn.find_executable("tshark"), 
                    help='path to tshark binary')
parser.add_argument('--ifconfig-path',
                    default=distutils.spawn.find_executable("ifconfig"), 
                    help='path to ifconfig')
parser.add_argument('--iwconfig-path',
                    default=distutils.spawn.find_executable("iwconfig"), 
                    help='path to iwconfig')
parser.add_argument('-o', '--output',
                    default='-', 
                    help='output file (path or - for stdout)')
parser.add_argument('-c', '--channel',
                    default='all', 
                    help='channel/s to hop (i.e. 3 or 3,6,9 or 3-14 or all or 0 for current channel')
parser.add_argument('--verbose',
                    action='store_true', 
                    help='verbose information')
parser.add_argument('-p', '--only-probes',
                    action='store_true',
                    help='only saves probe data spit by newline')
parser.add_argument('--delay',
                    default=5,
                    help='delay between channel change')
args = parser.parse_args()
share|improve this question
    
Don't do that; see e.g. meta.codereview.stackexchange.com/a/1483/32391 –  jonrsharpe Mar 13 at 15:11

1 Answer 1

up vote 1 down vote accepted

Python has a style guide, which lays out guidelines for (among other things) code formatting. Your current code is compliant with the style guide, except that the help parameter for --channel means the line is too long.

You can easily avoid this by simply breaking the string across multiple lines:

parser.add_argument('-c', '--channel',
                    default='all',
                    help='channel/s to hop (i.e. 3 or 3,6,9 or 3-14 or all or 0 '
                    'for current channel')

Alternatively, you can shorten the message slightly and use one of the other recommended indent styles, which uses less horizontal space:

parser.add_argument(
    '-c', '--channel',
    default='all',
    help="channel/s to hop (e.g. '3', '3,6,9', '3-14', 'all', '0' (current channel)")
share|improve this answer
    
Ok. Should I put a blank line between entries? Without it seems to me a little bit confusing. –  Helio Mar 13 at 14:18
1  
@Helio the style guide says blank lines should be used "sparingly". I think the blank space at the start of the parameter lines between each parser... is clear enough, but you can add them if you like. –  jonrsharpe Mar 13 at 14:19
    
Ok, I used the second option without putting newlines. Thank you very much! –  Helio Mar 13 at 14:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.