文件“<template>”</template>中的Python脚本中的TypeError

时间:2014-02-18 23:33:21

标签: python

我是Python的新手,并继承了一个引用其他脚本和模块的脚本。当我从Windows命令提示符运行它时,我遇到以下消息:

  

文件"<template>",第37行,位于顶级模板代码中   TypeError:需要浮点参数,而不是str

我想对此进行问题排查,但我不知道"<template>"引用了哪个.py文件。

主文件的代码如下:

from markdown import markdown
import flowerpoint
from re import sub
from HTMLParser import HTMLParser
from os.path import abspath
from os import getcwd
from time import sleep
import jinja2
from jinjaFunctions import jinjaFunctions

class FlowerParser:

    template = None
    outputFile = None
    mdHtml = None
    jinjaHtml = None

    class FlowerHTMLParser(HTMLParser):
        from flowertags import FlowerTags

        curTextbox = None
        slideInitialized = False

        justAddedParagraph = True
        curFont = flowerpoint.PPTextFormat()
        tags = None

        excelMode = False
        excelWorkbooks = {}

        def _getWorkbook(self, workbookName):
            wkbk = self.excelWorkbooks.get(workbookName, None)
            if wkbk:
                return wkbk
            else:
                raise Exception("Workbook not found: %s" % workbookName)

        def handle_starttag(self, tag, attrs):
            self.tags.handleTag(tag, attrs, True)

        def handle_endtag(self, tag):
            self.tags.handleTag(tag, None, False)

        def handle_data(self, data):
            #self.addText(sub(" +"," ",sub("\n"," ",data)))
            self.addText(sub(" +"," ",sub("\n|\r","",sub("\n(?!$)"," ",data))))

        def addText(self, text, format=True, isSpace=False):
            if len(text) == 0:
                return
            self.justAddedParagraph = isSpace
            if self.slideInitialized and self.curTextbox is not None:
                if format:
                    flowerpoint.addText(self.curTextbox, text, self.curFont)
                else:
                    flowerpoint.addText(self.curTextbox, text, None)

        def __init__(self):
            HTMLParser.__init__(self)
            self.tags = self.FlowerTags(self)

        def __init__(self, inputFile, template, outputFile):
            self.template = template
            self.outputFile = outputFile
                with open(inputFile,"r") as mdInputFile:
                    jinjaEnv = jinja2.Environment()
                    jinjaEnv.globals.update(zip=zip, int=int, float=float)
                    jinjaTemplate = jinjaEnv.from_string(mdInputFile.read())
                    jinjaTemplate = jinjaTemplate.render(**jinjaFunctions)

                    self.jinjaHtml = jinjaTemplate
                    print self.jinjaHtml
                    self.mdHtml = sub("&gt;",">",sub("&lt;","<", markdown(jinjaTemplate)))

                    print self.mdHtml

        def run(self):
            flowerpoint.loadFromTemplate(self.template, self.outputFile)
            parser = self.FlowerHTMLParser()
            parser.flowerpoint = flowerpoint
            parser.feed(self.mdHtml)
            flowerpoint.close()

1 个答案:

答案 0 :(得分:0)

事实证明,程序正在调用markdown文件。该降价文件的第37行是:

{{'%.f' %  getCell(excelFile, 'Count', 16, 13)}} Temporary staffing<br>

这预期有一个浮点参数,但引用的单元格(位置16,13)是空白的,因此不是浮点数。这产生了错误。