# Argparse implementation [closed]

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')
default=default_interface,
help='the interface used for monitoring')
default=distutils.spawn.find_executable("tshark"),
help='path to tshark binary')
default=distutils.spawn.find_executable("ifconfig"),
help='path to ifconfig')
default=distutils.spawn.find_executable("iwconfig"),
help='path to iwconfig')
default='-',
help='output file (path or - for stdout)')
default='all',
help='channel/s to hop (i.e. 3 or 3,6,9 or 3-14 or all or 0 for current channel')
action='store_true',
help='verbose information')
action='store_true',
help='only saves probe data spit by newline')
default=5,
help='delay between channel change')
args = parser.parse_args()


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)")

• Ok. Should I put a blank line between entries? Without it seems to me a little bit confusing. – 0x2b3bfa0 Mar 13 '15 at 14:18
• @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 '15 at 14:19
• Ok, I used the second option without putting newlines. Thank you very much! – 0x2b3bfa0 Mar 13 '15 at 14:25