这是一个示例数据集.
#x y r c
1 2 10 2
3 1 2 4
3 2 1 5
Run Code Online (Sandbox Code Playgroud)
我可以绘制圆圈的半径代表第3列或用代表第3列的颜色.但是,我不知道如何将它们都保留在情节中.
这是我用代表第3列的半径绘制的代码.
plot 'rslt.log' u 1:2:3 w points pt 7 ps variable
Run Code Online (Sandbox Code Playgroud) 我需要知道为什么这会失败:
class ConfigurationError(Exception):
def __init__(self, *args):
super(ConfigurationError, self).__init__(self, args)
self.args = list(args)
# Do some formatting on the message string stored in self.args[0]
self.args[0]=self.__prettyfi(self.args[0])
def __prettyfi(self, arg):
pass
# Actual function splits message at word
# boundaries at pos rfind(arg[1:78]) if len(arg) >78
# it does this by converting a whitespace char to a \n
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,我收到以下消息:
<snip>
ConfigurationError.py", line 7, in __init__
self.args[0]=self.__prettyfi(self.args[0])
TypeError: 'tuple' object does not support item assignment
我编辑了第一行.匹配此代码示例.
我不明白为什么self.args = list(args)没有正确地将元组解压缩到第5行的列表中.
(我有一种潜行的怀疑,我没记得超基本的东西...)
我有一些适合我的代码,但是当我把它交给一些同事时,它就破了.他们正在使用,tcsh而据我所知,我正在使用csh.
我试过了:
csh -v
csh --version
csh -V
csh --help
csh -h
Run Code Online (Sandbox Code Playgroud)
没有成功(他们都只是带我直接到翻译提示).我也为字符串"version"找到了man页面,但我也没有想出任何有用的东西.有没有办法确定csh我安装的版本?
- 编辑 -
在符号链接之后/bin/csh,它们似乎终止,/bin/bsd-csh这似乎意味着我正在使用一些BSD风味的csh shell,如果这有助于任何人.另外,我正在使用ubuntu linux.
我想使用python ConfigParser模块读取配置文件:
[asection]
option_a = first_value
option_a = second_value
Run Code Online (Sandbox Code Playgroud)
我希望能够获得为选项“ option_a”指定的值的列表。我尝试了以下显而易见的方法:
test = """[asection]
option_a = first_value
option_a = second_value
"""
import ConfigParser, StringIO
f = StringIO.StringIO(test)
parser = ConfigParser.ConfigParser()
parser.readfp(f)
print parser.items()
Run Code Online (Sandbox Code Playgroud)
哪个输出:
[('option_a', 'second_value')]
Run Code Online (Sandbox Code Playgroud)
当我希望:
[('option_a', 'first_value'), ('option_a', 'second_value')]
Run Code Online (Sandbox Code Playgroud)
或者,甚至更好:
[('option_a', ['first_value', 'second_value'])]
Run Code Online (Sandbox Code Playgroud)
有没有办法用ConfigParser做到这一点?另一个主意?
场景:
>>> a=' Hello world'
index = 3
Run Code Online (Sandbox Code Playgroud)
在这种情况下,“ H”索引为“ 3”。但是我需要一个更通用的方法,这样对于任何字符串变量'a'我都需要知道第一个字符的索引?
替代方案:
>>> a='\tHello world'
index = 1
Run Code Online (Sandbox Code Playgroud) 我正在使用谷歌的API客户端与Gmail API进行交互.假设我有一个草稿的不可变ID,我想发送相关的草稿.
我试过了:
service.users().drafts().send(
userId='me', id=draft_id).execute(http=http)
Run Code Online (Sandbox Code Playgroud)
这draft_id是我要发送的草稿的id,http是一个Http适用于其他请求的实例(因此它经过了适当的身份验证).
试着上面,我得到一个TypeError:
Traceback (most recent call last):
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "/Users/mgilson/git/spider-web/app/pattern/handlers/ajax/email.py", line 77, in post
'success': int(client.send_draft(draft_id))
File "/Users/mgilson/git/spider-web/app/pattern/services/email/gmail.py", line 601, in send_draft
userId='me', id=draft_id) \
File "/Users/mgilson/git/spider-web/app/third_party/googleapiclient/discovery.py", line 669, in method
raise TypeError('Got an unexpected keyword argument "%s"' % name)
TypeError: Got an unexpected keyword argument "id"
Run Code Online (Sandbox Code Playgroud)
该文档有一个Java示例,但没有python示例.
我试过的其他变化:
service.users().drafts().send(
userId='me', draftId=draft_id).execute(http=http)
service.users().drafts().send(
userId='me', draft_id=draft_id).execute(http=http)
service.users().drafts().send( …Run Code Online (Sandbox Code Playgroud) 重复列表最大元素长度的最有效方法是什么?
拿这个:
list = ['one', 'two', 'three']
max_length = 7
Run Code Online (Sandbox Code Playgroud)
并产生这个:
final_list = ['one', 'two', 'three', 'one', 'two', 'three', 'one']
Run Code Online (Sandbox Code Playgroud) Python 3.6
我正在尝试创建一个装饰器,它自动将参数的字符串指定为默认值.
如:
def example(one='one', two='two', three='three'):
pass
Run Code Online (Sandbox Code Playgroud)
相当于:
@DefaultArguments
def example(one, two, three):
pass
Run Code Online (Sandbox Code Playgroud)
这是我的尝试(不起作用..但..)DefaultArguments:
from inspect import Parameter, Signature, signature
class DefaultArguments(object):
@staticmethod
def default_signature(signature):
def default(param):
if param.kind in (Parameter.POSITIONAL_OR_KEYWORD, Parameter.POSITIONAL_ONLY):
return param.replace(default=param.name)
else:
return param
return Signature([default(param) for param in signature.parameters.values()])
def __init__(self, func):
self.func = func
self.sig = self.default_signature(signature(func))
def __call__(self, *args, **kwargs):
arguments = self.sig.bind(*args, **kwargs)
return self.func(arguments)
Run Code Online (Sandbox Code Playgroud)
static方法default_signature为函数创建了所需的签名,但是我很难将新签名分配给函数.我正在尝试使用Signature.bind我已经阅读了文档,但我错过了一些东西.
编辑
结合Ashwini Chaudhary的回答:
from inspect import …Run Code Online (Sandbox Code Playgroud) 我有一个与MPI并行化的应用程序,它分为许多不同的任务。每个处理器仅分配一个任务,而分配了相同任务的处理器组则分配有它自己的通信器。任务需要定期进行同步。当前,同步是通过MPI_COMM_WORLD完成的,但是它的缺点是无法使用集体操作,因为不能保证其他任务将到达该代码块。
作为更具体的示例:
task1: equation1_solver, N nodes, communicator: mpi_comm_solver1
task2: equation2_solver, M nodes, communicator: mpi_comm_solver2
task3: file IO , 1 node , communicator: mpi_comm_io
Run Code Online (Sandbox Code Playgroud)
我想在task1上使用MPI_SUM一个数组,并将结果显示在task3上。有一种有效的方法可以做到这一点吗?(如果这是一个愚蠢的问题,我深表歉意,我在创建和使用自定义MPI通信器方面没有太多经验)
我有一个列表的多个条件的问题:
listionary = [{u'city': u'paris', u'id': u'1', u'name': u'paul'},
{u'city': u'madrid', u'id': u'2', u'name': u'paul'},
{u'city': u'berlin', u'id': u'3', u'name': u'tom'},
{u'city': u'madrid', u'id': u'4', u'name': u'tom'}]
Run Code Online (Sandbox Code Playgroud)
我尝试同时删除同时满足这两个条件的项目.
[elem for elem in listionary if (elem.get('name')!='paul' and elem.get('city')!='madrid')]
Run Code Online (Sandbox Code Playgroud)
在这种情况下,如果满足至少一个条件,则删除元素,我尝试以多种方式进行,任何想法?
预期产量:
[{u'city': u'paris', u'id': u'1', u'name': u'paul'}
{u'city': u'berlin', u'id': u'3', u'name': u'tom'}
{u'city': u'madrid', u'id': u'4', u'name': u'tom'}]
Run Code Online (Sandbox Code Playgroud)
我想删除符合这两个条件的元素.