python - 在python的类函数中更改全局变量
问题描述
我以前看过有关此问题的问题,但我无法在类函数中重新创建全局变量的更改:
test = 0
class Testing:
def add_one():
global test
test += 1
当我输入
Testing.add_one
print (test)
它打印“0”。如何让类中的函数添加一个进行测试?
谢谢!
解决方案
推荐阅读
- apache-spark - 如何定义 Spark UI 和驱动程序日志 URL,以便它们直接访问我的代理而不是 spark master
- c# - 统一使用颜色数据类型
- aws-sdk-js - node.js aws-sdk 使用名称中的空格访问 S3 目录
- powershell - 在 powershell 脚本中捕获 Snowsql 返回代码
- node.js - 可能不存在的字段上的“orderBy”完全跳过文档
- npm - 在 Yarn 中设置自定义注册表似乎不起作用
- matplotlib - 禁止在metpy中打印轴标签
- java - jlink不使用自动模块
- javascript - 反应 API 项目:类型错误:无法读取未定义的属性“小”
- java - 需要关于我做错了什么的建议