我有一个元组列表,其中包含11个点的值和坐标
dotted_array = [(0, 0, '.'), (2, 0, '.'), (3, 0, '.'), (0, 1, '.'), (2, 1, '.'), (0, 2, '.'), (2, 2, '.'), (3, 2, '.'), (0, 3, '.'), (2, 3, '.'), (3, 3, '.')]
Run Code Online (Sandbox Code Playgroud)
我列出了5个清单:
list_of_signs = [['+', '+', '-', '+', '+', '+', '+', '-', '+', '+', '-'], ['+', '+', '-', '+', '-', '+', '+', '-', '+', '+', '-'], ['+', '+', '-', '+', '+', '+', '+', '-', '+', '+', '-'], ['+', '-', '-', '+', '+', '+', '+', '-', …Run Code Online (Sandbox Code Playgroud) 我一直在尝试向API发出请求,我必须通过以下正文:
{
"description":"Tenaris",
"ticker":"TS.BA",
"industry":"Metalúrgica",
"currency":"ARS"
}
Run Code Online (Sandbox Code Playgroud)
尽管代码似乎是正确的,并且它以"处理完成退出代码0"结束,但它运行不正常.我不知道我错过了什么,但这是我的代码:
http = urllib3.PoolManager()
http.urlopen('POST', 'http://localhost:8080/assets', headers={'Content-Type':'application/json'},
data={
"description":"Tenaris",
"ticker":"TS.BA",
"industry":"Metalúrgica",
"currency":"ARS"
})
Run Code Online (Sandbox Code Playgroud)
顺便说一句,这是使用Python的第一天,如果我不够具体,请原谅我.
我有一个如下所示的 CSV 文件:
patient_id, age_in_years, CENSUS_REGION, URBAN_RURAL_STATUS
11511, 7 Northeast, Urban,
9882613, 73, South, Urban,
32190339, 49, West, Urban,
32190339, 49, West, Urban,
32190339, 49, West, Urban,
32190339, 49, West, Urban,
.....
Run Code Online (Sandbox Code Playgroud)
现在我的代码是这样的:
df = pd.read_csv(filename, index_col = 0)
Run Code Online (Sandbox Code Playgroud)
这给出了以下输出:
patient_id age_in_years CENSUS_REGION URBAN_RURAL_STATUS YEAR MONTH
11511 7 Northeast Urban 2011 6
9882613 73 South Urban 2011 7
32190339 49 West Urban 2011 8
32190339 49 West Urban 2011 8
32190339 49 West Urban 2011 8
32190339 49 West Urban …Run Code Online (Sandbox Code Playgroud) 我正在使用ceilometer python API并将数据发布到pubnub.不确定这个错误是什么意思.
这是导致我认为的问题的代码的一部分,
def init_Data(data, channel):
cpu_sample = cclient.samples.list(meter_name ='cpu_util')
for each in cpu_sample:
timetamp = each.timestamp
volume = each.counter_volume
volume_int = int(volume)
data_volume ={'value': volume_int}
data=json.dumps(data_volume)
print (data)
pubnub.publish(channel='orbit_channel', callback= init_Datar)
Run Code Online (Sandbox Code Playgroud) 我想知道如何从文本文件中仅提取数字数据并读取它的过程。我有一个名为 temperature.txt 的文本文件,它不断在模拟我的代码时附加数据。我想知道 javascript 中的代码以将数据实时流式传输到 plotly。
'use strict';
var plotly = require('plotly')('agni_2006','jtwubwfjtp');
var initdata = [{x:[], y:[], stream:{token:'g1z4cinzke', maxpoints:200}}];
var initlayout = {fileopt : 'overwrite', filename : 'try'};
plotly.plot(initdata, initlayout, function (err, msg) {
if (err) return console.log(err);
console.log(msg);
var stream1 = plotly.stream('g1z4cinzke', function (err, res) {
if (err) return console.log(err);
console.log(res);
clearInterval(loop); // once stream is closed, stop writing
});
var i = 0;
var loop = setInterval(function () {
var data = { x : i, y : …Run Code Online (Sandbox Code Playgroud) 我正在尝试格式化一些数据以执行分析.我正试图'*'从一开始的所有字符串中删除 .这是一个数据片段:
[['Version', 'age', 'language', 'Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Q9', 'Q10', 'Q11', 'Q12', 'Q13', 'Q14', 'Q15', 'Q16', 'Q17', 'Q18', 'Q19', 'Q20', 'Q21', 'Q22', 'Q23', 'Q24', 'Q25', 'Q26', 'Q27', 'Q28', 'Q29', 'Q30', 'Q31', 'Q32', 'Q33', 'Q34', 'Q35', 'Q36', 'Q37', 'Q38', 'Q39', 'Q40', 'Q41', 'Q42', 'Q43', 'Q44', 'Q45'], ['1', '18 to 40', 'English', '*distort', '*transfer', '*retain', 'constrict', '*secure', '*excite', '*cancel', '*hinder', '*overstate', 'channel', '*diminish', '*abolish', '*comprehend', '*tolerate', '*conduct', '*destroy', '*foster', 'direct', '*challenge', 'forego', '*cause', '*reduce', 'interrupt', …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用python请求登录论坛.这是我试图登录的论坛:http://fans.heat.nba.com/community/
这是我的代码:
import requests
import sys
URL = "http://fans.heat.nba.com/community/index.php?app=core&module=global§ion=login"
def main():
session = requests.Session()
# This is the form data that the page sends when logging in
login_data = {
'ips_username': 'username',
'ips_password': 'password',
'signin_options': 'submit',
'redirect':'index.php?'
}
r = session.post(URL, data=login_data)
# Try accessing a page that requires you to be logged in
q = session.get('http://fans.heat.nba.com/community/index.php?app=members&module=messaging§ion=view&do=showConversation&topicID=4314&st=20#msg26627')
print(session.cookies)
print(r.status_code)
print(q.status_code)
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
URL是论坛上的登录页面.使用'q'变量,会话尝试访问论坛(私人信使)上的某个网页,只有在您登录时才能访问该网页.但是,该请求的状态代码返回'403',这意味着我无法成功登录.
为什么我无法登录?在'login_data'中,'ips_username'和'ips_password'是HTML表单.但是,我相信我有实际的登录命令('signin_options','redirect')错误.
有人可以指导我正确的登录命令吗?
我正在写一个基于文本的游戏,我想将每个房间连接到其他四个房间 - 北,南,东和西.我现在正从北方开始.用户应该能够键入'walk north'并且应该调用north room.
我使用了三个文件 - 一个用于编写主要故事,一个用于调用故事中的适当房间,另一个用于导航以避免相互导入.
rooms.py:
import actions
class FirstRoom(object):
room_name = 'FIRST ROOM'
north = 'north_room'
def __init__(self):
pass
def start(self):
print self.room_name
while True:
next = raw_input('> ')
actions.walk(next, self.north)
actions.command(next)
class North(object):
room_name = "NORTH ROOM"
def __init__(self):
pass
def start(self):
print self.room_name
Run Code Online (Sandbox Code Playgroud)
actions.py:
import navigation
def walk(next, go_north):
"""Tests for 'walk' command and calls the appropriate room"""
if next == 'walk north':
navigation.rooms(go_north)
else:
pass
Run Code Online (Sandbox Code Playgroud)
navigation.py:
import rooms
first_room = rooms.FirstRoom()
north_room = …Run Code Online (Sandbox Code Playgroud) 我正在寻找以下最短的方式(一线解决方案)
a = ["a", "b", "c"]
b = ["w", "e", "r"]
Run Code Online (Sandbox Code Playgroud)
我想要以下输出:
q = ["a w", "b e", "c r"]
Run Code Online (Sandbox Code Playgroud)
当然,这可以通过应用for循环来实现.但我想知道是否有一个聪明的解决方案呢?
我想创建一个在飞行中返回数组的生成器.例如:
import numpy as np
def my_gen():
c = np.ones(5)
j = 0
t = 10
while j < t:
c[0] = j
yield c
j += 1
Run Code Online (Sandbox Code Playgroud)
使用简单的for循环:
for g in my_gen():
print (g)
Run Code Online (Sandbox Code Playgroud)
我得到了我想要的东西.但是list(my_gen()),我得到了一个包含始终相同的列表.
我挖得更深一些,我发现当我yield c.tolist()而不是yield c一切都好的时候......
我只是无法解释自己为何会出现这种奇怪的行为......
python ×9
list ×3
ceilometer ×1
class ×1
csv ×1
curl ×1
function ×1
generator ×1
javascript ×1
json ×1
namespaces ×1
node.js ×1
numpy ×1
oop ×1
pandas ×1
plotly ×1
python-3.x ×1
replace ×1
string ×1
urllib3 ×1