在Python中,我可以使用该.values()方法迭代字典的值.
例如:
mydict = {'a': [3,5,6,43,3,6,3,],
'b': [87,65,3,45,7,8],
'c': [34,57,8,9,9,2],}
values = mydict.values():
Run Code Online (Sandbox Code Playgroud)
其中values包括:
[
[3,5,6,43,3,6,3,],
[87,65,3,45,7,8],
[34,57,8,9,9,2],
]
Run Code Online (Sandbox Code Playgroud)
如何在Javascript中只获取字典的值?
编辑
我原来的印刷例子并不清楚我想做什么.我只想要字典中值的列表/数组.
我意识到我可以遍历列表并创建一个新的值列表,但有更好的方法吗?
我有一个zip存档:my_zip.zip.里面是一个txt文件,我不知道其名称.我正在看一下Python的zipfile模块(http://docs.python.org/library/zipfile.html),但是我无法理解我正在尝试做什么.
我怎么做相当于'双击'zip文件来获取txt文件,然后使用txt文件,所以我可以这样做:
>>> f = open('my_txt_file.txt','r')
>>> contents = f.read()
Run Code Online (Sandbox Code Playgroud) 我想采用多页pdf文件,并在每页创建单独的pdf文件.
我已经下载了reportlab并浏览了文档,但它似乎是针对pdf生成的.我还没有看到任何关于自己处理PDF文件的事情.
在python中有一个简单的方法吗?
我无法登录django管理页面.当我输入有效的用户名和密码时,它只会再次显示登录页面,没有错误消息
这个问题在django常见问题解答中,但我已经在那里找到答案,仍然无法通过初始登录屏幕.
我在ubuntu 12.04上使用django 1.4和apache2以及modwsgi.
我已经确认我在admin.py文件中注册了admin ,确保在添加后确认syncdb INSTALLED_APPS.当我输入了错误的密码我DO得到一个错误,所以我的管理员用户进行认证,只是没有在进行管理页面.
我已经尝试过设置SESSION_COOKIE_DOMAIN机器的IP和无.(确认cookie域显示为Chrome中机器的IP)
另外,检查用户是否通过shell进行身份验证:
>>> from django.contrib.auth import authenticate
>>> u = authenticate(username="user", password="pass")
>>> u.is_staff
True
>>> u.is_superuser
True
>>> u.is_active
True
Run Code Online (Sandbox Code Playgroud)
尝试使用IE8和chrome canary登录,两者都会导致返回登录屏幕.
还有别的什么我想念????
settings.py
...
MIDDLEWARE_CLASSES = (
'django.middleware.gzip.GZipMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.transaction.TransactionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.admin',
'django.contrib.staticfiles',
'django.contrib.gis',
'myapp.main',
)
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
SESSION_SAVE_EVERY_REQUEST = True
SESSION_COOKIE_AGE = 86400 # …Run Code Online (Sandbox Code Playgroud) 我是红宝石的新手,我正在玩IRB.
我发现我可以使用".methods"方法列出对象的方法,而self.methods类似于我想要的东西(类似于Python的dir(builtins)?),但我怎样才能找到方法库/模块我通过include和require加载?
irb(main):036:0* self.methods
=> ["irb_pop_binding", "inspect", "taguri", "irb_chws", "clone", "irb_pushws", "public_methods", "taguri=", "irb_pwws",
"public", "display", "irb_require", "irb_exit", "instance_variable_defined?", "irb_cb", "equal?", "freeze", "irb_context
", "irb_pop_workspace", "irb_cwb", "irb_jobs", "irb_bindings", "methods", "irb_current_working_workspace", "respond_to?"
, "irb_popb", "irb_cws", "fg", "pushws", "conf", "dup", "cwws", "instance_variables", "source", "cb", "kill", "help", "_
_id__", "method", "eql?", "irb_pwb", "id", "bindings", "send", "singleton_methods", "popb", "irb_kill", "chws", "taint",
"irb_push_binding", "instance_variable_get", "frozen?", "irb_source", "pwws", "private", "instance_of?", "__send__", "i
rb_workspaces", "to_a", "irb_quit", "to_yaml_style", "irb_popws", "irb_change_workspace", "jobs", "type", "install_alias
_method", "irb_push_workspace", "require_gem", …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的网站,我正在使用page_cache装饰器.我有一个cronjob,它检查新数据并在可用时处理它.(这是使用crontab执行的管理命令运行的)
我想在处理新数据时清除所有页面缓存.
我正在看这里的文档:https: //docs.djangoproject.com/en/dev/topics/cache/?from = olddocs?from = olddocs
并发现cache.clear(),这似乎是我想要的.我在数据处理部分添加了一个标志,并cache.clear()在找到新数据时执行.
但是,在命令运行后,不会清除缓存.(我已经清除了缓存的浏览器并检查以确定它不是浏览器)
难道cache.clear()不工作,清除所有缓存的页面?
我正在使用DatabaseCache,所以我想我可以手动清除缓存表,但是有更好的方法吗?
无论鼠标位于哪个窗口,我如何检测鼠标点击?
在python中Perferabliy,但是如果有人可以在任何语言中解释它我可能能够弄明白.
我在microsoft的网站上找到了这个:http: //msdn.microsoft.com/en-us/library/ms645533(VS.85).aspx
但我不知道如何检测或接收列出的通知.
尝试使用pygame的pygame.mouse.get_pos()函数,如下所示:
import pygame
pygame.init()
while True:
print pygame.mouse.get_pos()
Run Code Online (Sandbox Code Playgroud)
这只会返回0,0.我不熟悉pygame,缺少什么?
无论如何,我更喜欢不需要安装第三方模块的方法.(除了pywin32 http://sourceforge.net/projects/pywin32/)
我有一个数据框,想要按一系列值过滤或分组,然后获取每个bin中的值计数.
目前,我这样做:
x = 5
y = 17
z = 33
filter_values = [x, y, z]
filtered_a = df[df.filtercol <= x]
a_count = filtered_a.filtercol.count()
filtered_b = df[df.filtercol > x]
filtered_b = filtered_b[filtered_b <= y]
b_count = filtered_b.filtercol.count()
filtered_c = df[df.filtercol > y]
c_count = filtered_c.filtercol.count()
Run Code Online (Sandbox Code Playgroud)
但有没有更简洁的方法来完成同样的事情?
所以我在传单中有一个geojson图层,我可以将geojson对象添加到此图层以在结果图上显示.
现在我想添加一个文本标签来显示在对象附近.
此示例显示使用自定义L.control()对象在地图上显示其他信息.这似乎接近我想做的事情.
在这个例子中,我想添加位于每个状态上的State初始文本标签(即"TX","FL").可以L.control()用来做这个,还是有另一种方式?
http://leaflet.cloudmade.com/examples/choropleth.html
var info = L.control();
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
// method that we will use to update the control based on feature properties passed
info.update = function (props) {
this._div.innerHTML = '<h4>US Population Density</h4>' + (props ?
'<b>' + props.name + '</b><br />' + props.density + ' people / mi<sup>2</sup>'
: 'Hover over a state'); …Run Code Online (Sandbox Code Playgroud) 我想创建一个最简单的(hello world package)包,我可以使用pip在本地zip文件的virtualenv中安装.
在python我会做
>> from myinstallpackage import mymodule
>> mymodule.sayhello()
hello !
Run Code Online (Sandbox Code Playgroud)
setup.py和包文件夹中会包含什么内容?
谢谢