我new_tag从带有self.response.get("new_tag")和selected_tags来自复选框字段的表单文本字段中获取
self.response.get_all("selected_tags")
Run Code Online (Sandbox Code Playgroud)
我把它们组合成这样:
tag_string = new_tag
new_tag_list = f1.striplist(tag_string.split(",") + selected_tags)
Run Code Online (Sandbox Code Playgroud)
(f1.striplist是一个删除列表中字符串内部空格的函数.)
但是在tag_list空的情况下(没有输入新标签)但有一些selected_tags,new_tag_list包含一个空字符串" ".
例如,来自logging.info:
new_tag
selected_tags[u'Hello', u'Cool', u'Glam']
new_tag_list[u'', u'Hello', u'Cool', u'Glam']
Run Code Online (Sandbox Code Playgroud)
如何摆脱空字符串?
如果列表中有空字符串:
>>> s = [u'', u'Hello', u'Cool', u'Glam']
>>> i = s.index("")
>>> del s[i]
>>> s
[u'Hello', u'Cool', u'Glam']
Run Code Online (Sandbox Code Playgroud)
但是如果没有空字符串:
>>> s = [u'Hello', u'Cool', u'Glam']
>>> if s.index(""):
i = s.index("")
del s[i]
else:
print "new_tag_list …Run Code Online (Sandbox Code Playgroud) 此代码打开URL并/names在末尾附加并打开页面并将字符串打印到test1.csv:
import urllib2
import re
import csv
url = ("http://www.example.com")
bios = [u'/name1', u'/name2', u'/name3']
csvwriter = csv.writer(open("/test1.csv", "a"))
for l in bios:
OpenThisLink = url + l
response = urllib2.urlopen(OpenThisLink)
html = response.read()
item = re.search('(JD)(.*?)(\d+)', html)
if item:
JD = item.group()
csvwriter.writerow(JD)
else:
NoJD = "NoJD"
csvwriter.writerow(NoJD)
Run Code Online (Sandbox Code Playgroud)
但我得到了这个结果:
J,D,",", ,C,o,l,u,m,b,i,a, ,L,a,w, ,S,c,h,o,o,l,....
如果我将字符串更改为("JD","哥伦比亚大学法学院"......),那么我得到了
JD, Columbia Law School...)
我在文档中找不到如何指定分隔符.
如果我尝试使用,delimenter我会收到此错误:
TypeError: 'delimeter' is an invalid keyword argument for this function
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
我用连接到远程机器ssh user@192.168.1.5.当我需要在远程机器中打开文件时,例如,
emacs /usr/share/nginx/html/index.html
并index.html在shell 中打开文件.我注意到一些emacs命令工作但其他命令不起作用.例如,C-w不起作用; M-<不起作用.我该如何解决这个问题,使用emacs和ssh的最佳方法是什么?
我发现了这个问题,但它让我更加困惑.
我有这个admin.py
class LawyerAdmin(admin.ModelAdmin):
fieldsets = [
('Name', {'fields': ['last', 'first', 'firm_name', 'firm_url', 'school', 'year_graduated']}),
]
list_display = ('last', 'first', 'school', 'year_graduated', 'firm_name', 'firm_url')
list_filter = ['school', 'year_graduated']
search_fields = ['last', 'school', 'firm_name']
Run Code Online (Sandbox Code Playgroud)
我想让"firm_url"字段与字段中列出的每个网址一起点击.我怎样才能做到这一点?谢谢.
我刚刚用Clojure开始了Web开发,但我遇到了一个非常简单的问题.我:main myapp.core/foo在project.clj
(defproject myapp "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.5.1"]]
;; this will set foo as the main function
:main myapp.core/foo)
Run Code Online (Sandbox Code Playgroud)
但是当我跑步时lein我得到这个错误:
C:\Users\a>lein run First
No :main namespace specified in project.clj.
C:\Users\a>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在阅读nginx初学者的教程,在他们有的服务静态内容部分
http {
server {
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我添加一个http块时,我得到了错误
[emerg]这里不允许"http"指令......
当我删除http块并将conf文件更改为此文件时,它可以正常工作:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/example.com/html;
index index.html index.htm;
# make site accessible from http://localhost/
server_name localhost
location / {
try_files $uri $uri/ /index.html;
}
Run Code Online (Sandbox Code Playgroud)
我怀疑我错过了一些简单的东西,但为什么他们使用http来提供静态文件呢?
我准备运行此代码,但在我想修复异常处理之前:
for l in bios:
OpenThisLink = url + l
try:
response = urllib2.urlopen(OpenThisLink)
except urllib2.HTTPError:
pass
bio = response.read()
item = re.search('(JD)(.*?)(\d+)', bio)
....
Run Code Online (Sandbox Code Playgroud)
正如这里建议的那样,我添加了try...except但是现在如果页面没有打开,我会收到此错误:
bio = response.read()
NameError: name 'response' is not defined
Run Code Online (Sandbox Code Playgroud)
所以程序继续执行.相反,我希望它回到for循环并尝试下一个url.我试过break而不是pass但结束了程序.有什么建议?
>>> myList[1]
'from form'
>>> myList[1].append(s)
Traceback (most recent call last):
File "<pyshell#144>", line 1, in <module>
myList[1].append(s)
AttributeError: 'str' object has no attribute 'append'
>>>
Run Code Online (Sandbox Code Playgroud)
为什么myList[1]被认为是一个'str'对象?mList[1]返回列表中的第一项,'from form'但我无法附加到列表中的第1项myList.谢谢.
Edit01:
@pyfunc:谢谢你的解释; 现在我明白了.
我需要一份清单清单; 所以'从形式'应该是一个列表.我这样做了(如果这不正确,请更正):
>>> myList
[1, 'from form', [1, 2, 't']]
>>> s = myList[1]
>>> s
'from form'
>>> s = [myList[1]]
>>> s
['from form']
>>> myList[1] = s
>>> myList
[1, ['from form'], [1, 2, 't']]
>>>
Run Code Online (Sandbox Code Playgroud) 你知道为什么BeautifulSoup教程中的第一个例子http://www.crummy.com/software/BeautifulSoup/documentation.html#QuickStart给出了AttributeError: 'NavigableString' object has no attribute 'name'吗?根据这个答案,HTML中的空格字符会导致问题.我尝试了几页的来源和1个工作,其他人给出了同样的错误(我删除了空格).你能解释"名称"所指的是什么以及为什么会发生这种错误吗?谢谢.
我下载了tar文件emacs-24.3.tar.gz并将其解压缩.我在这里查看安装说明:
您可以在没有任何额外步骤的情况下运行Emacs,但是如果您想在"开始"菜单中使用图标,或者要让Emacs检测作为GTK的一部分已经安装在系统上的图像库,那么您应该运行程序emacs-24.3\bin\addpm.exe.
我如何运行Emacs?
在哪里emacs-24\bin\addpm.exe.在文件夹emacs-24中没有bin文件夹.那么如何在安装后运行emacs?