"""
Saves a dir listing in a file
Usage: python listfiles.py -d dir -f filename [flags]
Arguments:
-d, --dir dir; ls of which will be saved in a file
-f, --file filename (if existing will be overwritten)
Flags:
-h, --help show this help
-v
我尝试将整个字符串作为参数传递给python脚本。我遇到的问题是,Python假设我只需要字符串的第一个单词。
在下面的示例中,-l arg代表log,我希望它捕获整个字符串。
示例:
python myscript.py -l "Big String I want to as single argument"
代码如下:
try:
opts, args = getopt.getopt(sys.argv[1:], 'hcrn:l:wo:a:emi', ["reset="])
#-l is one of many arguments I
下面的脚本不会打印列表中每个Python模块中包含的名称。当我运行它时,每个dir(mod)命令都返回相同的名称列表。这就像'mod‘变量没有被dir所理解。for循环似乎不是问题所在。有什么办法解决这个问题吗?
#!/usr/bin/python
# Print out names in modules
# https://docs.python.org/2/py-modindex.html
import os, sys, re, subprocess, platform, shutil, argparse, test, xml, time, urllib2, getopt
de