Tag: python

Python中的二进制数字

如何在Python中添加,减去和比较二进制数字而不转换为十进制?

Python守护进程和systemd服务

我有简单的Python脚本作为守护进程。 我正在尝试创buildsystemd脚本,以便能够在启动过程中启动此脚本。 当前systemd脚本: [Unit] Description=Text After=syslog.target [Service] Type=forking User=node Group=node WorkingDirectory=/home/node/Node/ PIDFile=/var/run/zebra.pid ExecStart=/home/node/Node/node.py [Install] WantedBy=multi-user.target node.py: if __name__ == '__main__': with daemon.DaemonContext(): check = Node() check.run() run包含while True循环。 我尝试通过systemctl start zebra-node.service运行此服务。 不幸的是,服务没有完成说明序列 – 我不得不按Ctrl + C。 脚本正在运行,但状态正在激活,过了一段时间,它将变为停用状态。 现在我正在使用python守护进程(但在我尝试之前没有它,症状是相似的)。 我应该实施一些额外的function,我的脚本或systemd文件不正确?

Python浮动到int转换

基本上,我将一个浮点数转换为一个整数,但我并不总是有预期的价值。 这里是我正在执行的代码: x = 2.51 print("——— 251.0") y = 251.0 print(y) print(int(y)) print("——— 2.51 * 100") y = x * 100 print(y) print(int(y)) print("——— 2.51 * 1000 / 10") y = x * 1000 / 10 print(y) print(int(y)) print("——— 2.51 * 100 * 10 / 10") y = x * 100 * 10 / 10 […]

Matplotlib传奇不工作

自升级matplotlib以来,每当尝试创build图例时都会收到以下错误消息: /usr/lib/pymodules/python2.7/matplotlib/legend.py:610: UserWarning: Legend does not support [<matplotlib.lines.Line2D object at 0x3a30810>] Use proxy artist instead. http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist warnings.warn("Legend does not support %s\nUse proxy artist instead.\n\nhttp://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist\n" % (str(orig_handle),)) /usr/lib/pymodules/python2.7/matplotlib/legend.py:610: UserWarning: Legend does not support [<matplotlib.lines.Line2D object at 0x3a30990>] Use proxy artist instead. http://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist warnings.warn("Legend does not support %s\nUse proxy artist instead.\n\nhttp://matplotlib.sourceforge.net/users/legend_guide.html#using-proxy-artist\n" % (str(orig_handle),)) 这甚至发生这样一个简单的脚本: import matplotlib.pyplot as […]

如何在Python中获取__main__模块的文件名?

假设我有两个模块: a.py: import b print __name__, __file__ b.py: print __name__, __file__ 我运行“a.py”文件。 这打印: b C:\path\to\code\b.py __main__ C:\path\to\code\a.py 问题 :如何从“b.py”库中获取__main__模块(本例中为“a.py”)的path?

parsingHTTP用户代理string

在Python中parsingUser-Agentstring以便可靠检测的最佳方法是什么? 浏览器 浏览器版本 OS 或者可能是任何帮助程序库

python:只得到1小数点

如何将45.34531转换为45.3 ?

检查variables是否是dataframe

当我的函数f被调用一个variables我想检查var是一个pandas数据框: def f(var): if var == pd.DataFrame(): print "do stuff" 我想解决scheme可能很简单,但即使 def f(var): if var.values != None: print "do stuff" 我不能像预期那样工作。

使用PIL在图像上添加文本

我有一个加载图像的应用程序,当用户点击它时,这个图像的文本区域(使用jquery ),用户可以在图像上写一些文本。 应该在Image上添加哪个 在做了一些研究后,我发现PIL (Python Imaging Library)可以帮助我做到这一点。 所以我试了几个例子来看看它是如何工作的,我设法在图像上写文本。 但是我认为当我使用Python Shell和Web环境进行尝试时会有一些差异。 我的意思是textarea上的文字在px中非常大。 在使用PIL作为textarea上的文本时,如何获得相同的文本大小? 文本是Multiline。 我怎样才能使它在图像多行,也使用PIL ? 有比使用PIL更好的方法吗? 我不完全确定,如果这是最好的实施。 HTML: <img src="images/test.jpg"/> 正在编辑的图像 var count = 0; $('textarea').autogrow(); $('img').click(function(){ count = count + 1; if (count > 1){ $(this).after('<textarea />'); $('textarea').focus(); } }); jquery添加textarea。 此外文本区域的位置:绝对和固定的大小。 我应该把它放在一个窗体,所以我可以得到textarea图像的坐标? 我想在用户点击时在图片上写文字并保存在图片上。

我如何在Mac上安装Beautiful Soup模块?

我没有find解决scheme阅读这个: http : //docs.python.org/install/index.html