Questions tagged «python»

Python是一种多范式,动态类型的多用途编程语言。它旨在快速学习,理解和使用并强制使用干净统一的语法。请注意,Python 2自2020年1月1日起已不再受支持。不过,对于特定于版本的Python问题,请添加[python-2.7]或[python-3.x]标签。使用Python变体或库(例如Jython,PyPy,Pandas,Numpy)时,请将其包含在标签中。

2
Flask中的“端点”是什么?
该瓶文档显示: add_url_rule(*args, **kwargs) Connects a URL rule. Works exactly like the route() decorator. If a view_func is provided it will be registered with the endpoint. endpoint – the endpoint for the registered URL rule. Flask itself assumes the name of the view function as endpoint “端点”到底是什么意思?
124 python  flask 





6
Linux上的两个版本的python。如何使2.7成为默认值
我的linuxbox上有两个版本的python: $python Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> $ /usr/local/bin/python2.7 Python 2.7.3 (default, Oct 8 2013, 15:53:09) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2 Type "help", "copyright", "credits" or "license" …
124 python  linux  centos 

2
使用其构造函数初始化OrderedDict的正确方法,使其保留初始数据的顺序?
初始化有序词典(OD)以便保留初始数据顺序的正确方法是什么? from collections import OrderedDict # Obviously wrong because regular dict loses order d = OrderedDict({'b':2, 'a':1}) # An OD is represented by a list of tuples, so would this work? d = OrderedDict([('b',2), ('a', 1)]) # What about using a list comprehension, will 'd' preserve the order of 'l' …

10
如何在Python中使用WSDL(SOAP)Web服务?
我想在Python中使用基于WSDL SOAP的Web服务。我看过Dive Into Python代码,但是SOAPpy模块在Python 2.5下不起作用。 我已经尝试使用肥皂水(:类型未找到:“项目” suds.TypeNotFound),这部分工作,但打破了某些类型。 我也查看了Client,但这似乎不支持WSDL。 我看过ZSI,但它看起来非常复杂。有人有任何示例代码吗? WSDL是https://ws.pingdom.com/soap/PingdomAPI.wsdl,可与PHP 5 SOAP客户端配合使用。

7
为什么Python无法找到sys.path目录中的共享对象?
我正在尝试导入pycurl: $ python -c "import pycurl" Traceback (most recent call last): File "<string>", line 1, in <module> ImportError: libcurl.so.4: cannot open shared object file: No such file or directory 现在,libcurl.so.4在中/usr/local/lib。如您所见,这是在sys.path: $ python -c "import sys; print(sys.path)" ['', '/usr/local/lib/python2.5/site-packages/setuptools-0.6c9-py2.5.egg', '/usr/local/lib/python25.zip', '/usr/local/lib/python2.5', '/usr/local/lib/python2.5/plat-linux2', '/usr/local/lib/python2.5/lib-tk', '/usr/local/lib/python2.5/lib-dynload', '/usr/local/lib/python2.5/sitepackages', '/usr/local/lib', '/usr/local/lib/python2.5/site-packages'] 任何帮助将不胜感激。

3
Python字典到URL参数
我正在尝试将Python字典转换为用作URL参数的字符串。我敢肯定,有一种更好的,更Python化的方法可以做到这一点。它是什么? x = "" for key, val in {'a':'A', 'b':'B'}.items(): x += "%s=%s&" %(key,val) x = x[:-1]

14
scipy.misc模块没有属性读取?
我正在尝试读取图像。但是,它不接受该scipy.misc.imread零件。这可能是什么原因? >>> import scipy >>> scipy.misc <module 'scipy.misc' from 'C:\Python27\lib\site-packages\scipy\misc\__init__.pyc'> >>> scipy.misc.imread('test.tif') Traceback (most recent call last): File "<pyshell#11>", line 1, in <module> scipy.misc.imread('test.tif') AttributeError: 'module' object has no attribute 'imread'

10
BeautifulSoup抓取可见网页文本
基本上,我想使用BeautifulSoup来严格抓取网页上的可见文本。例如,此网页是我的测试用例。我主要想获取正文文本(文章),甚至在这里和那里甚至几个标签名称。我尝试了这个SO问题中的建议,该建议返回很多<script>我不想要的标签和html注释。我无法弄清楚该函数所需的参数findAll(),以便仅获取网页上的可见文本。 那么,我应该如何查找除脚本,注释,CSS等之外的所有可见文本?

5
Python-write()与writelines()和串联字符串
所以我正在学习Python。我正在上课,遇到一个问题,我不得不将很多压缩target.write()成一个write(),同时"\n"在每个用户输入变量(的对象write())之间都有一个。 我想出了: nl = "\n" lines = line1, nl, line2, nl, line3, nl textdoc.writelines(lines) 如果我尝试这样做: textdoc.write(lines) 我得到一个错误。但是如果我输入: textdoc.write(line1 + "\n" + line2 + ....) 然后工作正常。为什么我不能在其中使用字符串作为换行符,write()但可以在其中使用呢writelines()? Python 2.7当我搜索google时,发现的大部分资源都超出了我的想象力,我仍然是一个外行。

8
为什么在Python类中使用__init__?
我在理解类的初始化时遇到了麻烦。 它们的意义何在?我们如何知道其中包含什么?用类编写与创建函数相比是否需要不同的思维方式(我认为我可以只创建函数,然后将它们包装在类中,以便我可以重用它们。这行得通吗?) 这是一个例子: class crawler: # Initialize the crawler with the name of database def __init__(self,dbname): self.con=sqlite.connect(dbname) def __del__(self): self.con.close() def dbcommit(self): self.con.commit() 或另一个代码示例: class bicluster: def __init__(self,vec,left=None,right=None,distance=0.0,id=None): self.left=left self.right=right self.vec=vec self.id=id self.distance=distance __init__尝试阅读别人的代码时遇到了很多类,但是我不理解创建它们的逻辑。
124 python  class 

9
Python中的指针?
我知道Python没有指针,但是有办法提高产量 2,而不是 >>> a = 1 >>> b = a # modify this line somehow so that b "points to" a >>> a = 2 >>> b 1 ? 这是一个例子:我想要form.data['field']和form.field.value始终具有相同的值。并非完全必要,但我认为这会很好。 例如,在PHP中,我可以这样做: <?php class Form { public $data = []; public $fields; function __construct($fields) { $this->fields = $fields; foreach($this->fields as &$field) …
124 python  pointers 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.