title: How do I loop through functions with similar names in python?
body: <p>If I have different functions with increasing numbers in their names how do I loop through them? For example:</p>
  
  <pre><code>def Func1():
      something something
  
  def Func2():
      something something
  
  def Func3():
      something something
  
  ...
  
  def Func456832():
      something something
  
  def Func456833():
      something something
  </code></pre>
  
  <p>How can I loop through them with a:</p>
  
  <pre><code>for i in range(1,456833):
  </code></pre>
  
  <p>In essence it's this question:
  <a href="https://stackoverflow.com/questions/25427325/how-do-i-loop-through-functions-with-a-for-loop">How do I loop through functions with a for loop?</a></p>
  
  <p>Edit: Because so many asked, this is my real code:</p>
  
  <pre><code>def write(self):
      with open('distances.txt', 'a') as file:
          file.write('\n'+str(self.distance1))
          file.write('\n'+str(self.distance2))
          file.write('\n'+str(self.distance3))
          file.write('\n'+str(self.distance4))
          file.write('\n'+str(self.distance5))
          file.write('\n'+str(self.distance6))
          file.write('\n'+str(self.distance7))
          file.write('\n'+str(self.distance8))
          file.write('\n'+str(self.distance9))
          file.write('\n'+str(self.distance10))
          file.write('\n'+str(self.distance11))
          file.write('\n'+str(self.distance12))
          file.write('\n'+str(self.distance13))
          file.write('\n'+str(self.distance14))
          file.write('\n'+str(self.distance15))
  </code></pre>
  
  <p>I realised this was a pretty shitty way of getting it done, especialy if I wanted to keep expanding the list. So I went looking for the answer and this seemed to be what I needed to know in order to fix it.</p>
  
  <p>Edit2: Where I get the self.distanceX from:</p>
  
  <pre><code>class NeuralNetwork():
       def __init__(self, inputs, hidden1, hidden2, hidden3, outputs, alpha,it_1,it_2,it_3,it_4,it_5):
  
      ....
  
      self.distance1 = [alpha,hidden1,it_1,'train',0,0,0,0,0]
      self.distance2 = [alpha,hidden1,it_1,'test',0,0,0,0,0]
      self.distance3 = [alpha,hidden1,it_1,'dist',0,0,0,0,0]
      self.distance4 = [alpha,hidden1,it_2,'train',0,0,0,0,0]
      self.distance5 = [alpha,hidden1,it_2,'test',0,0,0,0,0]
      self.distance6 = [alpha,hidden1,it_2,'dist',0,0,0,0,0]
      self.distance7 = [alpha,hidden1,it_3,'train',0,0,0,0,0]
      self.distance8 = [alpha,hidden1,it_3,'test',0,0,0,0,0]
      self.distance9 = [alpha,hidden1,it_3,'dist',0,0,0,0,0]
      self.distance10 = [alpha,hidden1,it_4,'train',0,0,0,0,0]
      self.distance11 = [alpha,hidden1,it_4,'test',0,0,0,0,0]
      self.distance12 = [alpha,hidden1,it_4,'dist',0,0,0,0,0]
      self.distance13 = [alpha,hidden1,it_5,'train',0,0,0,0,0]
      self.distance14 = [alpha,hidden1,it_5,'test',0,0,0,0,0]
      self.distance15 = [alpha,hidden1,it_5,'dist',0,0,0,0,0]
  </code></pre>
  
  <p>Edit: solved. Thanks everyone :)</p>