【问题标题】:How to stop a class halfway, to run the next class, and how to do so? [closed]怎么中途停课,跑下一节课,怎么做? [关闭]
【发布时间】:2015-12-04 17:49:40
【问题描述】:

我在互联网上搜索并找不到解决方案。请帮忙。 比方说……

class A(self):
    def __init__ (self):
        """one chunk of code here"""

    if (condition met):
        print 'access granted'
        """I want to stop the code here and ask it to run class B, instead of just one method from class B"""
    else:
        print 'Stop process'
        break

class B(self):
    def __init__ (self):
        """one more chunk of codes here"""

这可能吗? (原谅我乱七八糟的代码)

【问题讨论】:

  • 你没有“运行”一堂课。你运行函数。
  • 好像是 XY 问题,你打算怎么做?

标签: python class call


【解决方案1】:

当您运行该脚本时,您的 if 条件代码只会运行一次。每当您创建类的实例时,只会运行 __init__ 函数。正如interjay 所提到的,您运行的不是类,而是函数。

【讨论】:

    猜你喜欢
    • 2021-08-07
    • 1970-01-01
    • 2014-02-28
    • 2021-12-08
    • 2011-05-24
    • 1970-01-01
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    相关资源
    最近更新 更多