在这里,我无法访问Python 列表推导中的类变量 .
class Student:
max_year = 18
year_choice = [i for i in range(100) if i > max_year]
def __init__(self, name):
self.name = name
print (self.year_choice)
Student('Blah')
Run Code Online (Sandbox Code Playgroud)
但它在Python 2中运行良好.
../workspace$ python student.py
[19, 20, 21, 22, 2.... 99]
Run Code Online (Sandbox Code Playgroud)
但是在Python 3中出现错误.
../workspace$ python student.py
File "student.py", line 18, in <listcomp>
year_choice = [i for i in range(100) if i > max_year]
NameError: name 'max_year' is not defined
Run Code Online (Sandbox Code Playgroud)
从调试这个当我改变下面的声明
[i for i in range(100) if i > max_year]
对此
[i …Run Code Online (Sandbox Code Playgroud) 我使用以下命令删除已合并到HEAD.
>>> git branch | xargs git branch -d
>>> # (not -D) because I don't wanted to forced delete all the branches
Run Code Online (Sandbox Code Playgroud)
但是我注意到它还删除了一个没有合并到HEAD但被推送到远程的分支。
错误警告:(分支未被删除)
Run Code Online (Sandbox Code Playgroud)warning: not deleting branch 'ER-1421' that is not yet merged to 'refs/remotes/origin/ER-1421', even though it is merged to HEAD. error: The branch 'ER-1421' is not fully merged.
警告无错误:(已从本地删除)
Run Code Online (Sandbox Code Playgroud)warning: deleting branch 'ER-2256' that has been merged to 'refs/remotes/origin/ER-2256', but not yet merged to HEAD. Deleted branch ER-2256 (was d18dafcee).
我的问题是:如何限制删除会发出任何警告 …