动态语言正在兴起,其中有很多:例如Ruby,Groovy,Jython,Scala(静态,但具有动态语言的外观和感觉)等等.我的背景是Java SE和EE编程,我想要将我的知识扩展到这些动态语言之一,以便为将来做好更充分的准备.
但是我应该关注哪种动态语言学习?为什么?在不久的将来,哪些将成为首选语言?
我在python脚本中使用ctypes lib时遇到了麻烦.这是我的代码(在互联网上找到):
if __name__ == "__main__":
from ctypes import *
user32 = windll.user32
kernel32 = windll.kernel32
class RECT(Structure):
_fields_ = [
("left", c_ulong),
("top", c_ulong),
("right", c_ulong),
("bottom", c_ulong)];
class GUITHREADINFO(Structure):
_fields_ = [
("cbSize", c_ulong),
("flags", c_ulong),
("hwndActive", c_ulong),
("hwndFocus", c_ulong),
("hwndCapture", c_ulong),
("hwndMenuOwner", c_ulong),
("hwndMoveSize", c_ulong),
("hwndCaret", c_ulong),
("rcCaret", RECT)
]
def moveCursorInCurrentWindow(x, y):
# Find the focussed window.
guiThreadInfo = GUITHREADINFO(cbSize=sizeof(GUITHREADINFO))
user32.GetGUIThreadInfo(0, byref(guiThreadInfo))
focussedWindow = guiThreadInfo.hwndFocus
# Find the screen position of the window.
windowRect = RECT() …Run Code Online (Sandbox Code Playgroud) 我已经安装了Jython,一个名为"jython-env" 的virtualenv,并安装了"bottle"来进行一些Web应用程序开发.我必须在这个应用程序中使用一些JAR文件供一些Python代码使用.我知道我必须设置应该包含这些JAR文件的类路径.我尝试使用设置类路径
export classpath=/home/myname/jclasses/foo.jar
Run Code Online (Sandbox Code Playgroud)
但是当我尝试导入该类时,它表示未找到模块.我是Java的新手,我是第一次这样做.
不能完成配置,以便我可以将JAR文件放在我的virtualenv的sitepackages目录中并从那里使用它?
我正在使用Eclipse而我正在尝试创建一个可以运行我的python代码的java程序.我遵循此页面上的指导原则:http://jythonpodcast.hostjava.net/jythonbook/en/1.0/JythonAndJavaIntegration. HTML#使用,Jython的内-Java的应用程序
但是当我在顶部包含这些陈述时:
package org.jython.book.util;
import org.python.core.PyObject;
import org.python.core.PyString;
import org.python.util.PythonInterpreter;
Run Code Online (Sandbox Code Playgroud)
我收到一条消息说"导入org.python无法解决".对于如何解决这个问题,有任何的建议吗?
非常感谢!!
我在Java中使用Jython; 所以我有一个类似于下面的Java设置:
String scriptname="com/blah/myscript.py"
PythonInterpreter interpreter = new PythonInterpreter(null, new PySystemState());
InputStream is = this.getClass().getClassLoader().getResourceAsStream(scriptname);
interpreter.execfile(is);
Run Code Online (Sandbox Code Playgroud)
这将(例如)运行以下脚本:
# myscript.py:
import sys
if __name__=="__main__":
print "hello"
print sys.argv
Run Code Online (Sandbox Code Playgroud)
我如何使用此方法传递'命令行'参数?(我希望能够编写我的Jython脚本,以便我也可以使用'python script arg1 arg2'在命令行上运行它们).
众所周知,Python类不能拥有真正的私有成员.该不可─ 因为这-obvious含义是,Java类私处被公开于Jython的.(隐藏你的下体,Java!)
因此,当使用Jython并访问通常通过getter和setter暴露给其他Java类的Java类私有时,您是否还想使用这些方法?或者你直接访问私人?
更恰当的问题是,你应该使用getter和setter吗?如果这些方法存在副作用,那么答案肯定是'是',但是如果方法就在那里,因为有人认为在任何地方放置吸气剂和定位器是正确的事情(IMO不是,只是制造那该死的东西是公开的),那么有没有理由为Java的所有额外仪式而烦恼?
这是一个导致错误的片段:
net.grinder.scriptengine.jython.JythonScriptExecutionException: SyntaxError: ('invalid syntax', ('C:\\grinder-3.7.1\\lib
\\.\\nb-romg-file-store\\current\\grinder_test.py', 131, 9, ' finally:'))
Run Code Online (Sandbox Code Playgroud)
ss = ''
self._suggestionLock.acquire()
try:
ss = suggestion_strings.next()
except StopIteration:
suggestion_strings = suggestions_generator()
ss = suggestion_strings.next()
finally:
self._suggestionLock.release()
Run Code Online (Sandbox Code Playgroud)
这可能有什么问题?
我在正在使用的计算机上使用Jython的较旧版本(2.2.1),但我需要排序的方法。我已经从未来导入了发电机,但是
from __future__ import sorted
Run Code Online (Sandbox Code Playgroud)
返回SyntaxError:未定义将来的功能。有可以导入的模块吗?
我有以下内容:
with open("c:\xml1.txt","r") as f1, open('c:\somefile.txt','w') as f2:
Run Code Online (Sandbox Code Playgroud)
这是一个语法错误:
with open("c:\xml1.txt","r") as f1, open('c:\somefile.txt','w') as f2:
^
SyntaxError: mismatched input ',' expecting COLON
Run Code Online (Sandbox Code Playgroud)
我正在使用netbeans python插件,它依赖于jython 2.5.1
我已经添加了:
from __future__ import with_statement
Run Code Online (Sandbox Code Playgroud)
但这并没有改变任何事情.
关于该怎么做的任何建议?
谢谢
我写错了程序.
def changeByThirds(pic):
w= getWidth (pic)
h = getHeight(pic)
newPic = makeEmptyPicture(w,h)
for x in range (0,w):
for y in range (0,h):
pxl = getPixel(pic, x, y)
if (y<h/3):
#some code
if (y>(h*2/3)):
#some code
else:
#some code
return (newPic)
Run Code Online (Sandbox Code Playgroud)
当我执行这个程序时,第一个if语句if (y<h/3):被忽略,所以它运行就像第一个if不存在一样.
if (y>(h*2/3)):
#some code
else:
#some code
Run Code Online (Sandbox Code Playgroud)
我发现编写代码的正确方法是这样的:
def changeByThirds(pic):
w= getWidth (pic)
h = getHeight(pic)
newPic = makeEmptyPicture(w,h)
for x in range (0,w):
for y in range (0,h):
pxl = getPixel(pic, x, y)
if (y<h/3): …Run Code Online (Sandbox Code Playgroud) jython ×10
python ×7
argc ×1
argv ×1
bottle ×1
command-line ×1
ctypes ×1
grinder ×1
groovy ×1
if-statement ×1
java ×1
ruby ×1
scala ×1
sorted ×1
virtualenv ×1