0

次のコードを考えてみましょう。

def myDecorator(func):
  def wrapper(self):
    try:
      func(self)
    except Exception as e:
      print "The argument of the function was:" # print "Some Text"
      raise
  wrapper.__name__ = funct.__name__
  return wrapper


@myDecorator
def do_something(self):
  do_something_again("Some text")

私の質問は次のとおりです。関数「do_something_again」に与えられた引数を「except」ブロック内に表示するにはどうすればよいですか?

4

1 に答える 1

0

印刷str(e)して追加情報を入手してください。あなたの場合の例:

def myDecorator(func):
  def wrapper(self):
    try:
      func(self)
    except Exception as e:
      print "The argument of the function was:", str(e)
      raise
  wrapper.__name__ = funct.__name__
  return wrapper
于 2013-03-06T15:13:56.297 に答える