Get the first link in a Wikipedia article not inside parentheses

So I'm interested in this theory that if you go to a random Wikipedia article, click the first link not inside parentheses repeatedly, in 95% of the cases you will end up on the article about Philosophy. I wanted to write a script in Python that does the link fetching for me and in the end, print a nice list of which articles were visited ( linkA -> linkB -> linkC ) etc. I managed t

获取不在括号内的维基百科文章中的第一个链接

所以我对这个理论很感兴趣,如果你去看一篇随机的维基百科文章,那么95%的案例最终会在关于哲学的文章中重复点击第一个不在括号内的链接。 我想用Python编写一个脚本,为我提供链接,并最终打印出访问过哪些文章的好列表( linkA -> linkB -> linkC )等。 我设法获取了网页的HTML DOM,并设法去掉了一些不必要的链接和导致消歧页面的顶部描述栏。 到目前为止,我的结论是: DOM开始于您在某些页面右侧看到的表格

Draw a Line in Python Mayavi

How to draw a line in 3D space in Python Mayavi? Is there a function from MLAB module that allows me to specify the start and end point of the line which will be drawn? Check the documentation for mayavi; 3d plotting is in the tutorials and documented here. It's part of mlab , mayavi.mlab.plot3d(*args, **kwargs) . The syntax is plot3d(x, y, z, ...) One important feature you can use w

在Python Mayavi中绘制一条线

如何在Python Mayavi中绘制三维空间中的线条? MLAB模块中是否有函数可以指定要绘制的线的起点和终点? 检查mayavi的文档; 3D绘图是在教程中,并在这里记录。 它是mlab的一部分, mayavi.mlab.plot3d(*args, **kwargs) 。 语法是 plot3d(x, y, z, ...) 绘制线条时可以使用的一个重要功能是将它们表示为管。 下面我用来绘制X,Y,Z轴以及3D图的例子(请注意,在我的例子中,尺寸很大,所以你可能想调整它们): import

python argparse to handle arbitrary numeric options (like HEAD(1))

Is there a way to trick argparse into accepting arbitrary numeric arguments like HEAD(1) ? head -5 test.txt is equivalent to head -n 5 test.txt My current approach is to use parse_known_args() and then handle the remainder, but I'd wish there was something a tad more elegant. agrparse和optparse都不支持这一点。 对的,这是可能的: #!/usr/bin/env python # coding: utf-8 from argparse impor

python argparse处理任意数字选项(如HEAD(1))

有没有办法欺骗argparse接受像HEAD(1)这样的任意数字参数? head -5 test.txt 相当于 head -n 5 test.txt 我目前的做法是使用parse_known_args() ,然后处理余数,但我希望有一些更优雅的东西。 agrparse和optparse都不支持这一点。 对的,这是可能的: #!/usr/bin/env python # coding: utf-8 from argparse import ArgumentParser parser = ArgumentParser(description='Argparse with numeric arguments') parser.add_

How to automatically classify images by dominant color?

I have many images (tens of thousands) of fairly large JPG images. Each is an image of an index card. Most of them are white, but some have standard index-card colors (these colors). The colors correspond to data attributes, so I would like to programmatically classify these cards by color. I know it's possible to extract the dominant color from images in a web browser using a canvas ele

如何按主色自动分类图像?

我有很多图像(数以万计)相当大的JPG图像。 每张图片都是索引卡的图片。 他们大多数是白色的,但有些具有标准的索引卡片颜色(这些颜色)。 颜色对应于数据属性,所以我想以编程方式将这些卡按颜色分类。 我知道可以使用canvas元素和颜色小偷等算法从Web浏览器中的图像中提取主色,并且它可以工作 - 它为我提供了足以装入卡片的rgb值。 但我看不到如何通过网络浏览器在如此多的图像上运行这样的事情。 我想知道是否有

How to preserve column order while using psycopg2.extras.RealDictCursor

dict_cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) dict_cur.execute("SELECT column1, column2, column3 FROM mytable") result = dict_cur.fetchall() print result[0] >>> {'column2':10, 'column1':12, 'column3':42} How could I preserve column ordering without parsing executed SQL first? It works well with normal cursor when list is returned, but I need access to dictionary

如何在使用psycopg2.extras.RealDictCursor时保留列顺序

dict_cur = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) dict_cur.execute("SELECT column1, column2, column3 FROM mytable") result = dict_cur.fetchall() print result[0] >>> {'column2':10, 'column1':12, 'column3':42} 我如何保留列顺序而不先解析执行的SQL? 当返回列表时,它与普通游标一起工作良好,但我需要访问字典键,因此需要使用RealDictCursor。 编辑 :嗯,我实际上不能。 游标

