Changes

Jump to: navigation, search

OPS435 Python Lab 5

215 bytes added, 07:00, 5 September 2017
Create a Python Script Demonstrating Reading Files
print(line, end='')
f.close()
</source>:#The <br>We can improve upon the previous coding sequence by using the '''strip()''' function. In the previous coding example, the python ''print() '' function by default adds the new-line character to the end of the line. Using the ''end='''' argument used in print replaces the '\n' at the end with nothing ''. This allows the print() to use the new-line characters found on each line of the file that was read. Though (if desired ) you can always strip the new-line characters from any lines. The strip() function will remove all leading and trailing whitespacewhite-space, which may help in processing some lines or data.<br><br>:#To demonstrate, issue the following code sequence:<source lang="python">
f = open('data.txt', 'r')
for line in f:
</source>
:::*The '''read_file_string() ''' function should return a string:::*The '''read_file_list() ''' function should return a list:::*The '''read_file_list() ''' function must remove the new-line characters from each line in the list:::*Both functions must accept '''one argument ''' which is a string
:::*The script should show the exact output as the samples
:::*The script should contain no errors
13,420
edits

Navigation menu