Skip to content

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#3
VegarS wants to merge 1 commit intomiguelmoreto:masterfrom
VegarS:master

Conversation

@VegarS
Copy link
Copy Markdown

@VegarS VegarS commented Aug 7, 2015

  • Remove class-global variables to allow using multiple instances of
    ComtradeRecord
  • Remove unnecessary prints
  • Use exceptions to indicate errors, not print

- Remove class-global variables to allow using multiple instances of
ComtradeRecord
- Remove unnecessary prints
- Use exceptions to indicate errors, not print
Copy link
Copy Markdown
Owner

@miguelmoreto miguelmoreto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Comment thread src/pyComtrade.py
else:
print "%s File not found." %(filename)
return
raise Exception("{}: File not found.".format(filename))
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for that! I didn't know about this technique.

Comment thread src/pyComtrade.py
ft = ''
# Time stamp multiplication factor:
timemult = 0.0
DatFileContent = ''
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to know why this removal will allow using multiple instances of
ComtradeRecord, otherwise is not possible?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants