换句话说,可以使用/<tag[^>]*>.*?<\/tag>/正则表达式来匹配tag不包含嵌套tag元素的html 元素吗?
例如(lt.html):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>greater than sign in attribute value</title>
</head>
<body>
<div>1</div>
<div title=">">2</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
正则表达式:
$ perl -nE"say $1 if m~<div[^>]*>(.*?)</div>~" lt.html
Run Code Online (Sandbox Code Playgroud)
和屏幕刮刀:
#!/usr/bin/env python
import sys
import BeautifulSoup
soup = BeautifulSoup.BeautifulSoup(sys.stdin)
for div in soup.findAll('div'):
print div.string
$ python lt.py <lt.html
Run Code Online (Sandbox Code Playgroud)
两者都给出相同的输出:
1
">2
Run Code Online (Sandbox Code Playgroud)
预期产量:
1
2
Run Code Online (Sandbox Code Playgroud)
w3c说:
属性值是文本和字符引用的混合,除了文本不能包含模糊符号的附加限制.
给定一个整数数组,迭代它并找出它涵盖的所有范围的最简单方法是什么?例如,对于如下数组:
$numbers = array(1,3,4,5,6,8,11,12,14,15,16);
Run Code Online (Sandbox Code Playgroud)
范围是:
1,3-6,8,11-12,14-16
Run Code Online (Sandbox Code Playgroud) 我和一些朋友正在用Java编写MORPG,我们希望使用脚本语言,例如.创建任务.
我们没有使用Java编写脚本的经验.我们使用过Python,但我们对它缺乏经验.我们其中一个人也使用过Javascript.
我们应该使用什么脚本语言?我们不应该使用什么脚本语言?
这是顺序代码:
do i = 1, n
do j = i+1, n
if ("some_condition(i,j)") then
result = "here's result"
return
end if
end do
end do
Run Code Online (Sandbox Code Playgroud)
有没有更简洁的方法同时执行外部循环的迭代:
!$OMP PARALLEL private(i,j)
!$OMP DO
do i = 1, n
!$OMP FLUSH(found)
if (found) goto 10
do j = i+1, n
if ("some_condition(i,j)") then
!$OMP CRITICAL
!$OMP FLUSH(found)
if (.not.found) then
found = .true.
result = "here's result"
end if
!$OMP FLUSH(found)
!$OMP END CRITICAL
goto 10
end if
end do
10 continue
end …Run Code Online (Sandbox Code Playgroud) 在下面的代码中,我正在计算现在的纪元和当天纪元的开始.
import time
import pytz
from datetime import datetime
tz1 = pytz.timezone('CST6CDT')
utc = pytz.timezone('UTC')
now = pytz.UTC.localize(datetime.utcnow())
now_tz = now.astimezone(tz1)
print now_tz
print now_tz.strftime('%s')
begin_day = now_tz.replace(hour=0, minute=0, second=0)
print begin_day
print begin_day.strftime('%s')
Run Code Online (Sandbox Code Playgroud)
打印声明:
2012-08-28 13:52:21.595718-05:00
1346187141
2012-08-28 00:00:00.595718-05:00
1346137200
Run Code Online (Sandbox Code Playgroud)
使用CDT时区将时期转换为时间戳:1346187141 - 2012年8月28日15:52:21,1346137200 - 2012年8月28日02:00:00
我希望第二个时代开始,但现在是凌晨2点.在转换为纪元时,它看起来仍然使用本地时区PST.
我究竟做错了什么 ?或者这可以用不同的方式完成吗?
谢谢!
我有一个程序,每行读取3个字符串50000.然后做其他事情.读取文件并转换为整数的部分占总运行时间的80%.
我的代码段如下:
import time
file = open ('E:/temp/edges_big.txt').readlines()
start_time = time.time()
for line in file[1:]:
label1, label2, edge = line.strip().split()
# label1 = int(label1); label2 = int(label2); edge = float(edge)
# Rest of the loop deleted
print ('processing file took ', time.time() - start_time, "seconds")
Run Code Online (Sandbox Code Playgroud)
以上大约需要0.84秒.现在,当我取消注释该行
label1 = int(label1);label2 = int(label2);edge = float(edge)
Run Code Online (Sandbox Code Playgroud)
运行时间上升到大约3.42秒.
输入文件的格式为:str1 str2 str3每行
功能int()和float()那个慢吗?我怎么能优化这个?
以下curl命令工作正常(私有数据匿名):
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/abc/SMS/Messages.json' \
-d 'From=%2B14155551234' \
-d 'To=%2B17035551212' \
-d 'Body=This+is+a+test' \
-u foo:bar
Run Code Online (Sandbox Code Playgroud)
如何以正确的Python3.3方式发送这个完全相同的HTTPS POST请求?我不想使用Python 3.3标准库以外的任何东西,如果我可以避免它(换句话说,不使用twilio python模块,或"请求",或pycurl,或普通的外部Python之外的任何东西3.3安装).
首选的Python方法似乎不断从版本发展到版本,Googling发现的片段从未提及他们使用的版本或不执行登录部分,Python文档充满了"自3.x以来弃用"但永远不要包含新的做事方式的代码示例....
如果curl可以这么容易地做到这一点,标准Python 3.3也是如此.但是现在应该怎么做呢?
在尝试grep包含日志中的多行行的消息时,我遇到了以下错误...任何人都可以提供有关如何克服此错误的输入吗?
码:-
print gerrit_commitmsg
gerritlog = Popen('git','log','--grep','gerrit_commitmsg', stdout=PIPE, stderr=PIPE)
print gerritlog
Run Code Online (Sandbox Code Playgroud)
错误:-
Commit message:-
Build system changes
Build system changes to include packages in the build
Change-Id: I697558f01ae367d2baacdf2c7fcf1a03753edacd
Traceback (most recent call last):
File "gerrits_in_workspace.py", line 87, in <module>
main()
File "gerrits_in_workspace.py", line 77, in main
grep_commitmsg(gerrit_commitmsg)
File "gerrits_in_workspace.py", line 48, in grep_commitmsg
gerritlog = Popen('git','log','--grep','gerrit_commitmsg', stdout=PIPE, stderr=PIPE)
File "/usr/lib/python2.7/subprocess.py", line 629, in __init__
raise TypeError("bufsize must be an integer")
Run Code Online (Sandbox Code Playgroud) 做Python的str.__lt__或sorted顺序字符根据其Unicode索引或某些区域设置相关的排序规则?