我刚开始使用urllib3,我马上就遇到了问题.根据他们的手册,我从一个简单的例子开始:
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib3
>>>
>>> http = urllib3.PoolManager()
>>> r = http.request('GET', 'http://google.com/')
Run Code Online (Sandbox Code Playgroud)
我被抛出以下错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/urllib3/request.py", line 65, in request
**urlopen_kw)
File "/usr/local/lib/python2.7/dist-packages/urllib3/request.py", line 78, in request_encode_url
return self.urlopen(method, url, **urlopen_kw)
File "/usr/local/lib/python2.7/dist-packages/urllib3/poolmanager.py", line 113, in urlopen
return self.urlopen(method, e.new_url, **kw)
File "/usr/local/lib/python2.7/dist-packages/urllib3/poolmanager.py", line 113, in urlopen
return …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习在我的服务器上安装的nano(ubuntu 1204),但问题是每当我在nano编辑器中打开文件时它会将文件(比如一个shell脚本)打开为一个大行,而不是适合屏幕的换行符.
是否可以在nano中打开包含换行符的文件?我试过谷歌搜索这个问题,但找不到任何有用的东西.
任何帮助将非常感激.
我一直在尝试学习和掌握Django中分页的ListViews,但是在理解概念时似乎有些麻烦。所以,让我显示一些代码-我的view.py看起来像这样:
class SearchDisplayListView(ListView):
model = BlogPosts
template_name = "searchres_list.html"
paginate_by = '15'
context_object_name = "searchres"
def get_context_data(self, **kwargs):
context = super(SearchDisplayListView, self).get_context_data(**kwargs)
q = self.request.GET.get('q')
q = q.replace(" ","+")
context['searchq'] = q
return context
def get_queryset(self):
queryset = super(SearchDisplayListView, self).get_queryset()
# Get the q GET parameter
q = self.request.GET.get('q')
q = q.replace(" ","+")
if q is None:
# Return the base queryset
return queryset
# Return a filtered queryset
## do some awesome calculations using "q" i.e send request to …Run Code Online (Sandbox Code Playgroud) 我对 postgresql 全文搜索很陌生,我正在设置配置,因为我可以在哪里下载 ispell *.dict 和 *.affix filefollowing(与docs完全一样):
CREATE TEXT SEARCH DICTIONARY english_ispell (
TEMPLATE = ispell,
DictFile = english,
AffFile = english,
StopWords = english
);
Run Code Online (Sandbox Code Playgroud)
所以,我认为这需要文件english.dict,english.affix例如:
/usr/share/postgresql/9.2/tsearch_data
Run Code Online (Sandbox Code Playgroud)
但是这些文件不存在。我只有ispell_sample.dict和ispell_sample.affix- 当包含在上面时可以正常工作 - 没问题。
所以......我跟着这个职位,并下载必要的词典,从开放的办公室的人,并更名为.dic给.dict和.aff给.affix。然后我检查(使用file -bi dict.affix和file -bi english.dict他们是UTF8编码)。
当我运行上面的文本搜索字典时,出现错误:
ERROR: wrong affix file format for flag
CONTEXT: line 2778 of configuration file "/usr/share/postgresql/9.2/tsearch_data/english.affix": "COMPOUNDMIN …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习 python-watchdog,但我有点困惑为什么我设置的作业运行不止一次。所以,这是我的设置:
#handler.py
import os
from watchdog.events import FileSystemEventHandler
from actions import run_something
def getext(filename):
return os.path.splitext(filename)[-1].lower()
class ChangeHandler(FileSystemEventHandler):
def on_any_event(self, event):
if event.is_directory:
return
if getext(event.src_path) == '.done':
run_something()
else:
print "event not directory.. exiting..."
pass
Run Code Online (Sandbox Code Playgroud)
观察者设置如下:
#observer.py
import os
import time
from watchdog.observers import Observer
from handler import ChangeHandler
BASEDIR = "/path/to/some/directory/bin"
def main():
while 1:
event_handler = ChangeHandler()
observer = Observer()
observer.schedule(event_handler, BASEDIR, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()
if __name__ == '__main__': …Run Code Online (Sandbox Code Playgroud) 标题不言自明。我在linux和python2.7中收到以下错误:
Could not find a version that satisfies the requirement python-libtorrent (from versions: )
No matching distribution found for python-libtorrent
Run Code Online (Sandbox Code Playgroud)
我可以在pypi上看到它:
https://pypi.python.org/pypi/python-libtorrent/
那么,为什么不安装呢?
谢谢!
我正试图掌握django,我无法使用主键检索对象,这些主键来自另一个列表.所以,我能够做到以下几点:
one_entry = Entry.objects.get(pk=1)
Run Code Online (Sandbox Code Playgroud)
这看起来很好 - 没问题.现在,我有一个像这样的pk列表:
pk_id=[1,5,10,200,300,310]
Run Code Online (Sandbox Code Playgroud)
我想用上面的pks(循环?)提取对象并使其成为一个single queryset.我不确定循环是最好的选择 - 想知道是否有人能指出我正确的方向从列表中收集pk的对象并返回一个结果查询集.
我是python的新手,我一直在学习列表理解以及python列表和字典.
所以,我想做的事情如下:
[my_functiona(x) for x in a]
Run Code Online (Sandbox Code Playgroud)
..哪个工作完全正常.
但是,现在我想要做以下事情:
[my_functiona(x) for x in a] && [my_functionb(x) for x in a]
Run Code Online (Sandbox Code Playgroud)
..有没有办法结合或链接这样的列表理解? - 第二个函数使用第一个列表的结果.简而言之,我想申请my_functiona并 my_functionb随后列出a
我确实尝试使用谷歌搜索 - 但找不到任何令人满意的东西.对不起,如果这是一个愚蠢的101问题!
我一直在努力学习python-unipath并且已经掌握了基本的命令.但是,我被这个问题困扰了.所以,我想得到当前文件的祖先(2).所以,在python解释器上,我做了这样的事情:
Python 2.7.3 (default, Jan 2 2013, 13:56:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from unipath import Path
>>> ORM_ROOT = Path("/home/foo/lump/foobar/turf/orm/unipath_try.py").ancestor(2)
>>> ORM_ROOT
Path('/home/foo/lump/foobar/turf')
Run Code Online (Sandbox Code Playgroud)
..这是正确的,正是我想要的.现在,我将它包装在一个文件中,如下所示:
# -*- coding: utf-8 -*-
# unipath_try.py
from unipath import Path
ORM_ROOT = Path(__file__).ancestor(2)
print ORM_ROOT
Run Code Online (Sandbox Code Playgroud)
当我运行这个使用时,python unipath_try.py我没有输出!没有导入错误.我完全不知道为什么会这样 - 可能是非常愚蠢的事情.将不胜感激任何帮助/方向:(
我有一个安装了 debian 的服务器,apt几个月前我曾经在那里安装 pgsql9.4。现在,一个月后,我看到该文件夹总计 19GB:
/var/lib/postgresql/9.4/main
Run Code Online (Sandbox Code Playgroud)
占用了我所有的空间rootfs(19GB)。同意,我正在将一些沉重的 UTf-8 内容写入实例。
问这个问题可能很愚蠢,但是,有没有办法可以move将 postgres 中的这个文件夹/安装程序转移到另一个磁盘?仍然不影响我的数据库?这甚至可以做到吗?
python ×5
django ×2
django-views ×2
linux ×2
python-2.7 ×2
dictionary ×1
ispell ×1
libtorrent ×1
nano ×1
nlp ×1
postgresql ×1
ubuntu-12.04 ×1
urllib ×1
urllib2 ×1
urllib3 ×1