fopp icon indicating copy to clipboard operation
fopp copied to clipboard

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

Open paccattam opened this issue 6 years ago • 7 comments

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 avatar Aug 18 '19 12:08 paccattam

@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

EzraSkwarka avatar Oct 02 '19 17:10 EzraSkwarka

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 avatar Oct 02 '19 17:10 bnmnetp

fileref.readlines is not wrong its just not necessary.

bnmnetp avatar Oct 02 '19 17:10 bnmnetp

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

presnick avatar Oct 02 '19 19:10 presnick

Issued a pull request

EzraSkwarka avatar Oct 09 '19 18:10 EzraSkwarka

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

dbrucknr avatar Dec 01 '19 23:12 dbrucknr

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

bnmnetp avatar Dec 02 '19 01:12 bnmnetp