python argument of type_python TypeError: argument of type '_const' is not iterable

一下是代码:#code=utf-8class_const(object):classConstError(TypeError):passdef__setattr__(self,name,value):ifnameinself:raiseself.ConstError("Can'trebindconst(%s)"%name)se...

一下是代码:

# code=utf-8

class _const(object):

class ConstError(TypeError):pass

def __setattr__(self, name, value):

if name in self:

raise self.ConstError("Can't rebind const (%s)" %name)

self.__dict__[name]=value

def __delattr__(self, name):

if name in self.__dict__:

raise self.ConstError("Can't unbind const (%s)" %name)

raise NameError(name)

import sys

sys.modules[__name__] = _const()

调用:

import const

# 1.定义常量

const.value = 5

错误:

D:\Python34\python.exe E:/ZCY/Python/FirstPythonProject/BasicGrammar/BasicGrammar_2.py

Traceback (most recent call last):

File "E:/ZCY/Python/FirstPythonProject/BasicGrammar/BasicGrammar_2.py", line 4, in

const.value = 5

File "D:\Python34\lib\const.py", line 6, in __setattr__

if name in self:

TypeError: argument of type '_const' is not iterable

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值