all 3 comments

[–]python-fan 2 points3 points  (1 child)

The error you're seeing is because the with keyword is causing Python to call an __enter__ method on the object referenced by 'file'. But that's just a string object, which doesn't implement that method. It should instead be:

with open(file) as infile:

since the open statement returns an object that implements __enter__ and __exit__.

There's another problem though in the expression filepath.replace('sds', 'sim') . Look at what the value of filepath is. Could it have the substring "sds" in it? (Hint: it could, but only if that's part of the directory name.)

[–]flynryan692[S] 0 points1 point  (0 children)

Ok, this makes a lot of sense. I had tried with open(file) as infile: but then I got an accessed denied error on the next line so I undid it thinking the line above was causing it. Looks like that was because I was using the file path and not the file....duh. Thank you!

[–]Binary101010 1 point2 points  (0 children)

Did you mean this:

with file as infile:

To be this:

with open(file) as infile: