我想在python中使用枚举,如下面的代码(java).我是Python的新手.我在Java中有以下代码,并希望在Python中复制功能:
class Direction {
public enum Direction {LEFT, RIGHT, UP, DOWN}
public void navigate(Direction direction)
switch(direction){
case Direction.LEFT:
System.out.print("left");
break;
case Direction.RIGHT:
System.out.print("right");
break;
case Direction.UP:
System.out.print("up");
break;
case Direction.DOWN:
System.out.print("down");
break;
}
}
Run Code Online (Sandbox Code Playgroud)
如何强制用户只提供Python方法的枚举?
有没有一种正确的方法来循环RF中的字典?我使用了pythonic方式,但失败了:
:FOR ${key} ${value} IN &{dict}
Run Code Online (Sandbox Code Playgroud)
output:FOR循环值的数量应该是其变量的倍数.得到2个变量,但有1个值.
同样,当我将字典指向为标量变量时.我在文档中找不到一个例子.有人解决了吗?
PS
我知道解决方法,你使用kw.然后,获取字典键和获取字典值,以更新您使用的值设置为字典$ {key} $ {new_value},但这似乎是人类不友好并使用几个for循环迭代而不是一个.
from subprocess import call
import os
call(['robot '+os.getcwd()+'\\aaa.robot'])
Run Code Online (Sandbox Code Playgroud)
file_dir:D:/aaa/test/aaa.robot
现在在同一个目录中的脚本
Output:
Traceback (most recent call last):
File "__init.py", line 7, in <module>
call(['robot '+os.getcwd()+'\\aaa.robot'])
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 710, in __init_
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execut
startupinfo)
WindowsError: [Error 2] Nie mo?na odnale?Š okre?lonego pliku
Run Code Online (Sandbox Code Playgroud)
我只是无法处理它.我不明白为什么在python中调整任何东西都是如此复杂:(
我想要与此行相同的结果(直接写入cmd):
/>robot aaa.robot
Run Code Online (Sandbox Code Playgroud)