user interface - python program structure and use of global variables -
i have program completed following:
1)reads formatted data (a sequence of numbers , associated labels) serial port in real time.
2)does minor manipulations data. 3)plots data in real time in gui wrote using pyqt. 4)updates data stats in gui. 5)allows post analysis of data after collection stopped.
there 2 dialogs (separate classes) called within main window in order select preferences in plotting , statistics.
my question following: right data read in , declared several global variables appended data comes in 20x per second or - 2d list of values numerical values , 1d lists various associated text values. better create class in store data , various attributes, , use instances of data class make else happen - plotting of data , statistics associated it?
i have hunch answer yes, need bit of guidance on how make happen if best way forward. instance, every single datum new instance of data class? pass them 1 one or list of instances other classes , methods? how should passing elegantly done?
if i'm not being specific enough, please let me know other information me answer.
a reasonably rule of thumb if doing needs more 20 lines of code worth considering using object oriented design rather global variables, , if 100 lines should using classes. purists never use globals imho simple linear script overkill.
be warned lot of answers expressing horror not already.
there good, (and of them free), books introduce object oriented programming in python quick google should provide need.
added comments answer preserve them:
so @ 741 lines, i'll take yes oop:) on data class. correct create new instance of data class 20x per second data strings come in, or more appropriate append data list of existing instance of class? or there no clear preference either way? – timob
i append/extend existing instance. – seth
i think see light now. can instantiate data class when "start data" button pressed, , append instance in subsequent thread serial reading. thanks! – timob
Comments
Post a Comment