fopp
fopp copied to clipboard
Code error on page "10.7. Recipe for Reading and Processing a File"
The following code snippet given in the end of the text @ the link given below should have mentioned fire opbject reference instead of "lines" https://fopp.umsi.education/runestone/static/fopp/Files/FilesRecipe.html
fname = "yourfile.txt" with open(fname, 'r') as fileref: # step 1 for lin in lines: # step 2 ## some code that reference the variable lin #some other code not relying on fileref # step 3
@paccattam I'm not entirely sure what you are asking us to do, can you clarify a little bit?
Are you saying the 2nd snippet should be:
fname = "yourfile.txt"
with open(fname, 'r') as fileref: # step 1
for lin in fileref.readlines(): # step 2
## some code that reference the variable lin
#some other code not relying on fileref # step 3
The example should be:
with open(fname, 'r') as fileref:
for line in fileref:
## some code that uses line as the current line of the file
## some more code
fileref.readlines is not wrong its just not necessary.
It should be lin rather than line, to be compatible with the previous example on the page.
Issued a pull request
Just checking in on this issue. It appears a fix has been initiated. Can this issue/ticket be closed?
Still waiting for some changes to the PR, we can close as soon as the PR is accepted.