是这样的,人们似乎最常推荐:
$ sudo apt-get install python-setuptools
$ sudo easy_install pip
$ sudo pip install virtualenv
Run Code Online (Sandbox Code Playgroud)
或者这是我从http://www.pip-installer.org/en/latest/installing.html获得的:
$ curl -O https://github.com/pypa/virtualenv/raw/master/virtualenv.py
$ python virtualenv.py my_new_env
$ . my_new_env/bin/activate
(my_new_env)$ pip install ...
Run Code Online (Sandbox Code Playgroud)
还是完全不同的东西?
使用Boto检查CloudFormation堆栈是否存在且未处于损坏状态的最佳方法是什么?破碎我的意思是失败和回滚状态.
我不想使用try/except
解决方案,因为boto将其记录为错误,并且在我的方案中,它将异常日志发送到警报系统.
目前我有以下解决方案:
1)使用 boto.cloudformation.connection.CloudFormationConnection.describe_stacks()
valid_states = '''\
CREATE_IN_PROGRESS
CREATE_COMPLETE
UPDATE_IN_PROGRESS
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS
UPDATE_COMPLETE'''.splitlines()
def describe_stacks():
result = []
resp = cf_conn.describe_stacks()
result.extend(resp)
while resp.next_token:
resp = cf_conn.describe_stacks(next_token=resp.next_token)
result.extend(resp)
return result
stacks = [stack for stack in describe_stacks() if stack.stack_name == STACK_NAME and stack.stack_status in valid_states]
exists = len(stacks) >= 1
Run Code Online (Sandbox Code Playgroud)
这很慢,因为我有很多堆栈.
2)使用 boto.cloudformation.connection.CloudFormationConnection.list_stacks()
def list_stacks(filters):
result = []
resp = cf_conn.list_stacks(filters)
result.extend(resp)
while resp.next_token:
resp = cf_conn.list_stacks(filters, next_token=resp.next_token)
result.extend(resp)
return result
stacks = [stack for stack in list_stacks(valid_states) …
Run Code Online (Sandbox Code Playgroud) 我正在阅读输入模块代码,并查看mypy以了解它是如何进行类型检查的.对我来说不幸的是,mypy
构建一个非常智能的树,其中包含我仍然不理解的类型表达式,并且它都基于静态分析.
我想在Python中实现一个动态(无静态分析)的类型检查系统.假设调用执行类型检查的函数check_type
,我想完成以下操作:
>>> import typing
>>>
>>> check_type(1, int)
True
>>> check_type(1, float)
False
>>> check_type([1], typing.List[int])
True
>>> check_type([1], typing.List[float])
False
>>> check_type([1], typing.List[typing.Any])
True
>>> check_type((1,), typing.Tuple[int])
True
Run Code Online (Sandbox Code Playgroud)
我考虑过从其值重新创建对象类型,例如:
>>> get_type([1])
typing.List<~T>[int]
Run Code Online (Sandbox Code Playgroud)
但这不适用于issubclass
:
>>> issubclass(typing.List[int], typing.List[typing.Any])
False
Run Code Online (Sandbox Code Playgroud)
我没有看到在Python中检查类型的简单方法,而没有假设很多关于stdlib模块内部的typing
东西(例如,访问__args__
或__tuple_params__
).
如何正确实现check_type
适用于之前列出的案例的功能?我使用的是Python 2.7.
我想知道每种策略的含义以及它们如何在幕后工作(即Highlander,Red/Black,Rolling Push).在官方网站上提供这些信息非常有用.
谢谢