我为django 1.9项目创建了virtualenv.我试图pip安装mysqlclient或mysql-python但他们两个都给我错误.
pip install mysqlclient
pip install mysql-python
Run Code Online (Sandbox Code Playgroud)
两个都给我相同的错误信息:
命令"python setup.py egg_info"失败,错误代码为1/private/var/folders/r4/bkv_4t9s4r140pjkgv6lsq8w0000gn/T/pip-build-cdxcssp9/mysqlclient
有什么建议!?
由于其并发期货模块,我刚刚转到python3.我想知道我是否可以让它来检测错误.我想将并发期货用于并行程序,如果有更高效的模块请告诉我.
我不喜欢多处理,因为它太复杂,没有太多的文档.然而,如果有人可以编写一个没有类的Hello World,那么将使用多处理来并行计算,这样很容易理解.
这是一个简单的脚本:
from concurrent.futures import ThreadPoolExecutor
def pri():
print("Hello World!!!")
def start():
try:
while True:
pri()
except KeyBoardInterrupt:
print("YOU PRESSED CTRL+C")
with ThreadPoolExecutor(max_workers=3) as exe:
exe.submit(start)
Run Code Online (Sandbox Code Playgroud)
上面的代码只是一个演示,关于CTRL + C如何无法打印satement.
我想要的是能够调用函数是一个错误存在.此错误检测必须来自函数本身.
另一个例子
import socket
from concurrent.futures import ThreadPoolExecutor
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
def con():
try:
s.connect((x,y))
main()
except: socket.gaierror
err()
def err():
time.sleep(1)
con()
def main():
s.send("[+] Hello")
with ThreadPoolExecutor as exe:
exe.submit(con)
Run Code Online (Sandbox Code Playgroud) python multiprocessing python-2.7 python-3.4 concurrent.futures
我有一个像这样定义的表:
Column | Type | Modifiers | Storage | Stats target | Description
-------------+---------+-----------+---------+--------------+-------------
id | uuid | not null | plain | |
user_id | uuid | | plain | |
area_id | integer | | plain | |
vote_amount | integer | | plain | |
Run Code Online (Sandbox Code Playgroud)
我希望能够在查询此数据库时生成排名"列".该列将按列排序vote_amount.我试图创建一个查询来执行此操作,它看起来像这样:
subq_rank = db.session.query(user_stories).add_columns(db.func.rank.over(partition_by=user_stories.user_id, order_by=user_stories.vote_amount).label('rank')).subquery('slr')
data = db.session.query(user_stories).select_entity_from(subq_rank).filter(user_stories.area_id == id).group_by(-subq_rank.c.rank).limit(50).all()
Run Code Online (Sandbox Code Playgroud)
希望我的尝试能让你了解我想要实现的目标.
谢谢.
我在一个简单的图像上使用 CSS 动画。
我希望脉冲动画仅针对图像的一部分。
我如何制作脉冲动画,以便只有文本“Trello”改变不透明度?
这是我的代码:
.element {
/*animation-delay: 2s;*/
animation: pulse 3s infinite;
margin: 0 auto;
display: table;
margin-top: 50px;
animation-direction: alternate;
}
@keyframes pulse {
0% {
opacity: 1;
}
100% {
opacity: 0.3;
}
}
html,
body {
height: 100%;
background-color: #e74c3c;
}Run Code Online (Sandbox Code Playgroud)
<img src="https://d78fikflryjgj.cloudfront.net/images/50b4ebc64391dc394a38e73aed57f0e2/header-logo.png" alt="" class="element" />Run Code Online (Sandbox Code Playgroud)
我需要帮助理解这个 sparql 查询的作用(要求):
SELECT ?subject ?object
WHERE { ?subject onto:personName ?object . ?w ?q ?s}
Run Code Online (Sandbox Code Playgroud)
这是来自于人的本体论。第一部分容易理解;一些未知的主题必须有一个具有未知值的 personName,但为什么第二部分相关?
这是我需要帮助理解的内容:当有两个模式(“.”之前和之后)时,这是否意味着节点必须同时匹配第一个和第二个模式?如果是这样,那么在这种情况下,第二个模式会说:“一些未知的主体必须有一些未知的谓词和一些未知的对象”,这将返回 RDF 图中的所有三元组......所以在这种情况下,第二个模式将匹配所有三元组,但结果将受到第一个模式的限制。
我的问题是,为什么第二个模式那么重要,因为它似乎只相当于第一个模式。但是当我运行它时,我得到了本体中的“所有”三元组,所以我需要准确理解查询的作用。
另外:如果我替换?w为会发生什么?object,从而绑定?object到 boh 模式,所以看起来:?object必须有一些谓词?q和一些对象?s,所以如果我替换?w为?object,它会找到模式 1 中的传递对象 ( ?s) ?object……换句话说:?subject --> onto:personName --> ?object --> ?q --> ?s。
通过 Oracle 使用 SQL
这是我的数据格式的模拟
Unique_id Search_Date Value
1 01-Jan-2015 3
1 02-Jan-2015 -5
1 03-Jan-2015 8
2 01-Jan-2015 17
2 02-Jan-2015 20
2 03-Jan-2015 -50
3 01-Jan-2015 4
3 02-Jan-2015 24
3 03-Jan-2015 -12
Run Code Online (Sandbox Code Playgroud)
我需要提取 max(value), min(value) PER unique_id 并且我需要提取这些聚合的确切 search_date。
有任何想法吗?我可以提取每个hotel_id 的最大值和最小值,但我不能提取search_date 值。
import os
def new_directory(directory, filename):
# Before creating a new directory, check to see if it already exists
# Create the new file inside of the new directory
# Return the list of files in the new directory
print(new_directory("PythonPrograms", "script.py"))
Run Code Online (Sandbox Code Playgroud) 数据文件是一个包含4列的Excel列表:名称,位置,值和价格.用pandas导入的文件.
有5个不同的职位.
我试图匹配所有不同的可能性,它们只能是每个位置中的一个+一个尚未被选中的随机玩家.
def teams(x):
positions = list(data.Position.unique())
indices = []
for position in positions:
indices.append((data.Position == position).nonzero()[0])
positions.append('Random')
indices.append(data.index)
for i in indices[0]:
for i2 in indices[1]:
for i3 in indices[2]:
for i4 in indices[3]:
for i5 in indices[4]:
for i6 in indices[5]:
if i6 != i:
if i6 != i2:
if i6 != i3:
if i6 != i4:
if i6 != i5:
print i, i2, i3, i4, i5, i6
teams(data)
Run Code Online (Sandbox Code Playgroud)
我的问题是我的循环太慢而且我无法使if语句工作所以我必须制作5个不同的ifs,我认为这是一个非常愚蠢的解决方案.
我的问题是:如何让我的循环更快/更智能,以及如何修复我的if陈述
我在/ usr/bin/python中有原始的Python 2.7.5,我通过在/ usr/local/bin/python3下载Python 3.5.1软件包安装了Python3,然后我安装了BeautifulSoup4,如下所示:
sudo easy_install BeautifulSoup4
Searching for BeautifulSoup4
Best match: beautifulsoup4 4.4.1
Processing beautifulsoup4-4.4.1-py2.7.egg
beautifulsoup4 4.4.1 is already the active version in easy-install.pth
Using /Library/Python/2.7/site-packages/beautifulsoup4-4.4.1-py2.7.egg
Processing dependencies for BeautifulSoup4
Finished processing dependencies for BeautifulSoup4
Run Code Online (Sandbox Code Playgroud)
这样我不能在python3中使用bs4,如何在python3上安装bs4?
我有 2 个数组,如下所示:
x = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November',
'December']
y = [5.3, 6.1, 25.5, 27.8, 31.2, 33.0, 33.0, 32.8, 28.4, 21.1, 17.5, 11.9]
Run Code Online (Sandbox Code Playgroud)
我需要将月份放在 x 轴上,将月份的最高温度放在 y 轴上。但是,当我使用下面的代码时:
import matplotlib.pyplot as plt
import numpy as np
x = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November',
'December']
y = [5.3, 6.1, 25.5, 27.8, 31.2, 33.0, 33.0, 32.8, 28.4, 21.1, 17.5, 11.9]
plt.bar(x, y, color='green',align='center')
plt.title('Max Temperature for Monthes')
plt.legend() …Run Code Online (Sandbox Code Playgroud) python ×6
python-2.7 ×2
sql ×2
axis ×1
bs4 ×1
css ×1
django ×1
html ×1
loops ×1
matplotlib ×1
mysql ×1
nested-loops ×1
numpy ×1
oracle ×1
performance ×1
postgresql ×1
python-3.4 ×1
python-3.x ×1
rdf ×1
sparql ×1
sqlalchemy ×1
virtualenv ×1