小编Ben*_*ing的帖子

使用Python将日记文件拆分为多个文件

我保留了技术说明的日记文件.每个条目都加上时间戳,如下所示:

# Monday 02012-05-07 at 01:45:20 PM

This is a sample note

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est …
Run Code Online (Sandbox Code Playgroud)

python regex file-io text

3
推荐指数
1
解决办法
2250
查看次数

编写Python RegEx以在HTML中选择列表项的子集

我有一个文件夹的Web索引视图...

<ul><li><a href="/sustainabilitymedia/pics/s5/"> Parent Directory</a></li> 
<li><a href="n150850_.jpg"> n150850_.jpg</a></li> 
<li><a href="n150850_ss.jpg"> n150850_ss.jpg</a></li> 
<li><a href="n150850q.jpg"> n150850q.jpg</a></li> 
<li><a href="n150858_.jpg"> n150858_.jpg</a></li> 
<li><a href="n150858_ss.jpg"> n150858_ss.jpg</a></li> 
<li><a href="n150858q.jpg"> n150858q.jpg</a></li> 
<li><a href="n150906_.jpg"> n150906_.jpg</a></li> 
<li><a href="n150906_ss.jpg"> n150906_ss.jpg</a></li>
...
Run Code Online (Sandbox Code Playgroud)

列表一直在继续.我的目标是只抓取结尾的列表项,_ss.jpg以便我可以渲染我的结果并在页面上很好地显示它们以进行演示.

我可以使用BeautifulSoup抓取页面,但从那里,我不知道如何过滤掉只匹配特定模式的列表项.该页面位于Basic Auth之后,我在之前关于BeautifulSoup的问题中已经解决了这个问题.我很高兴不使用它.

有任何想法吗?

html python regex beautifulsoup

1
推荐指数
1
解决办法
691
查看次数

在Python中,我可以在一个条件中处理两个变量吗?

有可能简化这个吗?也许两者相结合?教我干燥的方法: - \

o = old_last_result
if o == 7:
    old_last_result_msg = result_7
elif o == 12:
    old_last_result_msg = result_12
elif o == 23:
    old_last_result_msg = result_23
elif o == 24:
    old_last_result_msg = result_24
elif o == 103:
    old_last_result_msg = result_103
elif o == 1000:
    old_last_result_msg = result_1000
else:
    old_last_result_msg = "Error code: #%s" % old_last_result

n = new_last_result
if n == 7:
    new_last_result_msg = result_7
elif n == 12:
    new_last_result_msg = result_12
elif n == 23:
    new_last_result_msg = result_23 …
Run Code Online (Sandbox Code Playgroud)

python conditional

1
推荐指数
1
解决办法
195
查看次数

Python中的条件迭代器:我如何选择特定的迭代?

在django模板中,我完成了这个{% if forloop.first %}但是我不知道如何在常规'ole python中执行此操作而不用编写一个笨重的计数器来计算我的条件迭代.他们是一个简单的出路吗?

python django iterator conditional-operator

0
推荐指数
1
解决办法
363
查看次数