我试图通过定义游戏的初始化函数(NOT __init__
)来使代码更紧凑,但在调用函数后我无法获得定义的对象在功能里面。
更具体地说,如果我的功能是:
def beginning():
d = Deck()
game_deck = d.thedeck(suit,values)
但是当我运行beginning()
并想要打印d
或game_deck
时,我得到了#34;未定义"
答案 0 :(得分:0)
如果beginning
和d = None
game_deck = None
def beginning():
global d
global game_deck
d = Deck()
game_deck = d.thedeck(suit,values)
是>>> a = [True, False, True, True, False, False, True, True, True]
>>> from itertools import groupby
>>> [list(v) for k,v in groupby([_ if a[_] else None for _ in range(len(a)) ], lambda x: not x is None) if k]
[[0], [2, 3], [6, 7, 8]]
中的局部变量,那么您将无法访问这些函数执行的游戏。相反,尝试在全球范围内声明它们。
aside div {
background: url('http://www.law.kuleuven.be/canon_law/Pictures/staff/pasfoto.jpg/download');
overflow: hidden;
width: 100px;
height: 100px;
border-radius: 50%;
background-size: cover;
background-repeat: no-repeat;
-webkit-transition: 0.2s;
margin: 0 auto;
position: relative;
top: -50px;
}
aside div:hover {
padding: 0;
width: 110px;
height: 110px;
}
aside section {
position: absolute;
text-align: center;
width: 300px;
height: 500px;
background: #fff;
}