Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In the document catalogue.py, likely including like .py files for the same homework, in the def saveCountryCatalogue(self,fname): why are 2 instance variables, _countrySorted and _sortName,
In the document catalogue.py, likely including like .py files for the same homework, in the def saveCountryCatalogue(self,fname): why are 2 instance variables, _countrySorted and _sortName, created if they serve no purpose in the function? _sortName is used however it appears to be just as a counter even though we are supposed to sort the data it is never stored and thus useless.
#saving the data def saveCountrycatalogue (self, fname ): try : countrySorted = {} sortName = for name in self._countrycat: sortName . append (name ) #sort through the name sortName . sort ( ) #loop through the names, then find the country and storing the information in the sorted country dictionry #create a new file and write data to it _newCountryFile = open(fname, "w") _newCountryFile. write("Country |Continent | Population |Area" ) _newCountryFile .write("\\") for c in _sortName: if c in self._countrycat: name = c pop = str (self ._countrycat[c] . getpopulation( ) ) area = str (self._countrycat[c]. getArea( ) ) cont = self._countrycat [c] . getcontinent ( ) #print (name + "|" + cont + "|" + pop + "|" + area) _newCountryFile . write(name + "|" + cont + "|" + pop + "|" + area) newCountryFile. write("\\") continue newCountryFile. close ( ) return len(_countrysorted) except : return - 1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started