我正在尝试安装最新版本的六个python包,但我有以下问题.在mac OSX 10.10.2中无法摆脱六个1.4.1
sudo pip install six --upgrade
Requirement already up-to-date: six in /Library/Python/2.7/site-packages
Cleaning up...
pip search six
six - Python 2 and 3 compatibility utilities
INSTALLED: 1.9.0 (latest)
python -c "import six; print six.version"
1.4.1
which -a python
/usr/bin/python
which -a pip
/usr/local/bin/pip
Run Code Online (Sandbox Code Playgroud)
这有什么不对?不能升级六个!
我有一个弹性搜索文档,格式如下.我需要部分更新"x"字段并在其中添加python dict.
{
"_index": "gdata34",
"_type": "gdat",
"_id": "328091-72341-118",
"_version": 1,
"_score": 1,
"_source": {
"d": {
"Thursday": {
"s": ""
},
"Email": {
"s": ""
},
"Country": {
"s": "US"
},
},
"x": {
"Geo": {
"s": "45.335428,-118.057133",
"g": [
-118.057133
,
45.335428
]
}
},
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码来更新:
from elasticsearch import Elasticsearch, exceptions
import pprint
elasticsearch = Elasticsearch()
doc = elasticsearch.get(index='gdata34', doc_type='gdat', id='328091-72341-7')
elasticsearch.update(index='gdata34', doc_type='gdat', id='328091-72341-7',
body={"script":"ctx._source.x += y",
"params":{"y":"z"}
}
)
elasticsearch.indices.refresh(index='gdata34')
new_doc = elasticsearch.get(index='gdata34', doc_type='gdat', id='328091-72341-7') …
Run Code Online (Sandbox Code Playgroud) 我需要提取远程mp3文件的ID3标签和元数据.
我写了几行可以得到本地文件的ID3标签:
from mutagen.mp3 import MP3
import urllib2
audio = MP3("Whistle.mp3")
songtitle = audio["TIT2"]
artist = audio["TPE1"]
print "Title: " + str(songtitle)
print "Artist: "+str(artist)
Run Code Online (Sandbox Code Playgroud)
我需要为mp3文件的url链接实现这一点.我试图使用urllib2部分下载文件.
import urllib2
from mutagen.mp3 import MP3
req = urllib2.Request('http://www.1songday.com/wp-content/uploads/2013/08/Lorde-Royals.mp3')
req.headers['Range'] = 'bytes=%s-%s' % (0, 100)
response = urllib2.urlopen(req)
headers = response.info()
print headers.type
print headers.maintype
data = response.read()
print len(data)
Run Code Online (Sandbox Code Playgroud)
如何在不完全下载文件的情况下提取MP3网址的ID3标签?
我修改了我的仪表板并尝试将其保存为主页,我收到以下消息
主页设置此页面已设置为默认的Kibana仪表板
我仍然无法将修改后的仪表板作为默认仪表板加载,请告诉我如何操作.
我正在尝试在 elasticsearch 中获取索引(不是商店)的实际大小。我使用了索引 API 来获取统计信息。
GET doc/_stats
Run Code Online (Sandbox Code Playgroud)
“索引”-“index_total”是实际索引大小吗?
"total": {
"docs": {
"count": 1000000,
"deleted": 0
},
"store": {
"size_in_bytes": 118078896
},
"indexing": {
"index_total": 1000000,
"index_time_in_millis": 30985,
"index_current": 0,
"index_failed": 0,
"delete_total": 0,
"delete_time_in_millis": 0,
"delete_current": 0,
"noop_update_total": 0,
"is_throttled": false,
"throttle_time_in_millis": 0
},
Run Code Online (Sandbox Code Playgroud) 我试图将从richeditDocument生成的内存流转换为字节数组.代码如下:
Public Sub saveAsTemplate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ms As MemoryStream = New MemoryStream()
richEditControl1.SaveDocument(ms, DocumentFormat.Rtf)
GetStreamAsByteArray(ms)
MessageBox.Show("save")
End Sub
Private Function GetStreamAsByteArray(ByVal stream As MemoryStream) As Byte()
Dim streamLength As Integer = Convert.ToInt32(stream.Length)
Dim fileData As Byte() = New Byte(streamLength) {}
' Read the file into a byte array
stream.Read(fileData, 0, streamLength)
stream.Flush()
stream.Close()
Return fileData
End Function
Run Code Online (Sandbox Code Playgroud)
生成流时我可以获得流长度,但最终的咬合数组只包含0,使其无效.我怎样才能获得正确的字节数组?
我有一个带有英文文本和标点符号的阿拉伯字符串.我需要过滤阿拉伯语文本,我尝试使用sting删除标点符号和英语单词.但是,我丢失了阿拉伯语单词之间的间距.我哪里错了?
import string
exclude = set(string.punctuation)
main_text = "????? ????????: ?? ????? ????? ??????? ????? ?? ??????? ??????? ?? ????? http://alriyadh.com/1031499"
main_text = ''.join(ch for ch in main_text if ch not in exclude)
[output after this step="????? ???????? ?? ????? ????? ??????? ????? ?? ??????? ??????? ?? ????? httpalriyadhcom1031499]"
n = filter(lambda x: x not in string.printable, n)
print n
????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
我能够删除标点符号和英文文本,但我丢失了单词之间的空格.我怎样才能保留每一个字?
我正在使用python Beautiful汤来获取以下内容:
<div class="path">
<a href="#"> abc</a>
<a href="#"> def</a>
<a href="#"> ghi</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
html_doc="""<div class="path">
<a href="#"> abc</a>
<a href="#"> def</a>
<a href="#"> ghi</a>
</div>"""
from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc)
path = soup.find('div',attrs={'class':'path'})
breadcrum = path.findAll(text=True)
print breadcrum
Run Code Online (Sandbox Code Playgroud)
输出如下,
[u'\n', u'abc', u'\n', u'def', u'\n', u'ghi',u'\n']
Run Code Online (Sandbox Code Playgroud)
如何只以这种形式获取结果:abc,def,ghi
作为单个字符串?
我也想知道这样获得的输出。
我需要根据从侧边栏中选择的输入更改mydb(字符串)值.
library(shiny)
shinyUI(fluidPage(
titlePanel("Shiny App"),
sidebarLayout(
sidebarPanel( selectInput("site",
label = "Choose a site for Analysis",
choices = c("abc", "def",
"ghi", "jkl"),
selected = "abc")
),
mainPanel(
textOutput("text"),
)
))
Run Code Online (Sandbox Code Playgroud)
library(shiny)
library(ggplot2)
library(RMySQL)
shinyServer(function(input, output) {
if(input$site=="abc"){
mydb<-"testdb_abc"}
else if(input$site=="def"){
mydb<-"testdb_def"}
con <- dbConnect(MySQL(),dbname=mydb, user="root", host="127.0.0.1", password="root")
query <- function(...) dbGetQuery(con, ...)
output$text <- renderText({
paste("You have selected:",input$site)
})
})
Run Code Online (Sandbox Code Playgroud)
在上面的server.R中,我需要根据选定的输入为mydb分配字符串值.我收到此错误:
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context. (You tried to do something that …
Run Code Online (Sandbox Code Playgroud) 我想用ggplot可视化网球数据.到目前为止,我能够根据赢家/输家数据可视化数据.
2015 Flavia Pennetta 81
2014 Serena Williams 65
2013 Serena Williams 109
2012 Serena Williams 94
2011 Samantha Stosur 61
2010 Kim Clijsters 58
2009 Kim Clijsters 82
2008 Serena Williams 89
2007 Justine Henin 70
2006 Maria Sharapova 66
2015 Roberta Vinci 47
2014 Caroline Wozniacki 49
2013 Victoria Azarenka 91
2012 Victoria Azarenka 87
2011 Serena Williams 41
2010 Vera Zvonareva 31
2009 Caroline Wozniacki 66
2008 Jelena Jankovic 79
2007 Svetlana Kuznetsova 54
2006 Justine Henin …
Run Code Online (Sandbox Code Playgroud)