title: How to create lists from objects
body: <p>I have an inventory program which reads lists from an excel file and then creates a class. I want to override new values of objects in the list then I will export the list to excel. Here I import the lists from the excel file</p>
  <pre><code>import pandas as pd
  df = pd.read_excel('stock.xlsx')
  
  inventory_code = df['code'].tolist()
  inventory_name= df['name'].tolist()
  inventory_amount = df['amount'].tolist()
  inventory_unit = df[&quot;birim&quot;].tolist()
  inventory_location=df[&quot;location&quot;].tolist()
  </code></pre>
  <p>And then I create the class</p>
  <pre><code>class Inventory:
      def __init__(self,i_code,i_amount,i_unit,i_location):
          self.i_code=i_code
          self.i_amount=i_amount
          self.i_unit=i_unit
          self.i_location=i_location
      def info(self):
          print(&quot;Product code:&quot;, self.i_code, &quot;Amount:&quot;, self.i_amount, &quot;Unit:&quot;, self.i_unit, &quot;Place:&quot;, self.i_location)
      def add(self, add_amount):
          self.i_amount += add_amount
      def update(self):
          mylist2.append(self.i_amount)
          
  
  for i in range(0,len(inventory_name)):
      globals()[inventory_name[i]]=Inventory(inventory_code[i],inventory_amount[i],inventory_unit[i],inventory_location[i])
  </code></pre>
  <p>Now, I want to create a new list, mylist2 which contains inventory amount as before and the new value of folyo.</p>
  <pre><code>mylist2=[]
  folyo.info()
  folyo.add(999999)
  folyo.update()
  folyo.info()
  
  print(mylist2)
  
  </code></pre>
  <p>In this code, here is the output:</p>
  <pre><code>Product code: 0 Amount: 500 Unit: m2 Place: storage_1
  Product code: 0 Amount: 1000499 Unit: m2 Place: storage_1
  [1000499]
  </code></pre>
  <p>However, my update command saves only the mentioned thing, in this case amount folyo. I want to save all objects. How can I solve this?</p>
  <p>I think that updating only the relevant thing can be a solution. However,  my solution gives only an empty list.</p>
  <pre><code>    def update(self):
          for i in range(0, len(mylist2)):
              if inventory_code[i] == self.i_code:
                  mylist2[i]= self.i_amount
              else:
                  pass
  </code></pre>
  <p>Thank you!</p>
  <p>Solved as below:</p>
  <pre><code>import pandas as pd
  df = pd.read_excel('stock.xlsx')
  
  inventory_code = df['code'].tolist()
  inventory_name= df['name'].tolist()
  inventory_amount = df['amount'].tolist()
  inventory_unit = df[&quot;birim&quot;].tolist()
  inventory_location=df[&quot;location&quot;].tolist()
  
  class Inventory:
      def __init__(self,i_code,i_amount,i_unit,i_location):
          self.i_code=i_code
          self.i_amount=i_amount
          self.i_unit=i_unit
          self.i_location=i_location
  
      def info(self):
          print(&quot;Product code:&quot;, self.i_code, &quot;Amount:&quot;, self.i_amount, &quot;Unit:&quot;, self.i_unit, &quot;Place:&quot;, self.i_location)
  
      def add(self, add_amount):
          self.i_amount += add_amount
  
  
  
      def update(self):
          for i in range(0, len(inventory_name)):
              if inventory_code[i] == self.i_code:
                  mylist2.append(self.i_amount)
              else:
                  mylist2.append(inventory_amount[i])
  
  
  
  for i in range(0,len(inventory_name)):
      globals()[inventory_name[i]]=Inventory(inventory_code[i],inventory_amount[i],inventory_unit[i],inventory_location[i])
  
  
  mylist2=[]
  folyo.info()
  folyo.add(4000)
  folyo.update()
  folyo.info()
  
  print(mylist2)
  
  print(len(inventory_amount))
  print(len(mylist2))
  </code></pre>