Skip to content

Instantly share code, notes, and snippets.

@mladoux
Last active November 7, 2017 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mladoux/7122bc1212bf4ca868a7 to your computer and use it in GitHub Desktop.
Save mladoux/7122bc1212bf4ca868a7 to your computer and use it in GitHub Desktop.
Print multiple newlines
def printnl(lines=1):
'''Print a variable number of empty lines to the screen
Keyword arguments:
lines -- Number of empty lines to print.
Defaults to 1.
Returns: string
'''
try:
'''Try to convert input to a float first, because a naked float can be
converted to an integer, but not a float in a string'''
lines = float(lines)
'''now convert it to an integer, because range won't work with a float'''
lines = int(lines)
except:
'''Obviously, we either don't have a number, or we have some insane float
like infinity, so we should raise an exception'''
raise ValueError("printnl: Value must be an integer.")
if lines < 0:
''' If lines is a negative value raise a value error '''
raise ValueError('printnl: Integer must be a positive value.')
for c in range(lines):
''' print however many lines that lines equals '''
print('')
@mladoux
Copy link
Author

mladoux commented Nov 23, 2014

Simple method I created for when I need more than one newline on console output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment