python 内置函数:vars()

vars()返回对象的__dic__属性,即包含对象的可变属性字典。
注意:不带参数调用vars()函数将返回包含本地属性和属性值的字典,类似 locals()。

示例一

# 示例一
# 展示 类具有定义时的3个可变属性(name、age、country),以及类本身自带的可变属性
class Person:
    name = "John"
    age = 36
    country = "norway"

x = vars(Person)
print(x)
# {'__module__': '__main__', 'name': 'John', 'age': 36, 'country': 'norway', '__dict__': <attribute '__dict__' of 'Person' objects>, '__weakref__': <attribute '__weakref__' of 'Person' objects>, '__doc__': None}

示例二

# 示例二
# 展示 类具有定义时的1个可变属性。
class Person:
    a = 1
print(vars(Person))
# {'__module__': '__main__', 'a': 1, '__dict__': <attribute '__dict__' of 'Person' objects>, '__weakref__': <attribute '__weakref__' of 'Person' objects>, '__doc__': None}

# 展示 类的实例化对象没有可变属性
p = Person()
print(vars(p))  # {}
print(p.a)  # 1

# 展示 类的实例化对象被修改的属性属于可变属性
p.a = 2
print(vars(p))  # {'a': 2}
print(p.a)  # 2

示例三

# 示例三
# 不带参数调用vars()
print(vars())
# {'__name__': '__main__', '__doc__': None, '__package__': '', '__loader__': None, '__spec__': None, '__file__': '/home/hxl/libo/UCL/main.py', '__cached__': None, '__builtins__': {'__name__': 'builtins', '__doc__': "Built-in functions, exceptions, and other objects.\n\nNoteworthy: None is the `nil' object; Ellipsis represents `...' in slices.", '__package__': '', '__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__spec__': ModuleSpec(name='builtins', loader=<class '_frozen_importlib.BuiltinImporter'>), '__build_class__': <built-in function __build_class__>, '__import__': <built-in function __import__>, 'abs': <built-in function abs>, 'all': <built-in function all>, 'any': <built-in function any>, 'ascii': <built-in function ascii>, 'bin': <built-in function bin>, 'breakpoint': <built-in function breakpoint>, 'callable': <built-in function callable>, 'chr': <built-in function chr>, 'compile': <built-in function compile>, 'delattr': <built-in function delattr>, 'dir': <built-in function dir>, 'divmod': <built-in function divmod>, 'eval': <built-in function eval>, 'exec': <built-in function exec>, 'format': <built-in function format>, 'getattr': <built-in function getattr>, 'globals': <built-in function globals>, 'hasattr': <built-in function hasattr>, 'hash': <built-in function hash>, 'hex': <built-in function hex>, 'id': <built-in function id>, 'input': <built-in function input>, 'isinstance': <built-in function isinstance>, 'issubclass': <built-in function issubclass>, 'iter': <built-in function iter>, 'len': <built-in function len>, 'locals': <built-in function locals>, 'max': <built-in function max>, 'min': <built-in function min>, 'next': <built-in function next>, 'oct': <built-in function oct>, 'ord': <built-in function ord>, 'pow': <built-in function pow>, 'print': <built-in function print>, 'repr': <built-in function repr>, 'round': <built-in function round>, 'setattr': <built-in function setattr>, 'sorted': <built-in function sorted>, 'sum': <built-in function sum>, 'vars': <built-in function vars>, 'None': None, 'Ellipsis': Ellipsis, 'NotImplemented': NotImplemented, 'False': False, 'True': True, 'bool': <class 'bool'>, 'memoryview': <class 'memoryview'>, 'bytearray': <class 'bytearray'>, 'bytes': <class 'bytes'>, 'classmethod': <class 'classmethod'>, 'complex': <class 'complex'>, 'dict': <class 'dict'>, 'enumerate': <class 'enumerate'>, 'filter': <class 'filter'>, 'float': <class 'float'>, 'frozenset': <class 'frozenset'>, 'property': <class 'property'>, 'int': <class 'int'>, 'list': <class 'list'>, 'map': <class 'map'>, 'object': <class 'object'>, 'range': <class 'range'>, 'reversed': <class 'reversed'>, 'set': <class 'set'>, 'slice': <class 'slice'>, 'staticmethod': <class 'staticmethod'>, 'str': <class 'str'>, 'super': <class 'super'>, 'tuple': <class 'tuple'>, 'type': <class 'type'>, 'zip': <class 'zip'>, '__debug__': True, 'BaseException': <class 'BaseException'>, 'Exception': <class 'Exception'>, 'TypeError': <class 'TypeError'>, 'StopAsyncIteration': <class 'StopAsyncIteration'>, 'StopIteration': <class 'StopIteration'>, 'GeneratorExit': <class 'GeneratorExit'>, 'SystemExit': <class 'SystemExit'>, 'KeyboardInterrupt': <class 'KeyboardInterrupt'>, 'ImportError': <class 'ImportError'>, 'ModuleNotFoundError': <class 'ModuleNotFoundError'>, 'OSError': <class 'OSError'>, 'EnvironmentError': <class 'OSError'>, 'IOError': <class 'OSError'>, 'EOFError': <class 'EOFError'>, 'RuntimeError': <class 'RuntimeError'>, 'RecursionError': <class 'RecursionError'>, 'NotImplementedError': <class 'NotImplementedError'>, 'NameError': <class 'NameError'>, 'UnboundLocalError': <class 'UnboundLocalError'>, 'AttributeError': <class 'AttributeError'>, 'SyntaxError': <class 'SyntaxError'>, 'IndentationError': <class 'IndentationError'>, 'TabError': <class 'TabError'>, 'LookupError': <class 'LookupError'>, 'IndexError': <class 'IndexError'>, 'KeyError': <class 'KeyError'>, 'ValueError': <class 'ValueError'>, 'UnicodeError': <class 'UnicodeError'>, 'UnicodeEncodeError': <class 'UnicodeEncodeError'>, 'UnicodeDecodeError': <class 'UnicodeDecodeError'>, 'UnicodeTranslateError': <class 'UnicodeTranslateError'>, 'AssertionError': <class 'AssertionError'>, 'ArithmeticError': <class 'ArithmeticError'>, 'FloatingPointError': <class 'FloatingPointError'>, 'OverflowError': <class 'OverflowError'>, 'ZeroDivisionError': <class 'ZeroDivisionError'>, 'SystemError': <class 'SystemError'>, 'ReferenceError': <class 'ReferenceError'>, 'MemoryError': <class 'MemoryError'>, 'BufferError': <class 'BufferError'>, 'Warning': <class 'Warning'>, 'UserWarning': <class 'UserWarning'>, 'DeprecationWarning': <class 'DeprecationWarning'>, 'PendingDeprecationWarning': <class 'PendingDeprecationWarning'>, 'SyntaxWarning': <class 'SyntaxWarning'>, 'RuntimeWarning': <class 'RuntimeWarning'>, 'FutureWarning': <class 'FutureWarning'>, 'ImportWarning': <class 'ImportWarning'>, 'UnicodeWarning': <class 'UnicodeWarning'>, 'BytesWarning': <class 'BytesWarning'>, 'ResourceWarning': <class 'ResourceWarning'>, 'ConnectionError': <class 'ConnectionError'>, 'BlockingIOError': <class 'BlockingIOError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'ChildProcessError': <class 'ChildProcessError'>, 'ConnectionAbortedError': <class 'ConnectionAbortedError'>, 'ConnectionRefusedError': <class 'ConnectionRefusedError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'FileExistsError': <class 'FileExistsError'>, 'FileNotFoundError': <class 'FileNotFoundError'>, 'IsADirectoryError': <class 'IsADirectoryError'>, 'NotADirectoryError': <class 'NotADirectoryError'>, 'InterruptedError': <class 'InterruptedError'>, 'PermissionError': <class 'PermissionError'>, 'ProcessLookupError': <class 'ProcessLookupError'>, 'TimeoutError': <class 'TimeoutError'>, 'open': <built-in function open>, 'quit': Use quit() or Ctrl-D (i.e. EOF) to exit, 'exit': Use exit() or Ctrl-D (i.e. EOF) to exit, 'copyright': Copyright (c) 2001-2022 Python Software Foundation.
# All Rights Reserved.

