一、两步在java中调用python
1、在大类中加入这样的一个方法
private static boolean CallPython(String string) throws Exception{
Process proc = Runtime.getRuntime().exec(string);
proc.waitFor();
return true;
}
2、在main函数中直接使用调用语句
CallPython("python py_java/***.py");
二、使用命令行调用python代码:
三、常用常识不再一一列举(按照使用频率排序)
去除多余的空格:strip
列表添加.append
替换:replace
循环语句: for a in list: list可以来源于读文件readlines(),也可以是上述.append得到的列表,也可是是range(len(...))
将序列中元素通过制定的字符串连接''.join(list类型)
去重 words=set()
正则表达式中常用 re.match()/re.search() group(); re.sub(old, new, text) re.compile()
如何读取二进制文件存在变量中
去除中文的Python正则表达式:string = re.sub(ur"[^\u4e00-\u9fa5]", " ",string),java是nativeStr.split("[^\\u4e00-\\u9fa5]")
四、排序
dict= sorted(result.iteritems(), key=lambda d:d[1], reverse = True) #返回时列表 for key,val in dict:无items
import operater
sortedClassCount = sorted(classCount.iteritems(), key=operator.itemgetter(1), reverse=True) 返回是矩阵直接去 sortedClassCount[0][0]
五、写NLP任务python程序设计:重要的是设计,这个可以参考kim那篇CNN代码如:变量、参数的设计