我基本上有一个文件夹中所有文件的列表,在简化版本中看起来像:
file_list = [ 'drug.resp1.17A.tag', 'drug.resp1.96A.tag', 'drug.resp1.56B.tag', 'drug.resp2.17A.tag', 'drug.resp2.56B.tag', 'drug.resp2.96A.tag']
Run Code Online (Sandbox Code Playgroud)
另一个清单:
drug_list = [ '17A', '96A', '56B']
Run Code Online (Sandbox Code Playgroud)
我想将这两个列表组合成一个字典,这样:
dictionary = {
'17A' : ['drug.resp1.17A.tag' , 'drug.resp2.17A.tag' ],
'96A' : ['drug.resp1.96A.tag' , 'drug.resp2.96A.tag' ],
'56B' : ['drug.resp1.56B.tag' , 'drug.resp2.56B.tag' ]}
Run Code Online (Sandbox Code Playgroud)
我想这样做却被卡住了!
dict_drugs = {}
for file in file_list:
list_filename = file.split('.')
for elem in drug_list:
if elem in list_filename:
Run Code Online (Sandbox Code Playgroud)
在此之后我可以做什么来将元素加入字典中,或者我完全错误地做了这个?
我的问题是,当我把任何谷歌图表的js代码放在外部javascript文件中时.它开始加载页面并且不显示任何东西.如果内联javascripts其工作正常.
以下是我的HTML代码"google barchart.html"
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="test.js"></script>
<script type="text/javascript"></script>
</head>
<body>
<input type="button" id="btn" value="Show Graph" />
<div id="chart_div" style="width: 441px; height: 300px;"></div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的js文件"test.js"
$(document).ready(function() { $('#btn').click(function() { //alert("hi");
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
['', 'Your Restaurant', 'Other Restaurants'],
['Question1', 5, 4],
['Question2', 4, 5],
['Question3', 3, 2],
['Question4', 5, 1]
]);
var options = {
//title: 'Company Performance',
hAxis: …Run Code Online (Sandbox Code Playgroud) 此代码设置为读取两列数据,然后将第一列打印到第一个numpy数组中,然后将第二列打印到第二个numpy数组中.
def read2coldata(filename):
import numpy
b = []
f = open(filename,"r")
lines = f.readlines()
f.close()
for line in lines:
a = line.split()
for i in a:
b.append(i)
return (numpy.array(b[::2]),numpy.array(b[1::2]))
Run Code Online (Sandbox Code Playgroud)
但是这给出了:
(array(['1.5', '8', '16', '17'], dtype='|S3'), array(['4', '5', '6', '6.2'], dtype='|S3'))
Run Code Online (Sandbox Code Playgroud)
如何摆脱dtype="|S3"零件只是离开:
(array(["1.5","8","16","17"], array(["4","5","6","6.2"])
Run Code Online (Sandbox Code Playgroud) 我有一个静态(HTML/CSS)网站作为Google App Engine上的应用程序托管 - Python.除了我想添加联系表单外,一切正常.我找到了一个很好的模板,我希望使用它,但发现它需要PHP才能工作.有没有办法让它工作或找到一个与GAE一起使用的联系表格.
我知道将GAE用于静态网站并不是它的主要用途,但它是免费的,并且非常适合我想要它做的事情(托管单页简历).
我有两张桌子,Staff和Wages
Staff 包含
id, name, jobID, wage
1 Name1 2
2 Name2 4
3 Name3 1
4 Name4 2
Run Code Online (Sandbox Code Playgroud)
Wages 包含
JobID, Wage
1 1500
2 800
3 1600
4 2000
Run Code Online (Sandbox Code Playgroud)
(实际上有很多列我刚刚进入前4名)
我错过了Staff桌子里的工资,工作人员表中我需要的工资是表中的费率Wages.
所以我需要一个查询,使Staff表格看起来像:
id, name, jobID, wage
1 Name1 2 800
2 Name2 4 2000
3 Name3 1 1500
4 Name4 2 800
Run Code Online (Sandbox Code Playgroud)
我尝试的一个示例查询是:
UPDATE `Staff`
SET wage = (SELECT wage FROM `Wages`)
WHERE jobID = (Select jobId FROM `Wages`) …Run Code Online (Sandbox Code Playgroud) 在Google应用引擎上,我想在模板中使用两个变量for循环:我需要输入10个项目.如果数据存储区中已有某些项目,则显示它们,否则,将该字段留空.我该怎么做?谢谢.
顺便说一句,我注意到Django中有"multifor",但我不知道如何在GAE上安装它.
main.py:
def mainPage(webapp2.RequestHandler):
query = db.Query(Item)
items = query.fetch(limit=10)
template_values = {'range': range(10), 'items': items}
common.render(handler, 'main.html', template_values)
Run Code Online (Sandbox Code Playgroud)
main.html中:
<form action=... method="post">
{% for i in range; for item in items %}
<input type="text" name="name" value="item.name">
{% endfor %}
<input type="submit">
</form>
Run Code Online (Sandbox Code Playgroud) 在Google App Engine中,我曾经nowTime = datetime.datetime.now()获得系统时间.但是,我发现它与计算机系统时间不同.例如,nowTime是2012-12-20 14:44:30.910192,但我的计算机系统时间是2012-12-20 22:44.有八个小时的差异.是因为时区吗?Google App Engine SDK从哪里获得时间?谢谢.
我试过浏览这里发布的类似问题,但似乎都没有
的manifest.json
{
"manifest_version": 2,
"name" : "A simple Found Text Demo",
"description" : "Bla",
"version" : "1.0",
"background" : {
"pages" : "background.html"
},
"page_action" : {
"default_icon" : "icon.png"
},
"content_scripts" : [{
"matches" : ["*://*/*"],
"js" : ["contentscript.js"]
}]
}
Run Code Online (Sandbox Code Playgroud)
Background.html
<html>
<script>
chrome.extension.onMessage.addListener(
function(request, sender, sendResponse){
alert(request);
//chrome.pageAction.show(sender.tab.id);
sendResponse('Found!');
}
)
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
Contentscript.js
chrome.extension.sendMessage({"name" : "hola"}, function(res){
console.log(res); })
Run Code Online (Sandbox Code Playgroud)
但是我反复得到同样的错误:
Port error: Could not establish connection. Receiving end does not exist.
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我试图以下面的方式分割字符串.这是一个示例字符串:
"Hello this is a string.?-2.34 This is an example1 string."
Run Code Online (Sandbox Code Playgroud)
请注意,""是U + F8FF unicode字符,字符串的类型是Unicode.
我想打破字符串:
"Hello this is a string.","-2.34"," This is an example1 string."
Run Code Online (Sandbox Code Playgroud)
我写了一个正则表达式来分割字符串,但使用这个我不能得到我想要的数字部分.(第一个字符串中的-2.34)
我的代码:
import re
import os
from django.utils.encoding import smart_str, smart_unicode
text = open(r"C:\data.txt").read()
text = text.decode('utf-8')
print(smart_str(text))
pat = re.compile(u"\uf8ff-*\d+\.*\d+")
newpart = pat.split(text)
firstpart = newpart[::1]
print ("first part of the string ----")
for f in firstpart:
f = smart_str(f)
print ("-----")
print f
Run Code Online (Sandbox Code Playgroud)
我的第一篇文章......
我正在使用python脚本从Mac OS X Lion上的剪贴板中获取文本.
我用以下函数设置了剪贴板:
def setClip (text):
pb = NSPasteboard.generalPasteboard()
pb.clearContents()
a = NSArray.arrayWithObject_(text)
return pb.writeObjects_(a)
Run Code Online (Sandbox Code Playgroud)
where text="some text"
我用以下内容检索剪贴板:
def getClip():
pb = NSPasteboard.generalPasteboard()
pbstring = pb.stringForType_(NSString *)dataType
return pbstring
Run Code Online (Sandbox Code Playgroud)
输出前面带有"u",文本用引号括起,如下所示:
In [224]: setClip('some text')
Out[224]: True
In [225]: getClip()
Out[225]: "u'some text'"
Run Code Online (Sandbox Code Playgroud)
如何检索文本,因为它应该输入剪贴板?
我对NSPasteboard一无所知.我在stackoverflow上找到了这些代码片段.
提前致谢.
附录:我的实际代码
from AppKit import *
def setClip (text):
pb = NSPasteboard.generalPasteboard()
pb.clearContents()
a = NSArray.arrayWithObject_(text)
return pb.writeObjects_(a)
def getClip():
pb = NSPasteboard.generalPasteboard()
pbstring = pb.stringForType_(NSString *)dataType
return pbstring
Run Code Online (Sandbox Code Playgroud)
这就是我在ipython中运行它时会发生的事情:
输出前面带有"u",文本用引号括起,如下所示: …
如果我的字符串"deed"在前9个字符中有"数字或空白",我试图测试True.
deed = "4472 0438 (N/A Online)$0"
Run Code Online (Sandbox Code Playgroud)
我已经尝试了以下几种变体,但总是得到一个True,当我在字符串上尝试它时不应该返回True.所以我做错了.
re.search("([\. 0-9]{0,6})",deed)
Run Code Online (Sandbox Code Playgroud)
任何建议将不胜感激!对不起,全新的Regex ..但是学习.
我已经安装了Python 2.7和mysql-python 2.7.我想执行此代码以在Python中测试MySQL:
import MySQLdb
db = MySQLdb.connnect(host = "localhost",
user="Bishnu Bhattarai",
passwd = "password",
db = "student")
cursor =db.cursor()
cursor.execute("select * from basic_info" )
numrows = int(cursor.rowcount)
for x in range(0,numrows):
row = cursor.fetchall()
print row[0],"-->",row[1]
Run Code Online (Sandbox Code Playgroud)
但它显示错误:
Traceback (most recent call last):
File "C:\Users\Bishnu\Desktop\database", line 2, in <module>
db = MySQLdb.connnect(host = "localhost",
AttributeError: 'module' object has no attribute 'connnect'
Run Code Online (Sandbox Code Playgroud)
问题是什么?
我有一个字符串列表,每个字符串作为一个字符.他们按照这个词的顺序排列.如何将每个字符放在一个字符串中.例:
list_characters = ['H', 'e', 'l', 'l', 'o']
Run Code Online (Sandbox Code Playgroud)
成为:
'Hello'
Run Code Online (Sandbox Code Playgroud)
请帮助,谢谢
python ×9
arrays ×1
charts ×1
contact-form ×1
datetime ×1
dictionary ×1
external ×1
javascript ×1
list ×1
mysql-python ×1
nspasteboard ×1
numpy ×1
regex ×1
split ×1
sql ×1
templates ×1
unicode ×1