在python中创建超链接 [英] creating hyperlinks in python

查看:1255
本文介绍了在python中创建超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日志文件,其中一些测试命令及其状态(Pass / Fail)使用python进行记录。现在我希望测试命令不应该写成简单的文本,而应该写成超链接。因此,当我点击它们时,打开了链接到它们的另一个文件。



例如:

  file = open(C:/logfile.log,w)
file.write([命令名称 - '%35s'] [PASSED] \\\
%(CommandName))
file.close()

file1 = open(C:/TestCommand.log/,w)
file1.write( '%35s \\\
%(str(parameter_val_for_test_command)))
file1.close()

现在我希望在logfile.log中写入的CommandName应该是文件TestCommand.log的超链接。因此,当我单击CommandName时,将打开文件TestCommand.log。



您能否建议我应该如何创建带有超链接CommandName的logfile.log,然后如何将此超链接CommandName链接到文件TestCommand.log ??

解决方案

你似乎对超链接有些困惑, 文本文件是包含文本的文件。 (这很简单,但需要说!)它没有图片,动画,颜色,标题或类似的东西。它只是文本。



由于人们通常需要更多的数据和文本(x应该是一个标题,y应该是红色的,z应该在鼠标悬停时制作一个有趣的光标)它),有许多用于编码关于文本的数据的方案。例如, Markdown 是StackOverflow使用的文本格式。 HTML是一种使用< tag> 元素的标记语言(一种标注文本的方式)。这很有用,因为Web浏览器可以将HTML页面作为输入并以图形方式显示它们。

您描述的超链接是一个图形元素,例如您可能在网站上找到的图形元素。您不能将它们放在文本文件中,因为文本文件只是文本 。但您可以通过编写

 < a href =where / you / want / the来指示Web浏览器显示超链接/ link / to / go>文字链接< / a> 

如果您在网络浏览器中打开一个包含该文件的文件,它会将文本显示为链接。请注意,包含HTML的文件通常称为 something.html 来指示其内容,并且任何HTML文档中都有一堆必需的标记(< ; html>< head>< / head>< body>< / body>< / html> )。

I have a log file in which some test commands and their status (Pass/Fail) are logged using python. Now I want that test commands should not be written as simple text but should be written as hyperlinks. So that when I click on them another files which are linked to them are opened.

For e.g:

file = open("C:/logfile.log", "w")
file.write("[Command Name - '%35s']    [PASSED]\n" %(CommandName))
file.close()

file1 = open("C:/TestCommand.log/", "w")
file1.write("'%35s \n" %(str(parameter_val_for_test_command)))
file1.close()

Now I want that the CommandName written in logfile.log should be a hyperlink for the file TestCommand.log So that when I click on the CommandName the file TestCommand.log opens.

Can you please suggest how should I do create a logfile.log with hyperlinked CommandName and then how should I link this hyperlinked CommandName to the file TestCommand.log??

解决方案

You seem to be a bit confused about what a hyperlink, well, is.

A text file is a file containing text. (It's simple, but it needs to be said!) It doesn't have pictures, animations, colours, headers, or anything like that. It's just text.

Since people often want more data with their text (x should be a heading, y should be red, z should make a funny cursor when you mouse over it), there are many schemes for encoding data about text. For example, Markdown is a text format used by StackOverflow. HTML is a markup language (a way of annotating text) that uses <tag> elements. It's useful because web browsers can take HTML pages as input and display them graphically.

A hyperlink as you describe it is a graphical element such as you might find on a website. You can't have them in a text file, because a text file is just text. But you can instruct a web browser to display a hyperlink by writing

<a href="where/you/want/the/link/to/go">text of the link</a>

If you open a file containing that in a web browser, it will display the text as a link. Note that files containing HTML are conventionally called something.html to indicate their contents, and that there are a bunch of required tags in any HTML document (<html><head></head><body></body></html>).

这篇关于在python中创建超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