我想打电话给母班,但我得到这样的信息:
Traceback (most recent call last):
File "***test.py", line 23, in <module>
for i in daughter:
File "***test.py", line 18, in __iter__
for i in super(Mother, self):
TypeError: 'super' object is not iterable
Run Code Online (Sandbox Code Playgroud)
我认为这只是语法,我试着在没有任何方法的情况下调用超级(母亲,自己),只是对象本身.这里的代码:
class Mother(object):
def __init__(self, upperBound):
self.upperBound = upperBound
def __iter__(self):
for i in range (self.upperBound):
yield i
class Daughter(Mother):
def __init__(self, multiplier, upperBound):
self.multiplier = multiplier
super(Daughter, self).__init__(upperBound)
def __iter__(self):
for i in super(Mother, self): # Here
yield i * self.multiplier
daughter = Daughter(2, …Run Code Online (Sandbox Code Playgroud) 我无法访问我的env var:
import subprocess, os
print os.environ.get('PATH') # Works well
print os.environ.get('BONSAI') # doesn't work
Run Code Online (Sandbox Code Playgroud)
但是env var在我的中添加得很好/home/me/.bashrc:
BONSAI=/home/me/Utils/bonsai_v3.2
export BONSAI
Run Code Online (Sandbox Code Playgroud)
我可以从一个新的终端访问这个env var.
如何同时执行除法和模数.处理器有可能吗?
喜欢 :
int a, b = 8 / 3; //a = 2, b = 2
Run Code Online (Sandbox Code Playgroud)
或者是否有比以下更好的操作:
int a = 8 / 3;
int b = 8 % 3;
Run Code Online (Sandbox Code Playgroud)
也许这更好?
int a = 8 / 3;
int b = 8 - a * 3;
Run Code Online (Sandbox Code Playgroud)
谢谢.
在这里我得到一个关键错误,即使我检查密钥是否存在于dict中:
def foo(d):
if (('element' in d.keys()) & (d['element'] == 1)):
print "OK"
foo({})
Run Code Online (Sandbox Code Playgroud)
在文档中我们可以阅读:
表达式x和y首先计算x; 如果x为false,则返回其值; 否则,将评估y并返回结果值.
任何人都能解释一下这种行为吗?
python ×3
bash ×1
c ×1
c++ ×1
dictionary ×1
division ×1
generator ×1
if-statement ×1
inheritance ×1
keyerror ×1
modulo ×1
processor ×1