实现命令行UI的"最干净"方式是什么,类似于git,例如:
git push origin/master
git remote add origin git://example.com master
Run Code Online (Sandbox Code Playgroud)
理想情况下还允许更灵活的解析,例如,
jump_to_folder app theappname v2
jump_to_folder app theappname source
jump_to_folder app theappname source v2
jump_to_folder app theappname build v1
jump_to_folder app theappname build 1
jump_to_folder app theappname v2 build
Run Code Online (Sandbox Code Playgroud)
jump_to_folder是脚本名称,app是命令,theappname是"固定位置"参数,"构建"和"v2"等是参数(例如,可能的参数是任何数字/任何前缀为av的数字,或者build/source/TMP /配置)
我可以用一系列if/ else/ 手动解析参数elifs,但必须有更优雅的方法来做到这一点?
作为一个完全理论上的例子,我可以描述UI模式..
app:
fixed: application_name
optional params:
arg subsection:
"build"
"source"
"tmp"
"config"
arg version:
integer
"v" + integer
Run Code Online (Sandbox Code Playgroud)
然后通过上面的模式解析提供的参数,并获取一个字典:
>>> print schema.parse(["app", "theappname", "v1", "source"])
{ …Run Code Online (Sandbox Code Playgroud) 我一直想知道,游戏程序员如何将外部3D建模软件(如maya或3d max)中完成的游戏角色与用最喜欢的编程语言(如c或c ++)完成的实际游戏逻辑结合在一起.
你如何将这两件事结合在一起,从建模角色到编程,构建游戏的实际过程是什么?
让我想知道的一些事情是,你是从代码还是从3D模型编写角色动作?
例子真的很高兴看到.
我希望通过像q-gram距离或简单的"包距离"或者Python中的Levenshtein距离来聚集~100,000个短字符串.我打算填写距离矩阵(100,000选择2比较),然后用pyCluster进行分层聚类.但是我甚至在开始之前遇到了一些记忆问题.例如,距离矩阵太大而不适合numpy.
aa = numpy.zeros((100000, 100000))
ValueError: array is too big.
Run Code Online (Sandbox Code Playgroud)
这看起来像是一件合理的事吗?或者我注定要在这项任务中记忆问题?谢谢你的帮助.
请以您选择的语言提供代码示例.
更新:没有为外部存储设置约束.
示例:通过网络接收/发送整数.本地磁盘上有足够的空间用于中间结果.
我正在尝试创建一个扫描文本文件并将参数传递给子进程的程序.一切正常,直到我得到路径中有空格的目录.
我的分裂方法,打破了争论的空间:
s = "svn move folder/hello\ world anotherfolder/hello\ world"
task = s.split(" ")
process = subprocess.check_call(task, shell = False)
Run Code Online (Sandbox Code Playgroud)
或者,我需要函数来解析正确的参数,或者我将整个字符串传递给子进程而不先将其分解.
我虽然有点失落.
$.ajax({
type: "POST",
url: "SomePage.aspx/GetSomeObjects",
contentType: "application/json; charset=utf-8",
...
});
Run Code Online (Sandbox Code Playgroud)
它有时用作示例,或者软件可以在没有显式字符集的情况下中断.
应用程序/ json媒体类型的rfc 4627表示它不接受第6节中的任何参数:
The MIME media type for JSON text is application/json.
Type name: application
Subtype name: json
Required parameters: n/a
Optional parameters: n/a
Run Code Online (Sandbox Code Playgroud)
可以解释为charset不应该与application/json一起使用.
和第3节表明,这是没有必要指定字符集:
JSON text SHALL be encoded in Unicode. The default encoding is
UTF-8.
Since the first two characters of a JSON text will always be ASCII
characters [RFC0020], it is possible to determine whether …Run Code Online (Sandbox Code Playgroud) 假设我有一个包含索引的列表列表[[start, end], [start1, end1], [start2, end2]].
例如:
[[0, 133], [78, 100], [25, 30]].
如何检查列表之间的重叠并删除每次更长的列表?所以:
>>> list = [[0, 133], [78, 100], [25, 30]]
>>> foo(list)
[[78, 100], [25, 30]]
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止尝试做的事情:
def cleanup_list(list):
i = 0
c = 0
x = list[:]
end = len(x)
while i < end-1:
for n in range(x[i][0], x[i][1]):
if n in range(x[i+1][0], x[i+1][1]):
list.remove(max(x[i], x[i+1]))
i +=1
return list
Run Code Online (Sandbox Code Playgroud)
但除了令人费解之外它还没有正常工作:
>>>cleanup_list([[0,100],[9,10],[12,90]])
[[0, 100], [12, 90]]
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激!
编辑:
其他例子是:
>>>a = [[0, 100], …Run Code Online (Sandbox Code Playgroud) 可能有人问过,但是在使用python 2.7时我找不到任何关于subprocess.call超时的信息
Python 3.3.3 Windows 7
Here is the full stack:
Traceback (most recent call last):
File "Blah\MyScript.py", line 578, in Call
output = process.communicate( input=SPACE_KEY, timeout=600 )
File "C:\Python33\lib\subprocess.py", line 928, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "C:\Python33\lib\subprocess.py", line 1202, in _communicate
self.stdin.write(input)
OSError: [Errno 22] Invalid argument
Run Code Online (Sandbox Code Playgroud)
代码如下所示:
process = subprocess.Popen( arguments,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
env=environment )
output = process.communicate( input=SPACE_KEY, timeout=600 )
Run Code Online (Sandbox Code Playgroud)
这段代码每天运行数百次没有问题.但是如果在同一台机器上运行多个脚本(相同的脚本,但有时来自不同的文件夹),我会收到错误.脚本没有执行相同的操作(即:当我收到此错误时,另一个脚本没有执行子进程).
subProcess代码使用许多不同的命令行来引发错误.
那么,任何人都知道发生了什么?解释器是否有多个执行问题(在不同的进程中)?相同的代码通常可以正常工作,如果解释器运行相同(或非常相似)的脚本,则会破解.但它们通常执行脚本的不同部分.
我很茫然:在8核机器上使用单个处理器很烦人.
python ×7
subprocess ×3
algorithm ×2
3d ×1
command-line ×1
directory ×1
http ×1
json ×1
list ×1
numpy ×1
python-2.7 ×1
python-3.x ×1
timeout ×1
windows ×1