如果我尝试成功,我想退出Python脚本.我的代码不会退出并继续执行脚本的其余部分.
如果我运行python myscript.py --help
,我需要脚本退出.如果我跑,python myscript.py
我需要执行该except
部分.
try:
if sys.argv[1] == '--help' or sys.argv[1] == '-help' or \
sys.argv[1] == '-h' or sys.argv[1] == '--h':
print "NAME"
sys.exit("Usage : python go.py")
except:
#REST OF THE CODE.
Run Code Online (Sandbox Code Playgroud) 所以我有一个清单:
>>> print references
>>> ['Reference xxx-xxx-xxx-007 ', 'Reference xxx-xxx-xxx-001 ', 'Reference xxx-xxx-xxxx-00-398 ', 'Reference xxx-xxx-xxxx-00-399']
Run Code Online (Sandbox Code Playgroud)
(列表比这长得多)
我需要编写一个CSV文件,它看起来像这样:
Column 1:
Reference xxx-xxx-xxx-007
Reference xxx-xxx-xxx-001
[...]
Run Code Online (Sandbox Code Playgroud)
我试过这个:
c = csv.writer(open("file.csv", 'w'))
for item in references:
c.writerows(item)
Or:
for i in range(0,len(references)):
c.writerow(references[i])
Run Code Online (Sandbox Code Playgroud)
但是当我打开创建的csv文件时,我得到一个窗口,要求我选择分隔符无论如何,我有类似R,e,f,e,r,e,n,c,es的东西
我需要填充结构的属性x和y.鉴于我有很多成员(x,y ...),并且每个人都有相同的属性(读,写等),无论如何我能以比这更短的方式做到这一点吗?
features.x.Read = GetAttribute(node,"x","Read",HexValue);
features.x.Write = GetAttribute(node,"x","Write",HexValue);
features.x.address = GetAttribute(node,"x","address",HexValue);
features.x.value = GetAttribute(node,"x","value",HexValue);
features.y.Read = GetAttribute(node,"y","Read",HexValue);
features.y.Write = GetAttribute(node,"y","Write",HexValue);
features.y.address = GetAttribute(node,"y","address",HexValue);
features.y.value = GetAttribute(node,"y","value",HexValue);
Run Code Online (Sandbox Code Playgroud)
谢谢