我想在python中从键盘读取数据
我试试这个:
nb = input('Choose a number')
print ('Number%s \n' % (nb))
Run Code Online (Sandbox Code Playgroud)
但它不起作用,既不是日食也不是终端,它总是停止问题.我可以输入一个数字,但没有任何事情发生.
你知道为什么吗?
我正在创建一个wcf服务,我的wcf服务现在托管在一个控制台应用程序中,如下所示
PersonService = new ServiceHost(typeof(PersonService));
PersonService.AddServiceEndpoint(typeof(IPersonService), binding, "http://localhost:5645/PersonService");
PersonService.Open();
Run Code Online (Sandbox Code Playgroud)
然后我使用ChannelFactory类消耗wcf服务;
EndpointAddress endPoint = new EndpointAddress("http://localhost:5645/PersonService");
ChannelFactory<IPersonService> engineFactory = new ChannelFactory<IPersonService>(binding, endPoint);
IPersonService personChannel = engineFactory.CreateChannel();
Run Code Online (Sandbox Code Playgroud)
然后我可以使用此通道调用方法,如
personChannel.GetPersonById("1");
personChannel.Close();
Run Code Online (Sandbox Code Playgroud)
我的问题是:
如上面的代码所示,在完成工作后关闭通道时,服务始终打开.这是保持服务打开的良好行为,或者我应该打开服务然后在每次呼叫时关闭它,同时考虑到我可能有两个客户同时呼叫同一服务.
请指教.
在任何需要运行时值来构造特定依赖项的地方,Abstract Factory就是解决方案.
我的问题是:为什么很多来源都赞成FactoryInterface而不是FactoryDelegate来实现这种模式?两种解决方案的优缺点是什么?
这是一个了解我的意思的例子
如果您的服务需要具有特定上下文的存储库,则服务构造函数需要工厂来创建或访问其存储库.
对此的常见解决方案是创建这样的RepositoryFactoryInterface.
public IRepositoryFactory {
IRepository Create(ContextInformation context);
}
public class MyService {
private IRepositoryFactory repositoryFactory;
public MyService(IRepositoryFactory repositoryFactory)
{
this.repositoryFactory = repositoryFactory:
}
public void DoSomeService()
{
ContextInformation context = ....;
IRepository repository = this.repositoryFactory.Create(context);
repository.Load(...);
...
repository.Save(...);
}
}
Run Code Online (Sandbox Code Playgroud)
您还需要以某种方式实现IRepositoryFactory接口
public MyEf4RepositoryFactory : IRepositoryFactory
{
IRepository Create(ContextInformation context)
{
return new MyEf4Repository(context);
}
}
Run Code Online (Sandbox Code Playgroud)
...并在应用程序中使用它
public void main()
{
IRepositoryFactory repoFactory = new MyEf4RepositoryFactory();
IService service = new MyService(repoFactory);
service.DoSomeService();
}
Run Code Online (Sandbox Code Playgroud)
-----主流解决方案结束------ …
我目前正在研究一些相当古老的C++代码,并经常发现类似的东西
int i;
i = 42;
Run Code Online (Sandbox Code Playgroud)
要么
Object* someObject = NULL;
someObject = new Object();
Run Code Online (Sandbox Code Playgroud)
甚至
Object someObject;
someObject = getTheObject();
Run Code Online (Sandbox Code Playgroud)
我完全理解这段代码的作用,但我真的不知道变量定义和初始化的这种分离是否有用.我搜索了一些解释,但总是最终得到成员初始化列表或者应该定义局部变量的问题.
最后,我不明白为什么有人可能故意编写这段代码.它只是将定义和初始化分成两个后续行并创建开销 - 在最后一种情况下,它使用默认构造函数创建一个对象,仅在下一行中销毁它.
我想知道我是否应该简单地将代码更改为
int i = 42;
Object* someObject = new Object();
Object someObject = getTheObject();
Run Code Online (Sandbox Code Playgroud)
这会导致任何问题吗?
我正在开发我的第一个iPhone应用程序.我必须每隔x秒用设备速度更新一个标签.我创建了自己的CLController,我可以获得设备速度,但我不知道是否必须使用NSTimer更新我的标签.我该怎么做?
我正在尝试使用jQuerys post-function将表单发布到CakePHP脚本.
像这样:
jQuery的:
$('#submit_btn').click(function(){
//Code to prevent redirect
dataString = 'test=testdata';
$.post('cakephp/forms/output', dataString, function(response){
alert(response);
})
});
Run Code Online (Sandbox Code Playgroud)
CakePHP的
function output(){
pr($this->data); # Print nothing
pr($_POST); # Print test => testdata
$this->render('view','ajax'); # Render ajax-friendly
}
Run Code Online (Sandbox Code Playgroud)
所以$_POST不是空的但是$this->data......怎么样?
发布数据的表单元素i来自aja,如果这是在这种情况下重要的事情.
我在Windows上使用SWI-Prolog并收到以下错误:
14 ?- parent(X, Y) :- child(Y, X).
ERROR: toplevel: Undefined procedure: (:-)/2 (DWIM could not correct)
Run Code Online (Sandbox Code Playgroud)
我不完全确定发生了什么,因为这上周工作,我刚开始学习Prolog.
可能这是一个愚蠢的问题.我想摆脱数字的小数部分Double.但我不能这样做.它显示了不兼容类型的错误.该怎么办?
Double to int 转换成一行....请帮助谢谢
我已经定义了一个UIWebViewDelegate类并在我的UIWebView的Delegate属性中实例化了它,但是当webview加载请求时,没有调用ShouldStartLoad方法.我究竟做错了什么?
这是定义我的UIWebViewDelegate和我的UIWebView的代码:
public class MyWebViewDelegate: UIWebViewDelegate
{
private UIWebView _view;
public MyWebViewDelegate (UIWebView view)
{
_view = view;
}
public override bool ShouldStartLoad (UIWebView webView,
MonoTouch.Foundation.NSUrlRequest request,
UIWebViewNavigationType navigationType)
{
System.Console.WriteLine("Starting load");
return true;
}
}
public class MyWebView : UIWebView
{
private static MyWebView _instance = new MyWebView ();
private MyWebView () : base()
{
this.Delegate = new MyWebViewDelegate(this);
}
public static MyWebView Instance {
get { return _instance; }
}
public void Load ()
{
this.LoadRequest (new NSUrlRequest(NSUrl.FromString("http://myurl"), …Run Code Online (Sandbox Code Playgroud) .net ×2
java ×2
c# ×1
c++ ×1
cakephp-1.3 ×1
cllocation ×1
cocoa-touch ×1
definition ×1
input ×1
ios ×1
jquery ×1
keyboard ×1
nstimer ×1
post ×1
prolog ×1
python ×1
variables ×1
wcf ×1
wcf-client ×1
xamarin ×1
xamarin.ios ×1