Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python print without leading whitespace

# Basic syntax:
from textwrap import dedent
print(dedent("""
	Text for which you want to remove
    leading whitespace when printed
    """))
# Note, IMO it's mostly useful for keeping your code nicely formatted
#	while still printing messages left-justified without leading whitespace

# Example usage:
# Say you have code like:
if __name__ == '__main__':
	if True:
    	print("""
            Make sure the user
            knows this.
            """)
# when you run your script, that text will be printed with the leading
# whitespace, which is gross.

# You could print it without whitespace by restructuring your code like:
if __name__ == '__main__':
	if True:
    	print("""
Make sure the user
knows this.
            """)
# but that screws up the readability of your code.

# Instead, with dedent you can do this and print without the leading whitespace
if __name__ == '__main__':
	if True:
    	print(dedent("""
			Make sure the user
			knows this.
            """))
Comment

PREVIOUS NEXT
Code Example
Python :: python shuffle list with seed 
Python :: from sklearn.externals import joblib instead use..... 
Python :: sqlalchemy lock row 
Python :: does break stop all loops 
Python :: pd combine date time 
Python :: numpy arrays equality 
Python :: cv2 videocapture program for python 
Python :: find a prime number in python 
Python :: python time in nanoseconds 
Python :: pandas change column name from a dictionary 
Python :: select rows with nan pandas 
Python :: python module with alphabet list 
Python :: python writeline file 
Python :: how to set background color of an image to transparent in pygame 
Python :: win32api.mouse_event python 
Python :: spark add column to dataframe 
Python :: parse list from string 
Python :: identify the common columns between two dataframes pandas python 
Python :: remove empty rows csv python 
Python :: python exec return value 
Python :: accuracy score 
Python :: split string by length python 
Python :: count gabarit django 
Python :: Multiple Box Plot using Seaborn 
Python :: instagram private account hacking code python 
Python :: python csv reader 
Python :: python requests with login 
Python :: is vowel python 
Python :: plt.plot figure size 
Python :: list of files to zip python 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =