title: Python class and methods - best practice for accessing and altering attributes?
body: <p>TLDR: What's best practice for accessing and altering attributes of a class instance?</p>
  
  <p>Let's say we have a class to generate an object that is intended to hold data about a product (e.g. maybe a product master dataset).</p>
  
  <pre><code>class StoreProduct(object):
  
      def __init__(self,ProductID,ProductPrice,ProductDescription):
          self.ProductID = ProductID
          self.ProductPrice = ProductPrice
          self.ProductDescription = ProductDescription
  
  
      def ChangeProductPrice(self, newProductPrice):
          self.ProductPrice = newProductPrice
  </code></pre>
  
  <p>And we have another class we may be able to use to access those instances generated by StoreProduct(), with methods for making adjustments / changes.</p>
  
  <pre><code>class ChangeProductData(object):
  
      def __init__(self):
          pass
      @staticmethod
      def ChangeProductObjectPrice(newProductPrice,ProductObject):
  
          ProductObject.ProductPrice = newProductPrice
  </code></pre>
  
  <p>So we generate an instance named Product1:</p>
  
  <pre><code>Product1 = StoreProduct(
      ProductID="Product1",
      ProductPrice=4,
      ProductDescription="A nice lamp"
  )
  </code></pre>
  
  <p>What's best practice coding for reading and/or altering class instances?</p>
  
  <p>If I wanted to alter an attribute in Product 1 (in this case the price) is something like this acceptable in general, or is it bad code?</p>
  
  <p><strong>Method 1</strong></p>
  
  <pre><code>ChangeProductData().ChangeProductObjectPrice(8,Product1)
  </code></pre>
  
  <p>Or is this the preferred way to do it?</p>
  
  <p><strong>Method 2</strong></p>
  
  <pre><code>Product1.ChangeProductPrice(2)
  </code></pre>
  
  <p>When might there be exceptions?</p>
  
  <p>While the above are simplified situations, what I've currently read seems to indicate that Method 2 might be better practice. However, wouldn't Method 1 provide greater flexibility in future (e.g. if you need to change how a method works, or add new methods).</p>
  
  <p>I have also been reading into getattr() and setattr(), but people seem to be mixed on whether its better than using dot (e.g. Product1.ProductPrice to get the price).</p>