假设我有以下代码:
public static class Foo
{
public static void Bar() {}
}
Run Code Online (Sandbox Code Playgroud)
在IronPython中,我想:
Bar()
Run Code Online (Sandbox Code Playgroud)
无需在线上包含Foo.现在,我知道我可以说:
var Bar = Foo.Bar
Bar()
Run Code Online (Sandbox Code Playgroud)
但我想使用SetVariable在我的C#代码中将Bar添加到ScriptScope.我怎样才能做到这一点?
我现在正在学习python,今天,我在http://docs.python.org/release/2.5.4/tut/node8.html遇到了一个问题.
6.1.1将模块作为脚本执行
当你运行Python模块时
python fibo.py <arguments>模块中的代码将被执行,就像您导入它一样,但__ ____设置为"__main__".这意味着通过在模块的末尾添加此代码:
if __name__ == "__main__":
import sys`
fib(int(sys.argv[1]))
Run Code Online (Sandbox Code Playgroud)
您可以使该文件可用作脚本以及可导入模块,因为解析命令行的代码仅在模块作为"主"文件执行时才会运行:
$ python fibo.py 50 1 1 2 3 5 8 13 2134
但是当我在shell中这样做时,我得到了
File "<input>", line 1
python fibo.py 222
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud)
如何正确执行脚本?
fibo.py是
def fib(n):
a,b=0,1
while b<n:
print b,
a,b = b,a+b
def fib2(n):
result=[]
a,b=0,1
while b<n:
result.append(b)
a,b=b,a+b
return result
if __name__ =="__main__":
import sys
fib(int(sys.argv[1]))
Run Code Online (Sandbox Code Playgroud) 有没有开源的iPad应用程序?请帮我提供一些示例ipad源代码链接,这将有助于设计好的iPad应用程序..
我开始在我的机器人应用程序中探索使用概率.我的目标是进入完整的SLAM,但我开始使用更简单的卡尔曼滤波器来完成我的工作.
我正在使用扩展卡尔曼滤波器,状态为[X,Y,Theta].我使用控制输入[Distance,Vector],我有一个76个激光范围的数组[Distance,Theta]作为我的测量输入.
我无法知道如何决定在高斯函数中使用的协方差.因为我的测量结果是不确定的(激光在<1米时准确度约为1cm,但在更高的范围内精确度可达5cm)我不知道如何创建"函数"来估计这种情况的概率.我知道这个函数应该用'线性化'来使用,但我不知道该怎么做.
我有理由相信如何决定我的状态Gaussian的函数,我很高兴在这个上使用普通的旧均值= 0,方差= 1.这应该不起作用?我很感激人们理解卡尔曼滤波器的一些帮助,因为我想我可能会遗漏一些东西.
我在文件大小和已用磁盘空间之间存在差异(总文件大小甚至超过磁盘大小).我想因为在Windows 7/Vista中存在许多硬链接(对于WinSxS组件).但是,如何以编程方式将硬链接与Windows 7中的真实文件区分开来?
为什么这不适用于java,但确实如此
Map<String, Map<String, Boolean>> myMap = new HashMap<String,Map<String,Boolean>>();
Run Code Online (Sandbox Code Playgroud)
只是为了澄清下面对嵌套HashMap的更改显示了编译器错误,而上面并没有; 用地图(不是hashmap)
Map<String, Map<String, Boolean>> myMap = new HashMap<String,HashMap<String,Boolean>>();
Run Code Online (Sandbox Code Playgroud) 嗨Stackoverflowers,我在这个问题上花了太多时间来保持理智,所以是时候寻求帮助了...
我有一个使用此方法的类:
def telecom_info
Rails.cache.fetch("telecom_info_for_#{ref_num}", :expires_in=> 3.hours) do
info = Hash.new(0)
Telecom::SERVICES.each do |source|
results = TelecomUsage.find(:all,
:joins=>[:telecom_invoice=>{ :person=> :org_person}],
:conditions=>"dotted_ids like '%#{ref_num}%' and telecom_usages.ruby_type = '#{source}'",
:select=>"avg(charge) #{source.upcase}_AVG_CHARGE,
max(charge) #{source.upcase}_MAX_CHARGE,
min(charge) #{source.upcase}_MIN_CHARGE,
sum(charge) #{source.upcase}_CHARGE,
avg(volume) #{source.upcase}_AVG_VOLUME,
max(volume) #{source.upcase}_MAX_VOLUME,
min(volume) #{source.upcase}_MIN_VOLUME,
sum(volume) #{source.upcase}_VOLUME
")
results = results.first
['charge', 'volume'].each do |source_type|
info["#{source}_#{source_type}".to_sym] = results.send("#{source}_#{source_type}".downcase).to_i
info["#{source}_min_#{source_type}".to_sym] = results.send("#{source}_min_#{source_type}".downcase).to_i
info["#{source}_max_#{source_type}".to_sym] = results.send("#{source}_max_#{source_type}".downcase).to_i
info["#{source}_avg_#{source_type}".to_sym] = results.send("#{source}_avg_#{source_type}".downcase).to_i
end
end
return info
end
end
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,这是一个昂贵的调用,每个请求都会调用ALOT,因此我想缓存它.问题是memcached似乎不起作用,在日志文件中,我得到:
缓存读取:telecom_info_for_60000000
缓存未命中:telecom_info_for_60000000({})
奇怪的是,我知道memcached正在工作,因为它确实缓存了我在另一个模型中的其他一些函数的结果.
有什么建议?我在REE 1.8.7上运行Rails 2.3.5
我正在开发基于Web的Java应用程序[GWT]
我面临着TwitterException的问题.
我使用了有效的凭证.
Twitter twitter =新推特(myTwitterId,myTwiterPwd);
当我调用twitter.getFollowers()方法时
我收到了以下错误消息
twitter4j.TwitterException: 401:Authentication credentials were missing or incorrect.
<?xml version="1.0" encoding="UTF-8"?>
<errors>
<error code="53">Basic authentication is not supported</error>
</errors>
at twitter4j.http.HttpClient.httpRequest(HttpClient.java:469)
at twitter4j.http.HttpClient.get(HttpClient.java:412)
at twitter4j.Twitter.get(Twitter.java:276)
at twitter4j.Twitter.get(Twitter.java:228)
at twitter4j.Twitter.getFollowersStatuses(Twitter.java:1363)
at twitter4j.Twitter.getFollowers(Twitter.java:1350)
at com.vaibhav.dealelephant.server.impl.TwitterServiceImpl.getTwitterFollowers(TwitterServiceImpl.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:562)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:188)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:224)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
at …Run Code Online (Sandbox Code Playgroud) 当我构建我的项目(任何项目,真的 - 我尝试创建一个具有相同结果的新空项目)时,它可以在Xcode4或Xcode 3.2.4下使用GCC 4.2构建.
如果我使用Xcode4下的LLVM 2.0或Xcode3下的LLVM 1.5构建,我会遇到编译时构建失败,但只有在为模拟器构建时才会.
我在LLVM下获得的构建错误都在我无法控制的标题中,例如UIKit中的UIView.h,UIDevice.h,UIApplication.h,UITextView.h和UIWebView.h以及CoreGraphics中的CGPDFContext.h.
这是WebView.h中的示例错误:
@property(nonatomic) UIDataDetectorTypes dataDetectorTypes __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_3_0); //<--- Unknown type 'UIDataDetectorTypes'
Run Code Online (Sandbox Code Playgroud)
当UIDataDetectorTypes确实在UIDataDetectors.h中声明时,它包含在该文件中.
吸气