我使用HighCharts Javascript库的web应用程序,并希望有图表内的图像水印(比方说在左上角的小图像).不仅要在浏览器中显示此水印图像,还要有人将图表导出为JPG或PNG.
我曾经在Web应用程序中看到过这种情况,该应用程序也使用HighCharts但不记得它在哪里.
有什么建议?
最近我使用VSCode作为我的Python IDE,我安装了
DonJayamanne/pythonVSCode,它支持linting.然而,linter只在保存时起作用,但我想要的是实时linting.作者建议的解决方法是设置files.autoSave为on,以便只要文件自动保存,linter就会起作用.有关Github的相关讨论,供您参考.
由于我不想打开自动保存功能,有没有办法用VSCode进行Python的实时 linting?或者有任何建议的延期?
我想我对Python中"class"和"inheritance"的使用有一些误解.我将简化我的问题如下:
class A:
def __init__(self):
self.data = 100
class B(A):
def b(self):
print self.data
>>>B().b()
>>>100
Run Code Online (Sandbox Code Playgroud)
好的,到目前为止一切顺利.但是,如果我创建另一个类,则会出现问题,如下所示:
class C(A):
def c(self, num=self.data):
print self.data
>>>C().c()
NameError: name 'self' is not defined
Run Code Online (Sandbox Code Playgroud)
我想将'num'的默认值设置为self.data,即'100'.没有'class',它会更简单:
data = 100
def d(num = data):
print num
>>>d()
>>>100
Run Code Online (Sandbox Code Playgroud)
我已经搜索了一些文章,但仍然坚持这个问题...提前谢谢!
我正在做一些像下面这样的分词实验.
lst是一系列字符,output是所有可能的单词.
lst = ['a', 'b', 'c', 'd']
def foo(lst):
...
return output
output = [['a', 'b', 'c', 'd'],
['ab', 'c', 'd'],
['a', 'bc', 'd'],
['a', 'b', 'cd'],
['ab', 'cd'],
['abc', 'd'],
['a', 'bcd'],
['abcd']]
Run Code Online (Sandbox Code Playgroud)
我已经检查过combinations并permutations在itertools库中,
并尝试过组合学.
然而,似乎我在看错了,因为这不是纯粹的排列和组合......
似乎我可以通过使用大量循环来实现这一点,但效率可能很低.
编辑
单词顺序很重要,因此组合喜欢['ba', 'dc']或['cd', 'ab']无效.
订单应始终从左到右.
编辑
@Stuart的解决方案在Python 2.7.6中不起作用
编辑
@Stuart的解决方案在Python 2.7.6中有效,请参阅下面的注释.
我先发布我的代码,然后提问.
def menu(**arg):
if len(arg) == 0:
name = raw_input("Enter your name: ")
location = raw_input("Enter your name: ")
else:
for i,j in arg.items():
globals()[i] = j
print "Name: %s | Location: %s" % (name, location)
Run Code Online (Sandbox Code Playgroud)
这个函数的目标是打印出这样的东西:
姓名:某人| 位置:某个地方
如果我只是输入
菜单()
好的,没问题,但如果我输入
menu(name ='someone',location ='somewhere')
有些不对劲...
如果我像这样重写它:
def menu(**arg):
if len(arg) == 0:
pass
else:
for i,j in arg.items():
globals()[i] = j
print "Name: %s | Location: %s" % (name, location)
Run Code Online (Sandbox Code Playgroud)
我打字
menu(name ='someone',location ='somewhere')
它有效...但我不知道为什么
另外,为什么我不能用"重写版本"中的globals()替换vars()?
我的最后一个问题是......
我发现这段代码冗长冗余..
有没有什么方法可以让它更干净整洁? …
我真的很痛苦这个问题.
最初,在使用matplotlib绘制内容后,我可以轻松保存图像.
但是,安装scipy之后,我再也无法保存我的图像了.
(我使用pip安装了matplot和scipy.)
我试图查找一些信息,但我仍然无法解决问题.
我的操作系统是Mac OS X Lion(10.7)
我认为以下链接是一些相关问题
https://github.com/ipython/ipython/issues/2710
Matplotlib python savefig运行时错误python 3.2.3
matplotlib和libpng问题ipython notebook
libpng15静态链接问题
看来如果我可以重新链接库或设置DYLD_LIBRARY_PATH(实际上我不知道那是什么......)
或许我必须重新编译一些东西?
顺便说一下,我对基于linux的系统很新,所以如果有人能以一种相对简单的方式解释它,那将是非常好的.非常感谢你.
以下是一些错误消息:
libpng warning: Application was compiled with png.h from libpng-1.5.4
libpng warning: Application is running with png.c from libpng-1.4.10
libpng warning: Incompatible libpng version in application and library
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
/Library/Python/2.7/site-packages/matplotlib/backends/backend_macosx.pyc in save_figure(self, *args)
476 if filename is None: # Cancel
477 return
--> 478 self.canvas.print_figure(filename)
479
480 def prepare_configure_subplots(self):
/Library/Python/2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, …Run Code Online (Sandbox Code Playgroud) 以下是我的问题:
data = ['a1_1 00000001\n', 'a1_2 00000002\n', 'a1_3 00000003\n',
'b1_1 00000004\n', 'b1_2 00000005\n', 'b1_3 00000006']
candidate = ['a', 'b']
for i in candidate:
for j in data:
if i in j.split()[0]:
print i, j.split()[1]
a 00000001
a 00000002
a 00000003
b 00000004
b 00000005
b 00000006
Run Code Online (Sandbox Code Playgroud)
但我想要做的是如下结果:
a 00000001, 00000002, 00000003
b 00000004, 00000005, 00000006
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?提前致谢!
python ×5
class ×1
combinations ×1
editor ×1
highcharts ×1
image ×1
inheritance ×1
javascript ×1
libpng ×1
matplotlib ×1
permutation ×1
self ×1
variables ×1
watermark ×1