Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python get lines from text file

def get_lines(file_name: str) -> [str]:
    """
    This function returns the lines from the file as a list.
    It handles the opening and closing of the file.
    Also, the function assumes the file exists and can be read.
    """
    with open(file_name, 'r') as f:
        lines = f.readlines()
    return lines

# How to use:
lines = get_lines('my_file.txt')
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #lines #text #file
ADD COMMENT
Topic
Name
4+7 =