Avoiding multiple references to the same object in Django ORM

We have an app with highly interrelated data, ie there are many cases where two objects might refer to the same object via a relationship. As far as I can tell, Django does not make any attempt to return a reference to an already-fetched object if you attempt to fetch it via a different, previously unevaluated relationship. For example: class Customer( Model ): firstName = CharField( max_

避免在Django ORM中多次引用同一对象

我们有一个具有高度相关数据的应用程序,即有很多情况下两个对象可能通过关系引用同一个对象。 据我所知,如果你试图通过不同的,以前未评估的关系来获取它,Django不会尝试返回已经获取的对象的引用。 例如: class Customer( Model ): firstName = CharField( max_length = 64 ) lastName = CharField( max_length = 64 ) class Order( Model ): customer = ForeignKey( Customer, related_name = "orders" )

Display image without gtk

I would like to display an image in Python using gstreamer bindings, but without using GTK+ (I'm on ARM). I know how to listen to music with python and gstreamer : #!/usr/bin/python # Simply initiates a gstreamer pipeline without gtk import gst import gobject import sys mainloop = gobject.MainLoop() my_bin = gst.element_factory_make("playbin") my_bin.set_property("uri", "file:///home/Lumm

显示没有gtk的图像

我想使用gstreamer绑定在Python中显示图像,但不使用GTK +(我在ARM上)。 我知道如何用python和gstreamer来听音乐: #!/usr/bin/python # Simply initiates a gstreamer pipeline without gtk import gst import gobject import sys mainloop = gobject.MainLoop() my_bin = gst.element_factory_make("playbin") my_bin.set_property("uri", "file:///home/Lumme-Badloop.ogg") my_bin.set_state(gst.STATE_PLAYING) try:

Generic way to create nested dictionary from flat list in python

I am looking for the simplest generic way to convert this python list: x = [ {"foo":"A", "bar":"R", "baz":"X"}, {"foo":"A", "bar":"R", "baz":"Y"}, {"foo":"B", "bar":"S", "baz":"X"}, {"foo":"A", "bar":"S", "baz":"Y"}, {"foo":"C", "bar":"R", "baz":"Y"}, ] into: foos = [ {"foo":"A", "bars":[ {"bar":"R", "bazs":[

从python的平面列表中创建嵌套字典的通用方法

我正在寻找最简单的通用方式来转换这个python列表: x = [ {"foo":"A", "bar":"R", "baz":"X"}, {"foo":"A", "bar":"R", "baz":"Y"}, {"foo":"B", "bar":"S", "baz":"X"}, {"foo":"A", "bar":"S", "baz":"Y"}, {"foo":"C", "bar":"R", "baz":"Y"}, ] 成: foos = [ {"foo":"A", "bars":[ {"bar":"R", "bazs":[ {"baz":"X"},{"baz":"Y"}

listing multiple versions on pypi

I am using setup.py / distutils to distribute a package. How can multiple released versions of a py package be listed on pypi using setup.py/distutils? right now when I submit the latest version, it replaces all previous versions on the pypi package page and restarts the # downloads counter. Thanks. 登录到PyPi,选择您的软件包,您可以选择显示旧版本和/或禁用自动隐藏功能。

在pypi上列出多个版本

我使用setup.py / distutils来分发一个包。 如何使用setup.py/distutils在pypi上列出多个已发布的py软件包版本? 现在当我提交最新版本时,它会替换pypi包页面上的所有先前版本并重新启动#下载计数器。 谢谢。 登录到PyPi,选择您的软件包,您可以选择显示旧版本和/或禁用自动隐藏功能。

Have Facebook dropped support for Python?

The Python SDK seems to have been removed from Github. https://github.com/facebook/python-sdk returns a 404. Have they moved the development somewhere else, dropped support, or is this just a mistake? The developer site still links to Github (see https://developers.facebook.com/opensource/) but that doesn't really mean much. Does anyone have a clone? Edit I realise the API is still

Facebook是否放弃了对Python的支持?

Python SDK似乎已从Github中删除。 https://github.com/facebook/python-sdk返回404。 他们是否将开发移到其他地方,放弃了支持,还是这只是一个错误? 开发者网站仍然链接到Github(请参阅https://developers.facebook.com/opensource/),但这并不意味着太多。 有没有人有克隆? 编辑 我意识到API仍然可用,但这不是重点。 许多第三方软件包依赖于SDK(如django-socialregistration)。 删除存储库已经打破了所有