【发布时间】:2017-05-18 08:55:54
【问题描述】:
我在 main_watch_images 列表中有两个项目,只想打印第一个。我试图在 findall 行之后添加 [0],但是它会垂直打印每个字母。我认为这是因为 for 循环将所有内容都打印在新行上,但我无法将其全部打印在一行上。
# Extract the first image (this is always the main image) that is in the
# "LIMITED" category
main_watch_images = findall('<img.* src="([^"]+).*LIMITED"', dennisov_html)
# Convert the URL to a full address
for images in main_watch_images:
if images.startswith('/'):
images = 'https://denissov.ru' + images
print images
请注意,这与其他问题不同。我是一个绝对的初学者,无法理解其他答案中使用的技术和操作符等。我需要一个具体的答案来解决我的问题。
【问题讨论】:
-
findall()返回什么?你能展示一个示例输出吗? -
正如副本上的答案之一所说,使用
print images,(注意,)。 -
它提供了两个网站,例如denissov.ru/files/collections/o_148441359756.png denissov.ru/files/collections/… 我只想通过打印名为 main_watch_images 的列表中的第一项来打印第一个。如果我在这一行使用 [0],它会垂直打印每个字母
标签: python python-2.7 for-loop newline