web2py FPDF 子类和 super()
web2py FPDF subclass and super()
Python 2.7
又一个新式 class 问题...但不是。
我看了其他的问题,结果好像是相反的,但那可能是我的无知。
class t1(object):
pass
c1 = t1()
print type(c1) # <class '__main__.t1'> within web2py <class '__restricted__.t1>
class t2():
pass
c2 = t2()
print type(c2) # <type 'instance'>
好的。太棒了,我不必通过 'object' 来获得新样式 classes(或者我错过了什么)。
因此,当我 subclass 一些应该是新样式 class 的东西(即在声明中传递了 'object' )时,我得到一个 class 对象,我无法通过在我的 class 声明中传递 'object'。
现在说说我的具体情况:
我正在 subclassing 声明为 class FPDF(object) 的 FPDF,并尝试在我的声明中使用 super 函数。
class MyFPDF(FPDF):
def __init__(self, data):
super(MyFPDF, self).__init__()
self.res = data['res'] # reseller info
self.cust = data['customer'] # customer info
super(MyFPDF, self).__init__()
TypeError: super() argument 1 must be type, not function
我在任何地方都找不到对这个特定错误的引用。
更新
# -*- coding: utf-8 -*-
from fpdf import FPDF, HTMLMixin
import datetime
import os
import codecs
import PIL
@auth.requires_login()
class MyFPDF(FPDF, HTMLMixin):
# cutoff to start the next page. Not using auto page break.
cutoff = 275
footerLineheight = 3
footerFontSize = 6.5
footerTextColor = 128
def __init__(self, data):
super(MyFPDF, self).__init__()
self.res = data['res'] # reseller info
self.cust = data['customer'] # customer info
def pdfDoc():
data = _select_offer(offerId) # data.offer data.customer
data['res'] = db.reseller[data.offer.reseller_id] # data.res
pdf = MyFPDF(data)
pdf.add_page() # from here is the code for the pdf document
我覆盖 init() 的唯一原因是我可以传递页脚的地址信息。我不能将它直接传递给我的页脚方法,因为该方法在模块内部使用。所以添加参数会导致其他问题。
我刚刚算出来了。
问题是 class 声明中不必要的装饰器 @auth.requires_login()。
Python 2.7
又一个新式 class 问题...但不是。
我看了其他的问题,结果好像是相反的,但那可能是我的无知。
class t1(object):
pass
c1 = t1()
print type(c1) # <class '__main__.t1'> within web2py <class '__restricted__.t1>
class t2():
pass
c2 = t2()
print type(c2) # <type 'instance'>
好的。太棒了,我不必通过 'object' 来获得新样式 classes(或者我错过了什么)。 因此,当我 subclass 一些应该是新样式 class 的东西(即在声明中传递了 'object' )时,我得到一个 class 对象,我无法通过在我的 class 声明中传递 'object'。
现在说说我的具体情况: 我正在 subclassing 声明为 class FPDF(object) 的 FPDF,并尝试在我的声明中使用 super 函数。
class MyFPDF(FPDF):
def __init__(self, data):
super(MyFPDF, self).__init__()
self.res = data['res'] # reseller info
self.cust = data['customer'] # customer info
super(MyFPDF, self).__init__()
TypeError: super() argument 1 must be type, not function
我在任何地方都找不到对这个特定错误的引用。
更新
# -*- coding: utf-8 -*-
from fpdf import FPDF, HTMLMixin
import datetime
import os
import codecs
import PIL
@auth.requires_login()
class MyFPDF(FPDF, HTMLMixin):
# cutoff to start the next page. Not using auto page break.
cutoff = 275
footerLineheight = 3
footerFontSize = 6.5
footerTextColor = 128
def __init__(self, data):
super(MyFPDF, self).__init__()
self.res = data['res'] # reseller info
self.cust = data['customer'] # customer info
def pdfDoc():
data = _select_offer(offerId) # data.offer data.customer
data['res'] = db.reseller[data.offer.reseller_id] # data.res
pdf = MyFPDF(data)
pdf.add_page() # from here is the code for the pdf document
我覆盖 init() 的唯一原因是我可以传递页脚的地址信息。我不能将它直接传递给我的页脚方法,因为该方法在模块内部使用。所以添加参数会导致其他问题。
我刚刚算出来了。 问题是 class 声明中不必要的装饰器 @auth.requires_login()。