1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Bug in PyHelpers?

Discussion in 'Civ4 - SDK/Python' started by Jean Elcard, May 1, 2008.

  1. Jean Elcard

    Jean Elcard The Flavournator

    Feb 26, 2006
    Leipzig, Germany
    My intension is to use this function from PyHelpers.py: getImprovementFoodBonus

    My Code (shortened to the essentials):

    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:

      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 I change that line to:

    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.
  2. EmperorFool

    EmperorFool Deity

    Mar 2, 2007
    Mountain View, California
    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

    from PyInfo import *

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

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

Share This Page