RunestoneInteractive / fopp

Foundations of Python Programming
https://runestone.academy/runestone/static/fopp/index.html
37 stars 120 forks source link

Code error on page "10.7. Recipe for Reading and Processing a File" #236

Open paccattam opened 5 years ago

paccattam commented 5 years ago

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

EzraSkwarka commented 4 years ago

@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

bnmnetp commented 4 years ago

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
bnmnetp commented 4 years ago

fileref.readlines is not wrong its just not necessary.

presnick commented 4 years ago

It should be lin rather than line, to be compatible with the previous example on the page.

EzraSkwarka commented 4 years ago

Issued a pull request

dbrucknr commented 4 years ago

Just checking in on this issue. It appears a fix has been initiated. Can this issue/ticket be closed?

bnmnetp commented 4 years ago

Still waiting for some changes to the PR, we can close as soon as the PR is accepted.