在Ubuntu 10.04上默认安装了Python 2.6,然后我安装了Python 2.7.我如何使用pip install安装Python 2.7的包.
例如:
pip install beautifulsoup4
Run Code Online (Sandbox Code Playgroud)
默认情况下,安装BeautifulSoup for Python 2.6
当我做:
import bs4
Run Code Online (Sandbox Code Playgroud)
在Python 2.6中它可以工作,但在Python 2.7中它说:
No module named bs4
Run Code Online (Sandbox Code Playgroud) 我有两个组件: Parent Component,我想从中更改子组件的状态:
class ParentComponent extends Component {
toggleChildMenu() {
?????????
}
render() {
return (
<div>
<button onClick={toggleChildMenu.bind(this)}>
Toggle Menu from Parent
</button>
<ChildComponent />
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
和儿童组成部分:
class ChildComponent extends Component {
constructor(props) {
super(props);
this.state = {
open: false;
}
}
toggleMenu() {
this.setState({
open: !this.state.open
});
}
render() {
return (
<Drawer open={this.state.open}/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我需要从Parent Component 更改Child Component的打开状态,或者在单击Parent Component中的Button时从Parent Component 调用Child Component的toggleMenu()?
推荐的参数是什么CascadeClassifier::detectMultiScale(),取决于我应该更改默认参数的因素?
void CascadeClassifier::detectMultiScale(
const Mat& image,
vector<Rect>& objects,
double scaleFactor=1.1,
int minNeighbors=3,
int flags=0,
Size minSize=Size(),
Size maxSize=Size() )
Run Code Online (Sandbox Code Playgroud) 我有这个:
g_c = 0
class TestClass():
global g_c
def run(self):
for i in range(10):
g_c = 1
print g_c
t = TestClass()
t.run()
print g_c
Run Code Online (Sandbox Code Playgroud)
我怎样才能真正修改我的全局变量g_c?
我从[python web site]复制了这个脚本[1]这是另一个问题,但现在编码问题:
import sqlite3
import csv
import codecs
import cStringIO
import sys
class UTF8Recoder:
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8
"""
def __init__(self, f, encoding):
self.reader = codecs.getreader(encoding)(f)
def __iter__(self):
return self
def next(self):
return self.reader.next().encode("utf-8")
class UnicodeReader:
"""
A CSV reader which will iterate over lines in the CSV file "f",
which is encoded in the given encoding.
"""
def __init__(self, f, dialect=csv.excel, encoding="utf-8", **kwds):
f = UTF8Recoder(f, encoding)
self.reader = …Run Code Online (Sandbox Code Playgroud) 我在我的本地机器上做了简单的性能测试,这是python脚本:
import redis
import sqlite3
import time
data = {}
N = 100000
for i in xrange(N):
key = "key-"+str(i)
value = "value-"+str(i)
data[key] = value
r = redis.Redis("localhost", db=1)
s = sqlite3.connect("testDB")
cs = s.cursor()
try:
cs.execute("CREATE TABLE testTable(key VARCHAR(256), value TEXT)")
except Exception as excp:
print str(excp)
cs.execute("DROP TABLE testTable")
cs.execute("CREATE TABLE testTable(key VARCHAR(256), value TEXT)")
print "[---Testing SQLITE---]"
sts = time.time()
for key in data:
cs.execute("INSERT INTO testTable VALUES(?,?)", (key, data[key]))
#s.commit()
s.commit()
ste = time.time()
print …Run Code Online (Sandbox Code Playgroud) 我默认使用ubuntu 10.04和python2.6.我安装了python2.7.
当我想安装python包时
apt-get python-<package>
Run Code Online (Sandbox Code Playgroud)
它被安装到python2.6.如何才能将软件包安装到python2.7?有什么选择吗?
我看过这个,但我在操作系统中找不到这样的目录.我考虑过使用easy_install-2.7,但不支持所有软件包.例如python-torctl.
我更感兴趣的是绑定python2.7 apt-get install.
我想在学习模型时使用 k 折交叉验证。到目前为止,我是这样做的:
# splitting dataset into training and test sets
X_train, X_test, y_train, y_test = train_test_split(dataset_1, df1['label'], test_size=0.25, random_state=4222)
# learning a model
model = MultinomialNB()
model.fit(X_train, y_train)
scores = cross_val_score(model, X_train, y_train, cv=5)
Run Code Online (Sandbox Code Playgroud)
在这一步,我不太确定是否应该使用 model.fit() ,因为在sklearn的官方文档中,它们不适合,而只是调用 cross_val_score 如下(它们甚至不将数据拆分为训练和测试集):
from sklearn.model_selection import cross_val_score
clf = svm.SVC(kernel='linear', C=1)
scores = cross_val_score(clf, iris.data, iris.target, cv=5)
Run Code Online (Sandbox Code Playgroud)
我想在学习模型的同时调整模型的超参数。什么是正确的管道?
我想在使用redis的python中编写应用程序.我用谷歌搜索,但我找不到任何问题的结果.通常,我这样做:
import redis
rs = redis.Redis('localhost')
Run Code Online (Sandbox Code Playgroud)
然后做所有得到和设置.但我可以在redis中做这样的事情:
rs1 = redis.Redis('app1')
rs2 = redis.Redis('app2')
Run Code Online (Sandbox Code Playgroud)
我的意思是,我想使用两个或更多实例,每个实例存储不同的东西(例如rs1用于url,rs2用于标题等等).而且我想知道如何删除所有键(例如在rs1中删除所有记录).任何好的教程,资源?注意:我需要使用redis,因为我需要执行快速检查和存储,就像url-seen for crawler一样.
我已经按照本教程验证了XML文件.但是在验证XML文件时我收到了异常.我做错了什么?我的代码:
XML架构:
<?xml version="1.0" encoding="utf-8" ?>
<!-- definition of simple elements -->
<xs:element name="first_name" type="xs:string" />
<xs:element name="last_name" type="xs:string" />
<xs:element name="phone" type="xs:string" />
<!-- definition of attributes -->
<xs:attribute name="type" type="xs:string" use="required"/>
<xs:attribute name="date" type="xs:date" use="required"/>
<!-- definition of complex elements -->
<xs:element name="reporter">
<xs:complexType>
<xs:sequence>
<xs:element ref="first_name" />
<xs:element ref="last_name" />
<xs:element ref="phone" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="report">
<xs:complexType>
<xs:attribute ref="type"/>
<xs:attribute ref="date" />
<xs:sequence>
<xs:element ref="reporter" />
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
要验证的XML文件:
<?xml version="1.0" encoding="utf-8" …Run Code Online (Sandbox Code Playgroud) python ×6
redis ×2
c++ ×1
csv ×1
installation ×1
java ×1
javascript ×1
linux ×1
opencv ×1
pip ×1
python-3.x ×1
reactjs ×1
scikit-learn ×1
sql ×1
sqlite ×1
ubuntu ×1
xml ×1
xsd ×1