This repository was archived by the owner on May 11, 2018. It is now read-only.
[docs] Context managers, file.writelines, etc
#20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
file.writelinesinstead offile.writefor each linewithstatement context managers instead of manually closing each filetry/exceptinsidemainto unpack the threesys.argvarguments (raiseValueErrorif not enough/too many arguments)gosecure_client_installwhere only one argument is neededI noticed quite a few blocks of code like this and thought it might be inefficient.
It seemed odd to iterate through each separate line of
fand check for the exact same string. I set up a small test to get an idea of how long it took compared to just searchingf.read()for the one string.To test the worst case scenario, I created a 1000 line file where the word "treasure" was at the end of the very last line. Using
content = f.read()and searching for that one string was around 3 times faster every time I checked it.I went through and changed the format of each of these instances to search for the desired string in the
f.read()string.