小编use*_*184的帖子

ImportError:没有名为twisted.internet的模块

我安装了python 2.7.5,工作正常.

然后我安装scrapy(我认为,它使用内部扭曲).我的scrapy蜘蛛也很好用.

我安装了扭曲:

sudo apt-get install python-twisted

然后,我使用此处显示的Echo Server代码创建了一个示例程序

这是代码

from twisted.internet import protocol, reactor


class Echo(protocol.Protocol):
    def dataReceived(self, data):
        self.transport.write(data)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()

reactor.listenTCP(1234, EchoFactory())
reactor.run()
Run Code Online (Sandbox Code Playgroud)

我尝试使用此命令运行此代码:

$ python twistedTester.py 
Traceback (most recent call last):
  File "twistedTester.py", line 1, in <module>
    from twisted.internet import protocol, reactor
ImportError: No module named twisted.internet
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮助我如何调试为什么我的扭曲包没有被Python安装拾取?

twisted python-2.7

15
推荐指数
3
解决办法
5万
查看次数

我什么时候应该同步我班级的方法?

我正在考虑创建一个类(如String,StringBuffer等).这可以在单线程和多线程环境中使用.我不知道开发人员可能正在使用哪种环境.预计最坏的情况,我可以同步.

但是,1.同步会带来性能损失.2.没有同步,它不是线程安全的.

所以,我有两个选择.

  1. 保持类不同步 - 但使用此类的开发人员需要在适当时同步它.
  2. 拥有所有同步方法 - 并取得性能影响.

我已经看到Java中的许多(如果不是全部.例如,ArrayList over Vector)类已经演变为采用第一种方法.在为我的班级决定这两个选项之前,我需要考虑哪些事项?

Or to put it in a different way, should I use "public synchronized void bar()" over "public void bar()" only when I know for sure that bar can be used in a multi-threaded environment and should not be run at the same time?

EDIT So, clearly I have mis-used the word "utility class" in the heading. Thanks, Jon Skeet, for pointing it out. I have removed the world …

java

8
推荐指数
1
解决办法
470
查看次数

Google Spreadsheet API - Java - com.google.gdata.util.ParseException:无法识别的内容类型:application/binary

我在简单的Android应用程序中使用Google Spreadsheet API.这是一段代码:

URL spreadSheetUrl = new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full");
SpreadsheetQuery query = new SpreadsheetQuery(spreadSheetUrl);
query.setTitleQuery("xyz");
query.setTitleExact(true);
SpreadsheetFeed spreadSheetFeed = service.getFeed(query, SpreadsheetFeed.class);
Run Code Online (Sandbox Code Playgroud)

从我的应用程序的同步适配器调用这段代码.

我收到此错误:

com.google.gdata.util.ParseException: Unrecognized content type:application/binary
com.google.gdata.client.Service.parseResponseData(Service.java:2136)
com.google.gdata.client.Service.parseResponseData(Service.java:2098)
com.google.gdata.client.Service.getFeed(Service.java:1136)
com.google.gdata.client.Service.getFeed(Service.java:1077)
com.google.gdata.client.GoogleService.getFeed(GoogleService.java:676)
com.google.gdata.client.Service.getFeed(Service.java:1034)
Run Code Online (Sandbox Code Playgroud)

有人可以建议我如何解决这个问题吗?

android google-sheets google-spreadsheet-api

5
推荐指数
1
解决办法
2387
查看次数

无法将“聚合物”识别为内部或外部命令

我最近安装了nodejs,bower。然后,我使用以下命令安装了Polymer:

npm install -g polymer

然后,我添加了聚合物安装路径:

C:\Users\<user>\AppData\Roaming\npm

然后,我正在尝试做polymer init。我看到此错误:

无法将“聚合物”识别为内部或外部命令,可操作程序或批处理文件。

有人可以建议我如何使聚合物起作用吗?

command-prompt polymer polymer-cli

3
推荐指数
1
解决办法
3153
查看次数

jQuery ajax()调用失败

我正在编写一个基于Web的应用程序,它调用服务器来从REST-ful应用程序更新服务器中的特定对象.

这是我写的javascript代码.

var sendUrl = url + "v1/items/" + itmId;
$.ajax({
    "type": "PUT",
    "url": sendUrl,
    //"data": {"name": nameVal, "description": descVal},
    "success": function() {
        alert('hai');  //refreshItems();
    },
    "complete": function (jqXHR, textStatus) {
        alert (textStatus);
    }
});
Run Code Online (Sandbox Code Playgroud)

执行此代码时,服务器未收到任何请求.浏览器未显示任何更新.

我使用谷歌浏览器作为我的浏览器.所以,我查看了Chrome的Javascript控制台,控制台显示了以下错误:

Chrome控制台出错

这个问题有什么可能的解决方案吗?


编辑:

正如其中一条评论中所建议的那样,我试着研究网络面板.它似乎没有调用Server.

这是此特定请求的屏幕截图: 在此输入图像描述

图像非常小.状态为"(失败)","类型"为"待定"

如果服务器未配置PUT,则会导致内部服务器错误.所以,这不会发生在这里.


编辑

在尝试答案中给出的建议后,

这是代码:

var sendUrl = url + "v1/items/" + itmId;
$.ajax({
    "type": "PUT",
    "url": sendUrl,
    //"data": {"name": nameVal, "description": descVal},
    }).done(function ( ) {
        alert('OK');
    }).fail(function ( jqXHR, textStatus, errorThrown ) {
        console.log(jqXHR);
        console.log(textStatus);
        console.log(errorThrown);
    }); …
Run Code Online (Sandbox Code Playgroud)

ajax jquery

2
推荐指数
1
解决办法
1万
查看次数