Bug in PyHelpers?

Jean Elcard

The Flavournator
Joined
Feb 26, 2006
Messages
1,008
Location
Leipzig, Germany
My intension is to use this function from PyHelpers.py: getImprovementFoodBonus

My Code (shortened to the essentials):

Code:
import PyHelpers

PyInfo = PyHelpers.PyInfo

#some function calling another function of the same module:

iYieldChange = PyInfo.BonusInfo(iBonusType).getImprovementFoodBonus()

#do something with the result
If I run this, I get this Python Exception:

Code:
  File "FlavourMod", line 268, in normalizeStartingPlotLocations
  File "FlavourMod", line 387, in evaluateStartingPlot
  File "PyHelpers", line 1181, in getImprovementFoodBonus
  File "PyHelpers", line 1172, in getImprovementModifierInfo
  File "PyHelpers", line 1015, in getAPrereqImprovementID
  File "PyHelpers", line [B]1010[/B], in getPrereqImprovementID

NameError: global name 'ImprovementInfo' is not defined

Line 1010 in PyHelpers is looking like this:

if self.ID in ImprovementInfo(i).getAffectedBonusIDList():

If I change that line to:

if self.ID in PyInfo.ImprovementInfo(i).getAffectedBonusIDList():

I get a similar error like the one before for another line, but if I add PyInfo. to this line too, everything is working like intended.

Is this a bug in PyHelper or am I doing something wrong in my code? I don't want to change anything in PyHelper itself to get this to work. I could easily rewrite the PyHelpers function, but why should I reinvent the wheel.
 
Yes, it looks like you've found 2 bugs in PyHelpers. It clearly needs the reference to PyInfo for those names. AFAIK, and I'm fairly new to Python myself, you cannot make names available to other modules from your module. Only the module itself can determine the names it has available, like PyInfo (which it imports) and PyInfo.ImprovementInfo (which PyInfo defines).

If PyHelpers had done

PHP:
from PyInfo import *
or

PHP:
from PyInfo import ImprovementInfo
then ImprovementInfo could be referenced by itself in PyHelpers. But with the default import statement

PHP:
import PyInfo
Python only makes the names defined in PyInfo available by prefixing them with the name of their module ("PyInfo.") as you found.
 
Top Bottom