More pythonic error handling, remove class-global variables#3
Open
VegarS wants to merge 1 commit intomiguelmoreto:masterfrom
VegarS:master
Open
More pythonic error handling, remove class-global variables#3VegarS wants to merge 1 commit intomiguelmoreto:masterfrom VegarS:master
VegarS wants to merge 1 commit intomiguelmoreto:masterfrom
VegarS:master
Conversation
- Remove class-global variables to allow using multiple instances of ComtradeRecord - Remove unnecessary prints - Use exceptions to indicate errors, not print
miguelmoreto
approved these changes
Sep 21, 2016
Owner
miguelmoreto
left a comment
There was a problem hiding this comment.
Thanks for your suggestions. I just would like to know more about the removal of class-global variables. Why it is not a good practice? Best regards!
| else: | ||
| print "%s File not found." %(filename) | ||
| return | ||
| raise Exception("{}: File not found.".format(filename)) |
Owner
There was a problem hiding this comment.
Thanks for that! I didn't know about this technique.
| ft = '' | ||
| # Time stamp multiplication factor: | ||
| timemult = 0.0 | ||
| DatFileContent = '' |
Owner
There was a problem hiding this comment.
I would like to know why this removal will allow using multiple instances of
ComtradeRecord, otherwise is not possible?
Author
There was a problem hiding this comment.
Class-global variables share their values across all instances of the class.
For example, if you were to read two files like this
a = ComtradeRecord('a.cfg')
b = ComtradeRecord('b.cfg')a.filename and b.filename would have the same value (b.cfg), along with all other class-global variables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
ComtradeRecord