title: Python: Cannot import name/IndexError: List index out of range
body: <p>I'm still pretty new to Python, and I didn't write most of this code, I'm just trying to get it to work. I have the following two .py files:</p>
  
  <p>This one is called FnSim.py-</p>
  
  <pre><code>import numpy,sys, os
  import math
  
  
  
  def intFn(kVars,params): # Do not change the name of this function
  
  sinTh = kVars['y']/(numpy.sqrt(kVars['y']**2+(1000.)**2))
  I = 4*((numpy.sin((numpy.pi*.7*sinTh)/.0006)/((.7*sinTh)/.0006))**2)*numpy.cos((numpy.pi*1.2*sinTh)/.0006)**2
  if not math.isnan(I):
      return I
  else:
      print 'Hello'
      return 0.0
  '''
  sinTh = kVars['y']/(numpy.sqrt(kVars['y']**2+(params['R0'])**2))
  A1 = numpy.complex(params['A1r'],params['A1i'])*numpy.e**(((-numpy.pi*params['p']*sinTh)/.0006)*1j)
  A2 = numpy.complex(params['A2r'],params['A2i'])*numpy.e**(((numpy.pi*params['p']*sinTh)/.0006)*1j)
  return (A1+A2)*numpy.conjugate(A1+A2)
  '''
  def simFn():
  """
      This is the function that will do the actual simulating. Fill out the filepaths below.
  """
  
  nTrueDir="./data/nTrueSF.npy"#Location to save the nTrue File
  inputKVDir="./data/flatY.txt"#Loaction of the Generated MC KV text File
  outputWeightDir="./data/wnListSF.npy"#Location where the weighted mask file will be saved
  
  iList = numpy.load("./data/iListSF.npy")#Location of the list of intensities. 
  
  iMax = iList.max()
  print iMax         
  gS.simulate(nTrueDir,inputKVDir,outputWeightDir,iList,iMax)
  
  
  from generalSim import generalSim
  inputKVDir="./data/FlatY.txt"#Loaction of the Generated MC KV File(Same as above)
  gS = generalSim(KVDir = inputKVDir)
  if sys.argv[1] == "i":
  numpy.save("./data/iListSF.npy",gS.calcIList({'A2r': 186.55622562665766, 'R0': 1000.0, 'A1r': 186.5549385015023, 'p': 1.2010987369259563, 'A2i': 0.0, 'A1i': 0.4681942082158097}))
  elif sys.argv[1] == "s":
  simFn()
  </code></pre>
  
  <p>This one is called generalSim.py-</p>
  
  <pre><code>import numpy
  import os, sys
  import fileinput
  from FnSim import intFn
  from random import random
  
  class generalSim (object):
  
  def __init__(self,KVDir):
      self.KVDir = KVDir
  
  def calcIList(self,params): 
      n = 0 
      iList = numpy.zeros(shape = (1))
      for line in fileinput.input([self.KVDir]): 
          iList.resize(n+1)       
          kvAs = line.split(",")
          kvAx = {kvA.split('=')[0]:float(kvA.split('=')[1]) for kvA in kvAs}
          iList[n] = intFn(kvAx,params)
          sys.stdout.write(str(n)+"\r")
          sys.stdout.flush()
          n+=1
  
      return iList
  
  def simulate(self,nTrueDir,inputKVDir,outputWeightDir,iList,iMax):
  
      nTrueList = [((1.0/(iList.shape[0]))*(iList.sum(0)))]  
      numpy.save(nTrueDir,nTrueList)
  
      wList=iList[:]/iMax
  
      wnList=numpy.zeros(shape=(wList.shape[0]))
  
      for wn in range(len(wList)):            
          if wList[wn]&gt;random():                
              wnList[wn] = 1 
  
      numpy.save(outputWeightDir,wnList)
  </code></pre>
  
  <p>I also have a text file called FlatY.txt in a folder labeled 'data'. The FlatY.txt contains one million lines of Y values.</p>
  
  <p>I need to run the files so that I can create the .npy files listed in the FnSim.py. I don't know Linux very well, but my intention is to have the files placed in the 'data' folder. However, if I try to compile FnSim.py, the console shows this:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "FnSim.py", line 38, in &lt;module&gt;
  
      from generalSim import generalSim
  
    File "/home/gendreau/workspace/generalSim.py", line 5, in &lt;module&gt;
  
      from FnSim import intFn
  
    File "/home/gendreau/workspace/FnSim.py", line 38, in &lt;module&gt;
  
      from generalSim import generalSim
  
  ImportError: cannot import name generalSim
  </code></pre>
  
  <p>When I try to run generalSim.py, I get this:</p>
  
  <pre><code>Traceback (most recent call last):
  
    File "generalSim.py", line 5, in &lt;module&gt;
  
      from FnSim import intFn
  
    File "/home/gendreau/workspace/FnSim.py", line 41, in &lt;module&gt;
  
      if sys.argv[1] == "i":
  
  IndexError: list index out of range
  </code></pre>
  
  <p>What can fix to resolve these problems and generate the necessary files?</p>