Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I am getting that exception from this code:

class Transaction:

  def __init__ (self):

    self.materials = {} 

  def add_material (self, m): 

    self.materials[m.type + m.purity] = m 

  def serialize (self): 

    ser_str = 'transaction_start\n' 

  for k, m in self.materials:

    ser_str += m.serialize () 

  sert += 'transaction_end\n'

  return ser_str

The for line is the one throwing the exception. The ms is Material objects. Anybody have any ideas why?

1 Answer

0 votes
by (106k points)
edited by

Use the following code to get rid of this error:-

for k, m in self.materials.items():

example:

miles_dict = {'Monday':1, 'Tuesday':2.3, 'Wednesday':3.5, 'Thursday':0.9} 

for k, v in miles_dict.items():

  print("%s: %s" % (k, v))

To know more about this you can have a look at the following video tutorial:-

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...