我有一个Git存储库.这个存储库有多个远程存储库(我认为).如何获取属于所述存储库的远程存储库列表?
喜欢git list --remotes或类似的东西?
我想在可执行的python脚本中创建一个文件.
import os
import stat
os.chmod('somefile', stat.S_IEXEC)
Run Code Online (Sandbox Code Playgroud)
它似乎os.chmod没有像unix chmod那样"添加"权限.注释掉最后一行后,该文件具有filemode -rw-r--r--,未注释掉,文件模式为---x------.如何u+x在保持其余模式完整的同时添加标志?
我正在编写一个需要timedelta输入的函数作为字符串传入.用户必须输入类似"32m"或"2h32m",甚至"4:13"或"5hr34m56s"的内容......是否有图书馆或其他已经实施此类内容的内容?
如何获得可迭代的类中的所有变量的列表?有点像locals(),但对于一个类
class Example(object):
bool143 = True
bool2 = True
blah = False
foo = True
foobar2000 = False
def as_list(self)
ret = []
for field in XXX:
if getattr(self, field):
ret.append(field)
return ",".join(ret)
Run Code Online (Sandbox Code Playgroud)
这应该回来了
>>> e = Example()
>>> e.as_list()
bool143, bool2, foo
Run Code Online (Sandbox Code Playgroud) 我有一个函数接受一个参数,可以是单个项目或双项目:
def iterable(arg)
if #arg is an iterable:
print "yes"
else:
print "no"
Run Code Online (Sandbox Code Playgroud)
以便:
>>> iterable( ("f","f") )
yes
>>> iterable( ["f","f"] )
yes
>>> iterable("ff")
no
问题是字符串在技术上是可迭代的,所以我不能在尝试时捕获ValueError arg[1].我不想使用isinstance(),因为这不是很好的做法(或者我被告知).
我想给我的图表一个大的18pt字体的标题,然后是一个较小的10pt字体下面的字幕.我怎么能在matplotlib中这样做?看起来该title()函数只接受一个具有单个fontsize属性的字符串.必须有办法做到这一点,但如何?
在python中,你可以这样做:
[([None] * 9) for x in range(9)]
Run Code Online (Sandbox Code Playgroud)
你会得到这个:
[[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, None],
[None, None, None, None, None, None, None, None, …Run Code Online (Sandbox Code Playgroud) 我正在尝试将一个SHP文件放入我的PostGIS数据库中,数据有点偏差.我想这是因为我使用了错误的SRID.PRJ文件的内容如下:
GEOGCS["GCS_North_American_1983",
DATUM["D_North_American_1983",
SPHEROID["GRS_1980",6378137.0,298.257222101]],
PRIMEM["Greenwich",0.0],
UNIT["Degree",0.0174532925199433]]
Run Code Online (Sandbox Code Playgroud)
SRID与此相关的是什么?更一般地说,如何根据PRJ文件中的信息查找SRID?在某个地方是否有一个列出所有SRID及其"geogcs"等价物的查找表?
作为参考,这里是使用导入的一些数据的图像srid=4269(我也尝试了4326并获得了完全相同的结果):
图片http://img245.imageshack.us/img245/2545/4326sand.png
黄色是我从SHP导入的数据,背景来自openlayers(来自geodjango admin).这是否意味着我使用了错误的SRID,或者这只是预期的误差范围?
shp文件来自这里
我知道Django 1.1有一些新的聚合方法.但是我无法弄清楚以下查询的等价物:
SELECT player_type, COUNT(*) FROM players GROUP BY player_type;
Run Code Online (Sandbox Code Playgroud)
是否可以使用Django 1.1的Model Query API,还是应该使用纯SQL?
我有一个django应用程序,一个论坛应用程序,它有模板.在这些模板中,有一些网址指向应用程序的某些部分.例如,thread_list模板具有到每个线程的链接,如下所示:
{% for thread in threads %}
<a href="{% url forum_thread thread %}">{{thread.title}}</a>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
问题是,我真的不喜欢称我的网址为"forum_thread".我更喜欢"线程"并使用django的命名空间功能."forum_thread"可以在项目的其他地方使用(名称空间冲突).所以它看起来像这样:
{% for thread in threads %}
<a href="{% url forum:thread thread %}">{{thread.title}}</a>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
但这不是正确的方法.这里的文档有点不清楚.
我希望这个应用程序可重用且易于配置.但我也想使用最好的标准.我不想让用户指定自己的命名空间名称,然后让他们编辑每个模板中的每个网址.
我应该如何在这个应用程序中做网址?
python ×5
django ×2
chmod ×1
datetime ×1
django-urls ×1
geodjango ×1
gis ×1
git ×1
javascript ×1
matplotlib ×1
postgis ×1
sql ×1
srid ×1
timedelta ×1