Note that there are some explanatory texts on larger screens.

plurals
  1. POWeird bug in python project
    primarykey
    data
    text
    <p>I'm working on a big project in Python, and I've run into a bizarre error I can't explain. In one of my classes, I have a private method being called during instantiation:</p> <pre><code>def _convertIndex(self, dimInd, dimName): '''Private function that converts numbers to numbers and non-integers using the subclass\'s convertIndex.''' print dimInd, ' is dimInd' try: return int(dimName) except: if dimName == '*': return 0 else: print self.param.sets, ' is self.param.sets' print type(self.param.sets), ' is the type of self.param.sets' print self.param.sets[dimInd], ' is the param at dimind' return self.param.sets[dimInd].value(dimName) </code></pre> <p>What it's printing out:</p> <pre><code>0 is dimInd [&lt;coremcs.SymbolicSet.SymbolicSet object at 0x10618ad90&gt;] is self.param.sets &lt;type 'list'&gt; is the type of self.param.sets &lt;SymbolicSet BAZ=['baz1', 'baz2', 'baz3', 'baz4']&gt; is the param at dimind ====================================================================== ERROR: testParameterSet (GtapTest.TestGtapParameter) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/myuser/Documents/workspace/ilucmc/gtapmcs/test/GtapTest.py", line 116, in testParameterSet pset = ParameterSet(prmFile, dstFile, GtapParameter) File "/Users/myuser/Documents/workspace/ilucmc/coremcs/ParameterSet.py", line 103, in __init__ self.distroDict, corrDefs = AbsBaseDistro.readFile(distFile, self.paramDict) File "/Users/myuser/Documents/workspace/ilucmc/coremcs/Distro.py", line 359, in readFile distro = cls.parseDistro(param, target, distroType, args) File "/Users/myuser/Documents/workspace/ilucmc/coremcs/Distro.py", line 301, in parseDistro return cls(param, target, distro, dim_names, argDict) File "/Users/myuser/Documents/workspace/ilucmc/coremcs/Distro.py", line 150, in __init__ self.dim_indxs = list(starmap(self._convertIndex, enumerate(dim_names))) # convert to numeric values and save in dim_indxs File "/Users/myuser/Documents/workspace/ilucmc/coremcs/Distro.py", line 194, in _convertIndex print self.param.sets[dimInd], ' is the param at dimind' IndexError: list index out of range </code></pre> <p>Obviously this isn't the code for the whole class, but it represents something that I don't understand. The error is coming when I index into self.param.sets. Apparently, dimInd is out of range. the problem is, dimInd is 0, and self.param.sets is a list of length 1 (as shown from the print statements), so why can't I index into it? </p> <p>EDIT: For what it's worth, the <code>__init__</code> method looks like this:</p> <pre><code>''' Stores a definitions of a distribution to be applied to a header variable. See the file setup/gtap/DistroDoc.txt for the details. ''' def __init__(self, param, target, distType, dim_names, argDict): self.name = param.name self.dim_names = dim_names self.dim_indxs = [] self.target = target.lower() if target else None self.distType = distType.lower() if distType else None self.rv = None self.argDict = {} self.modifier = defaultdict(lambda: None) self.param = param # Separate args into modifiers and distribution arguments for k, v in argDict.iteritems(): if k[0] == '_': # modifiers start with underscore self.modifier[k] = v else: self.argDict[k] = v # distribution arguments do not have underscore if self.target == 'index': print dim_names self.dim_indxs = list(starmap(self._convertIndex, enumerate(dim_names))) # convert to numeric values and save in dim_indxs if distType == 'discrete': entries = self.modifier['_entries'] if not entries: raise DistributionSpecError("Not enough arguments given to discrete distribution.") modDict = {k[1:]: float(v) for k, v in self.modifier.iteritems() if k[1:] in getOptionalArgs(DiscreteDist.__init__)} self.rv = DiscreteDist(entries, **modDict) return sig = DistroGen.signature(distType, self.argDict.keys()) gen = DistroGen.generator(sig) if gen is None: raise DistributionSpecError("Unknown distribution signature %s" % str(sig)) self.rv = gen.makeRV(self.argDict) # generate a frozen RV with the specified arguments self.isFactor = gen.isFactor </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload