我正在为Python创建一个微博(Twitter和Status.Net)库,并希望为它创建单元测试.我不太确定这样做的最好方法.
显然,从服务返回的数据每次都会有所不同 - 会有新的帖子等.另外,我不能强迫Twitter失败鲸鱼来测试.
使用Status.Net,我可以想象设置一个私人服务器用于测试,但似乎必须有一个更好的方法.
我的(第一个!)Python程序中有两个函数,只有必须实例化的类才有所不同.
def f(id):
c = ClassA(id)
...
return ...
def g(id):
c = ClassB(id)
...
return ...
Run Code Online (Sandbox Code Playgroud)
为了避免重复代码,我希望能够编写一个单独的函数,以某种方式接受该类作为参数进行实例化.
def f(id):
return f_helper(id, ... ClassA ...)
def g(id):
return f_helper(id, ... ClassB ...)
def f_helper(id, the_class):
c = ... the_class ... (id)
...
return ...
Run Code Online (Sandbox Code Playgroud)
我很确定这是可能的,但没有找到......
我有使用RQuantlib库的R代码.为了从python运行它我使用RPy2.我知道python有自己的quantlib绑定(quantlib-python).我想完全从R切换到python.
请告诉我如何使用quantlib-python运行以下命令
import rpy2.robjects as robjects
robjects.r('library(RQuantLib)')
x = robjects.r('x<-EuropeanOptionImpliedVolatility(type="call", value=11.10, underlying=100,strike=100, dividendYield=0.01, riskFreeRate=0.03,maturity=0.5, volatility=0.4)')
print x
Run Code Online (Sandbox Code Playgroud)
样品运行:
$ python vol.py
Loading required package: Rcpp
Implied Volatility for EuropeanOptionImpliedVolatility is 0.381
Run Code Online (Sandbox Code Playgroud) 我试图让一个函数从另一个页面上的php文件中获取一个对象.我正在使用jQuery ajax函数来执行json抓取,这是正常的.问题是当我尝试从函数返回该对象时.
我第一次记录对象(在成功函数内)它在控制台中是正确的,但函数getGantt()返回的对象记录为"未定义".
如何从函数中获取此对象?
我的代码:
function getGantt(requestNumber){
var ganttObject;
$.ajax({
type: "POST",
url: "get_gantt.php",
data: {request_number: requestNumber},
success: function(returnValue){
ganttObject = $.parseJSON(returnValue);
console.log(ganttObject); //this logs a correct object in the console
}
});
return ganttObject;
}
$(function(){ //document ready function
var requestNumber = $('#request_number').text();
var ganttObject = getGantt(requestNumber);
console.log(ganttObject); //this logs "undefined"
}); //end document ready function
Run Code Online (Sandbox Code Playgroud) 我有一个模特,Foo.它具有多个数据库属性,以及基于多个因素组合计算的多个属性.我想将这些计算出的属性呈现给用户,就好像它们是数据库属性一样.(支持因素将被更改以反映用户输入.)有没有办法使用Django管理界面?
尝试git clone git://github.com/ry/node.git不起作用的东西会导致:
Initialized empty Git repository in /home/robert/node/.git/
github.com[0: 207.97.227.239]: errno=Connection timed out
fatal: unable to connect a socket (Connection timed out)
Run Code Online (Sandbox Code Playgroud)
但是,通过HTTP克隆工作正常.到目前为止,我已经收集到这是协议的问题,但我正在尝试安装需要命令的cloud9
git submodule update --init --recursive
它试图使用git://协议并失败.有没有办法改变命令的工作方式?
伙计们,
假设我使用来自线程10,11,12的CallContext.SetData()来存储三个新的对象Car实例.这些线程完成执行.然后我执行另一个使用线程10,11,12的多线程操作(可能与第一个不同的操作).GetData()将检索我存储的相同三个对象吗?或者现在上下文有些不同,那些对象消失了?
我的特定用例是任务并行库.我正在使用TPL来并行化一些操作,我想了解在TPL调用之间通过CallContext.SetData()存储的数据会发生什么.
编辑
Per @wageoghe建议我尝试了ThreadLocal并且它有效!
更新代码以证明它:
using System;
using System.Threading;
using System.Threading.Tasks;
namespace TlsTest
{
public class Program
{
public static void Main()
{
Console.WriteLine( "-------using threadpool---------" );
UseThreadPool();
Console.WriteLine( "-------using tasks---------" );
UseTasks();
Console.WriteLine( "-------using parallel for---------" );
UseParallelFor();
Console.ReadKey();
}
public static void UseThreadPool()
{
var finish = new CountdownEvent( TotalThreads );
for ( int i = 0 ; i < TotalThreads ; i++ )
{
ThreadPool.QueueUserWorkItem( x =>
{
int id = Thread.CurrentThread.ManagedThreadId;
Thread.Sleep( SleepMilliseconds ); …Run Code Online (Sandbox Code Playgroud) 我第一次使用WPF,特别是使用我想绑定到ObservableCollection的ListView,后者是代码隐藏页面上的属性.现在我只是想了解事情是如何运作的,所以我试着保持这个简单.不幸的是,我不太清楚我在哪里出错了.
我的代码隐藏页面有一个如下所示的属性:
public ObservableCollection<Code> Code { get; set; }
Run Code Online (Sandbox Code Playgroud)
我在表单上有一个按钮,用于查询和填充Code属性.
Code类是一个简单的POCO类:
public class Code
{
public string Line { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我在XAML窗口中添加了一个命名空间:
<Window x:Class="SampleWPF.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SampleWPF"
Title="MainWindow" Height="350" Width="525"
>
Run Code Online (Sandbox Code Playgroud)
ListView看起来像这样:
<DockPanel Height="311" HorizontalAlignment="Left" Name="dockPanel1"
VerticalAlignment="Top" Width="182">
<ListView Name="lstCode"
ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Window, AncestorLevel=1}, Path=Code}"
DisplayMemberPath="Line">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Line}" />
</GridView>
</ListView.View>
</ListView>
</DockPanel>
Run Code Online (Sandbox Code Playgroud)
我还尝试在构造函数后面的代码中设置DataContext,没有运气,例如:
this.DataContext = this;
Run Code Online (Sandbox Code Playgroud)
编辑:将此行移至创建集合的代码行后固定的东西(以及建议的其他更改).
我还尝试在代码中显式设置ItemsSource(在我的点击处理程序中):
this.lstCode.ItemsSource = this.Code;
Run Code Online (Sandbox Code Playgroud)
我看了很多例子,但我在这里仍然遗漏了一些东西(并不是真的很惊讶).
在ASP.NET MVC中,如果我使用:
<%Response.Write(Url.Action("Index","usermanagement",new RouteValueDictionary(new {page ="{0}"}))); %>
我明白了:
/ usermanagement?页=%7B0%7D
但我想得到:
/ usermanagement?页= {0}
为什么它是encondig我的参数值,我该怎么做才能编写未编码的参数值?
谢谢
python ×4
.net ×1
.net-3.5 ×1
.net-4.0 ×1
ajax ×1
asp.net-mvc ×1
django ×1
django-admin ×1
function ×1
git ×1
github ×1
javascript ×1
jquery ×1
lua ×1
quantlib ×1
r ×1
rpy2 ×1
unit-testing ×1
view ×1
web-services ×1
wpf ×1