# Copyright (c) 2000 BeOpen.com.
# All Rights Reserved.

# Copyright (c) 1995-2001 Corporation for National Research Initiatives.
# All Rights Reserved.

# Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
# All Rights Reserved., 'credits':     Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
#    for supporting Python development.  See www.python.org for more information., 'license': Type license() to see the full license text, 'help': Type help() for interactive help, or help(object) for help about object., 'execfile': <function execfile at 0x7f39ef9a09d0>, 'runfile': <function runfile at 0x7f39ef7ed310>, '__pybind11_internals_v4_gcc_libstdcpp_cxxabi1011__': <capsule object NULL at 0x7f39edcf0450>}, 'os': <module 'os' from '/home/hxl/anaconda3/envs/FACIL/lib/python3.8/os.py'>, 'torch': <module 'torch' from '/home/hxl/anaconda3/envs/FACIL/lib/python3.8/site-packages/torch/__init__.py'>, 'nn': <module 'torch.nn' from '/home/hxl/anaconda3/envs/FACIL/lib/python3.8/site-packages/torch/nn/__init__.py'>, 'F': <module 'torch.nn.functional' from '/home/hxl/anaconda3/envs/FACIL/lib/python3.8/site-packages/torch/nn/functional.py'>, 'torchvision': <module 'torchvision' from '/home/hxl/anaconda3/envs/FACIL/lib/python3.8/site-packages/torchvision/__init__.py'>, 'np': <module 'numpy' from '/home/hxl/anaconda3/envs/FACIL/lib/python3.8/site-packages/numpy/__init__.py'>, 'tqdm': <class 'tqdm.std.tqdm'>, 'get_args': <function get_args at 0x7f38fa01dd30>, 'get_aug': <function get_aug at 0x7f38fa01ddc0>, 'get_model': <function get_model at 0x7f38f926e670>, 'AverageMeter': <class 'tools.average_meter.AverageMeter'>, 'knn_monitor': <function knn_monitor at 0x7f38f926ed30>, 'Logger': <class 'tools.logger.Logger'>, 'file_exist_check': <function file_exist_check at 0x7f38f4cbe430>, 'get_dataset': <function get_dataset at 0x7f38f4c9f160>, 'datetime': <class 'datetime.datetime'>, 'csv': <module 'csv' from '/home/hxl/anaconda3/envs/FACIL/lib/python3.8/csv.py'>, 'sys': <module 'sys' (built-in)>, 'Dict': typing.Dict, 'Any': typing.Any, 'ContinualDataset': <class 'datasets.utils.continual_dataset.ContinualDataset'>, 'Tuple': typing.Tuple, 'backward_transfer': <function backward_transfer at 0x7f38f926ef70>, 'forward_transfer': <function forward_transfer at 0x7f38f4c9f040>, 'forgetting': <function forgetting at 0x7f38f4c9f0d0>, 'mask_classes': <function mask_classes at 0x7f38f4cbe280>, 'create_if_not_exists': <function create_if_not_exists at 0x7f38f926ee50>, 'base_path': <function base_path at 0x7f38f4c9f670>, 'useless_args': ['dataset', 'tensorboard', 'validation', 'model', 'csv_log', 'notes', 'load_best_args'], 'print_mean_accuracy': <function print_mean_accuracy at 0x7f38f3dcd280>, 'CsvLogger': <class 'utils.loggers.CsvLogger'>, 'ContinualModel': <class 'models.utils.continual_model.ContinualModel'>, 'evaluate': <function evaluate at 0x7f39ef5975e0>, 'main': <function main at 0x7f38f3dcd820>, 'args': Namespace(aug_kwargs={'name': 'simsiam', 'image_size': 32}, ckpt_dir='./checkpoints/cifar10_results/', ckpt_dir_1=None, cl_default=False, config_file='configs/simsiam_c10.yaml', data_dir='../a_Data/cifar100', dataloader_kwargs={'drop_last': True, 'pin_memory': True, 'num_workers': 0}, dataset=<arguments.Namespace object at 0x7f38f3e6c460>, dataset_kwargs={'dataset': 'seq-cifar10', 'data_dir': '../a_Data/cifar100', 'download': False, 'debug_subset_size': 8}, debug=True, debug_subset_size=8, device='cuda', download=False, eval=<arguments.Namespace object at 0x7f38f3debd60>, eval_from=None, hide_progress=True, log_dir='../logs/in-progress_0904173018_simsiam-c10-experiment-resnet18', logger=<arguments.Namespace object at 0x7f38f3deb070>, model=<arguments.Namespace object at 0x7f38f3e6cb20>, name='simsiam-c10-experiment-resnet18', ood_eval=False, seed=None, train=<arguments.Namespace object at 0x7f38f3e6ca30>, validation=False), 'device': 'cuda', '__pydevd_ret_val_dict': {'get_dataset': <datasets.seq_cifar10.SequentialCIFAR10 object at 0x7f39ef538bb0>}, 'dataset': <datasets.seq_cifar10.SequentialCIFAR10 object at 0x7f39ef538bb0>, 'Person': <class '__main__.Person'>, 'x': mappingproxy({'__module__': '__main__', 'name': 'John', 'age': 36, 'country': 'norway', '__dict__': <attribute '__dict__' of 'Person' objects>, '__weakref__': <attribute '__weakref__' of 'Person' objects>, '__doc__': None})}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值