我想pip install的MySQL-python包,但我得到的ImportError.
Jans-MacBook-Pro:~ jan$ /Library/Frameworks/Python.framework/Versions/3.3/bin/pip-3.3 install MySQL-python
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in <module>
from setup_posix import get_config
File "./setup_posix.py", line 2, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/var/folders/lf/myf7bjr57_jg7_5c4014bh640000gn/T/pip-build/MySQL-python/setup.py", line 14, in …Run Code Online (Sandbox Code Playgroud) 我试图获取当前检查的所有复选框的值并将它们存储到数组中.到目前为止,这是我的代码:
$("#merge_button").click(function(event){
event.preventDefault();
var searchIDs = $("#find-table input:checkbox:checked").map(function(){
return $(this).val();
});
console.log(searchIDs);
});
Run Code Online (Sandbox Code Playgroud)
然而,这比我需要的更多.我不仅得到了价值,还有其他一些我不想要的东西.
["51729b62c9f2673e4c000004","517299e7c9f26782a7000003","51729975c9f267f3b5000002",prevObject:jQuery.fn.jQuery.init [3],context:document,jquery:"1.9.1",constructor:function,init:function ...]
我想要ID(在这种情况下前3项).
通过使用$.each值并将值推送到数组,我获得了所需的输出:
$("#find-table input:checkbox:checked").each(function(){ myArray.push($(this).val()); })
Run Code Online (Sandbox Code Playgroud)
["51729b62c9f2673e4c000004","517299e7c9f26782a7000003","51729975c9f267f3b5000002"]
但是我想使用$.map它,因为它为我节省了一行代码并且更漂亮.
谢谢
我是python3的新手,来自python2,我对unicode基础知识有点困惑.我已经阅读了一些好的帖子,这使得它更加清晰,但是我看到python 3上有2个方法,它们处理编码和解码,我不确定使用哪个方法.
所以python 3中的想法是,每个字符串都是unicode,可以编码并以字节存储,或者再次解码回unicode字符串.
但是有两种方法可以做到:
u'something'.encode('utf-8')生成b'bytes',但同样如此bytes(u'something', 'utf-8').
并且b'bytes'.decode('utf-8')似乎做同样的事情str(b'', 'utf-8').
现在我的问题是,为什么有两种方法似乎做同样的事情,并且要么比另一种更好(为什么?)我一直试图在谷歌找到答案,但没有运气.
>>> original = '27?????????'
>>> type(original)
<class 'str'>
>>> encoded = original.encode('utf-8')
>>> print(encoded)
b'27\xe5\xb2\x81\xe5\xb0\x91\xe5\xa6\x87\xe7\x94\x9f\xe5\xad\xa9\xe5\xad\x90\xe5\x90\x8e\xe5\x8f\x98\xe8\x80\x81'
>>> type(encoded)
<class 'bytes'>
>>> encoded2 = bytes(original, 'utf-8')
>>> print(encoded2)
b'27\xe5\xb2\x81\xe5\xb0\x91\xe5\xa6\x87\xe7\x94\x9f\xe5\xad\xa9\xe5\xad\x90\xe5\x90\x8e\xe5\x8f\x98\xe8\x80\x81'
>>> type(encoded2)
<class 'bytes'>
>>> print(encoded+encoded2)
b'27\xe5\xb2\x81\xe5\xb0\x91\xe5\xa6\x87\xe7\x94\x9f\xe5\xad\xa9\xe5\xad\x90\xe5\x90\x8e\xe5\x8f\x98\xe8\x80\x8127\xe5\xb2\x81\xe5\xb0\x91\xe5\xa6\x87\xe7\x94\x9f\xe5\xad\xa9\xe5\xad\x90\xe5\x90\x8e\xe5\x8f\x98\xe8\x80\x81'
>>> decoded = encoded.decode('utf-8')
>>> print(decoded)
27?????????
>>> decoded2 = str(encoded2, 'utf-8')
>>> print(decoded2)
27?????????
>>> type(decoded)
<class 'str'>
>>> type(decoded2)
<class 'str'>
>>> print(str(b'27\xe5\xb2\x81\xe5\xb0\x91\xe5\xa6\x87\xe7\x94\x9f\xe5\xad\xa9\xe5\xad\x90\xe5\x90\x8e\xe5\x8f\x98\xe8\x80\x81', 'utf-8'))
27????????? …Run Code Online (Sandbox Code Playgroud) 我喜欢Vim.但它现在让我很难过.
我使用了很多插件,在过去的6个月里,我发现了很多很棒的插件.但我的Vim也非常迟钝.我不断清理,但没有多大帮助.
我就是这样,Vim完全无法使用.感觉它呈现每秒2-5帧,切换标签/缓冲区需要大约一秒钟,滚动hjkl非常糟糕,滞后是如此糟糕,甚至在插入模式中键入句子令人困惑(由于滞后).
编辑:实际上,当我打开Vim的新实例时,OK-ish,但在15分钟内它变得无法使用.
我花了4个小时试图找出导致痛苦的插件或配置.我没有成功.
但是,我确实发现,删除此设置会导致所有延迟消失:
syntax on
这3行与语法相结合使一切变得更糟.
set t_Co=256
set background=dark
colorscheme candyman
Run Code Online (Sandbox Code Playgroud)
有趣.那么,语法突出显示将Vim从超级活泼变为令人难以置信的迟缓?
我尝试在"干净"模式下启用语法:
vim -u NONE
这不是问题.
所以似乎问题是Syntax Highlighting与我的一个或多个插件结合使用.我试过禁用一堆,没有运气.
有什么方法可以进行分析吗?手动测试我很累.
有没有人有类似的经历?也许快速浏览一下.vimrc,看看有什么响铃.
https://bitbucket.org/furion/dotfiles
解决方案: 导致混乱的插件是:
Bundle "gorodinskiy/vim-coloresque.git"
Run Code Online (Sandbox Code Playgroud)
我建议阅读答案,好的见解.
编辑(1个月后): coloresque插件已经看到一些改进.
我试图在VIM中自定义Enter密钥Normal模式的行为.这是我的.vimrc:
nmap <CR> o<Esc>
nmap <S-CR> i<CR><Esc>
Run Code Online (Sandbox Code Playgroud)
我试图让Enter在按下当前行之后简单地追加换行符.但是,如果Shift-Enter按下组合,我想打破光标处的当前行.
后者不起作用.每当我按下Shift-Enter它时,只需附加一行而不会在光标处打破它.
好的,我已经下载了Go 1.1并将其放入$ HOME/Documents/go.
然后,我修改了我的.bashrc:
export GOPATH=$HOME/Documents/go
export GOROOT=$GOPATH
export GOARCH=amd64
export GOOS=linux
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
Run Code Online (Sandbox Code Playgroud)
比我来源了.bashrc,并试过:
jan@janpc:~$ go version
go version go1.1 linux/amd64
Run Code Online (Sandbox Code Playgroud)
但我无法编译或安装任何依赖项.例如.我尝试运行我的小测试程序:
jan@janpc:~/Documents/go/src/github.com/jan/scrypt$ go run scrypt.go
warning: GOPATH set to GOROOT (/home/jan/Documents/go) has no effect
scrypt.go:9:3: cannot find package "github.com/dchest/scrypt" in any of:
/home/jan/Documents/go/src/pkg/github.com/dchest/scrypt (from $GOROOT)
($GOPATH not set)
jan@janpc:~/Documents/go/src/github.com/jan/scrypt$
Run Code Online (Sandbox Code Playgroud)
当我尝试安装依赖项时:
jan@janpc:~/Documents/go/src/github.com/jan/scrypt$ go get "github.com/dchest/scrypt"
warning: GOPATH set to GOROOT (/home/jan/Documents/go) has no effect
package github.com/dchest/scrypt: cannot download, $GOPATH must not be set …Run Code Online (Sandbox Code Playgroud) 我今天刚刚找到了pycrypto,我一直在研究我的AES加密类.不幸的是,只有一半的工作.self.h.md5以十六进制格式输出md5哈希值,为32byte.这是输出.它似乎解密了消息,但它在解密后放置了随机字符,在这种情况下\n \n \n ...我认为我的self.data块大小有问题,有谁知道如何解决这个问题?
Jans-MacBook-Pro:test2 jan $ ../../bin/python3 data.py b'RLfGmn5jf5WTJphnmW0hXG7IaIYcCRpjaTTqwXR6yiJCUytnDib + GQYlFORm + jIctest 1 2 3 4 5 endtest \n \n \n \n \n \n \n \n \n \n"
from Crypto.Cipher import AES
from base64 import b64encode, b64decode
from os import urandom
class Encryption():
def __init__(self):
self.h = Hash()
def values(self, data, key):
self.data = data
self.key = key
self.mode = AES.MODE_CBC
self.iv = urandom(16)
if not self.key:
self.key = Cfg_Encrypt_Key
self.key = self.h.md5(self.key, True)
def encrypt(self, data, key): …Run Code Online (Sandbox Code Playgroud) 我试图将此JS MongoDB查询转换为Go mgo查询:
var foo = "bar";
db.collection.find({"$or": [ {uuid: foo}, {name: foo} ] });
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所做的,但它不起作用:
conditions := bson.M{"$or": []bson.M{bson.M{"uuid": name}, bson.M{"name": name}}}
Run Code Online (Sandbox Code Playgroud)
编辑:它现在似乎工作.也许我在某个地方有一个错字.
我ng-repeat用来渲染一个html table.我的控制器看起来像这样:
app.controller("fooCtrl", function($scope, WebSocket) {
$scope.foo = [ ... ];
WebSocket.start(function(data) {
// this is a callback on websocket.onmessage
// here is a for loop iterating through $scope.foo objects and updating them
});
});
Run Code Online (Sandbox Code Playgroud)
如您所见,我$scope.foo定期更新阵列.但是,我的视图构造如下:
<tr ng-repeat="item in foo">
...
</tr>
Run Code Online (Sandbox Code Playgroud)
问题是,当我更新时foo,它不会使用新数据重新呈现我的表.
我该如何解决这个问题?
我正在尝试使用Go在MongoDB中插入一些数据.
这是数据结构:
type Entry struct {
Id string `json:"id",bson:"_id,omitempty"`
ResourceId int `json:"resource_id,bson:"resource_id"`
Word string `json:"word",bson:"word"`
Meaning string `json:"meaning",bson:"meaning"`
Example string `json:"example",bson:"example"`
}
Run Code Online (Sandbox Code Playgroud)
这是我的插入功能:
func insertEntry(db *mgo.Session, entry *Entry) error {
c := db.DB(*mongoDB).C("entries")
count, err := c.Find(bson.M{"resourceid": entry.ResourceId}).Limit(1).Count()
if err != nil {
return err
}
if count > 0 {
return fmt.Errorf("resource %s already exists", entry.ResourceId)
}
return c.Insert(entry)
}
Run Code Online (Sandbox Code Playgroud)
最后,这就是我所说的:
entry := &Entry{
ResourceId: resourceId,
Word: word,
Meaning: meaning,
Example: example,
}
err = insertEntry(db, entry)
if err …Run Code Online (Sandbox Code Playgroud)