我有一个很长的正则表达式,我想把它放入一个变量来测试.我希望能够把它放在多行上,这样它就不那么难以理解了.我看到你可以用文档标签做多行.但是当我尝试这种格式化时,Robot似乎认为这是一个列表.有没有办法在Robot Framework中执行此操作?
考虑:
${example_regex} = '(?m)Setting IP address to [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\nSetting MAC address to [0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}\nSetting IP forwarding kernel options'
Run Code Online (Sandbox Code Playgroud)
我想能够写:
${example_regex} '(?m)Setting IP address to [0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\n
Setting MAC address to [0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}\n
Setting IP forwarding kernel options'
Run Code Online (Sandbox Code Playgroud) 我有点想用python编程,所以请放轻松我.我正在尝试调用字符串属性rjust并指定浮点的精度.这是代码和示例输出(注意0.00右边没有对齐):
print '%s: %s %s \tchange: %.2f' % (Instance1.symbol.ljust(5),
Instance1.name.ljust(50), Instance1.buyprices.rjust(10), Instance1.val)
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
AXP : American Express Company 55.38 change: -1.15
AXR : Amrep Corp. 6.540 change: 0.00
Run Code Online (Sandbox Code Playgroud) 我需要通过打开和读取文件来获取主机来获取结构来设置其主机列表.以这种方式设置允许我拥有一个庞大的主机列表,而无需每次都为这些数据编辑我的fabfile.
我试过这个:
def set_hosts():
env.hosts = [line.split(',') for line in open("host_file")]
def uname():
run("uname -a")
Run Code Online (Sandbox Code Playgroud)
和
def set_hosts():
env.hosts = open('hosts_file', 'r').readlines
def uname():
run("uname -a")
Run Code Online (Sandbox Code Playgroud)
每次我尝试使用函数set_hosts时,我都会收到以下错误:
fab set_hosts uname
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/fabric/main.py", line 712, in main
*args, **kwargs
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 264, in execute
my_env['all_hosts'] = task.get_hosts(hosts, roles, exclude_hosts, state.env)
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 74, in get_hosts
return merge(*env_vars)
File "/usr/local/lib/python2.7/dist-packages/fabric/task_utils.py", line 57, in merge
cleaned_hosts = [x.strip() for x in list(hosts) + list(role_hosts)]
AttributeError: 'builtin_function_or_method' …Run Code Online (Sandbox Code Playgroud) 我有一个导入线程并使用threading.activeCount()确定何时完成所有线程的模块。我最初使用标准的python解释器编写了模块。在脚本中使用我的模块很好,但是在ipython中导入我的模块并调用依赖于threading.activeCount()的函数时。我的函数永不返回。
码:
for dev in run_list:
proc = threading.Thread(target=go, args=[dev])
proc.start()
while threading.activeCount() > 1:
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
我注意到,当第一次使用标准解释器导入线程并调用threading.activeCount()时,仅计数一个线程:
>>> import threading
>>> threading.activeCount()
1
>>> threading.enumerate()
[<_MainThread(MainThread, started 140344324941568)>]
Run Code Online (Sandbox Code Playgroud)
但是,使用ipython时,初始计数为2:
In [1]: import threading
In [2]: threading.activeCount()
Out[2]: 2
In [3]: threading.enumerate()
Out[3]:
[<_MainThread(MainThread, started 140674997614336)>,
<HistorySavingThread(Thread-1, started 140674935068416)>]
Run Code Online (Sandbox Code Playgroud)
这个模块被使用各种解释器的人们所使用,所以我想知道是否有更好的方法来处理这个问题(最好还是使用线程)?