Last active
November 7, 2017 06:18
-
-
Save mladoux/7122bc1212bf4ca868a7 to your computer and use it in GitHub Desktop.
Print multiple newlines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple method I created for when I need more than one newline on console output.