小编ram*_*esh的帖子

Python 3 - 未定义类变量

在这里,我无法访问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)

python scope python-3.x

8
推荐指数
1
解决办法
1673
查看次数

Git:只有在没有警告的情况下才删除分支

我使用以下命令删除已合并到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但被推送到远程的分支。

错误警告:(分支未被删除)

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).
Run Code Online (Sandbox Code Playgroud)

我的问题是:如何限制删除会发出任何警告 …

git

0
推荐指数
1
解决办法
1488
查看次数

标签 统计

git ×1

python ×1

python-3.x ×1

scope ×1