我尝试使用with
语句和tarfile模块...
with tarfile.open('/dir/dir/dir.tar.gz', 'w:gz') as fl:
fl.add('/dir/dir/dir/', arcname = '/')
Run Code Online (Sandbox Code Playgroud)
所以它显示了下一个:
Traceback (most recent call last): File "", line 1, in AttributeError: 'TarFile' object has no attribute '__exit__'
我尝试创建tar.gz文件并使用statement is关闭它,但它显示错误.问题是什么?
谢谢!
当我做
dict = {'Alice': '7898', 'Beth': '9102', 'Cecil': '3258'}
print filter(lambda x: x, dict['Alice'])
Run Code Online (Sandbox Code Playgroud)
它显示:7898
当我做下一个
dict = {'Alice': '2341', 'Beth': '9102', 'Cecil': '3258'}
print filter(lambda x: x=="2341", dict['Alice'])
Run Code Online (Sandbox Code Playgroud)
表明:
为什么它没有显示真实.如何获得真实?
我试图从dict获取项目,由json解码:
data = [ { 'a':'A', 'b':(2, 4), 'c':3 } ]
data_string = json.dumps(data)
decoded = json.loads(data_string)
decoded['c']
Run Code Online (Sandbox Code Playgroud)
所以它显示了下一个:
Traceback (most recent call last): File "", line 1, in TypeError: list indices must be integers, not str
我尝试在屏幕上打印c的值
所以我尝试在解码后看到3 ['c']
我该怎么做?
谢谢!
python ×3