如何在iPython标记的href链接中插入变量

如何在iPython标记的href链接中插入变量,python,ipython,ipython-notebook,jupyter-notebook,ipython-magic,Python,Ipython,Ipython Notebook,Jupyter Notebook,Ipython Magic,我正在使用Ipython笔记本2 我在变量中有一个文件名,它动态计算位于当前目录中的文件的位置和文件名,我想在标记中插入该变量以下载它 代码如下: 然后使用我的标记下载文件: 但是它没有按预期工作您可以使用IPython.display模块中的工具显示HTML: HTML是将HTML表示为文本的对象 display是一种显示对象的功能(如print,但用于富媒体对象) 例如: from IPython.display import display, HTML # create a st

我正在使用Ipython笔记本2

我在变量中有一个文件名,它动态计算位于当前目录中的文件的位置和文件名,我想在标记中插入该变量以下载它

代码如下:

然后使用我的标记下载文件:



但是它没有按预期工作

您可以使用
IPython.display
模块中的工具显示HTML:

  • HTML
    是将HTML表示为文本的对象
  • display
    是一种显示对象的功能(如
    print
    ,但用于富媒体对象)
例如:

from IPython.display import display, HTML

# create a string template for the HTML snippet
link_t = "<a href='{href}'> Click here to download the result</a>"

result_file = "Revenue_per_city" + start_date + "_" + end_date + ".xlsx"

# create HTML object, using the string template
html = HTML(link_t.format(href=result_file))

# display the HTML object to put the link on the page:
display(html)
从IPython.display导入显示,HTML
#为HTML代码段创建字符串模板
link_t=“”
结果文件=“每个城市的收入”+开始日期+“\u”+结束日期+”.xlsx”
#使用字符串模板创建HTML对象
html=html(链接格式(href=result\u文件))
#显示HTML对象以在页面上放置链接:
显示(html)

您可以使用
IPython.display
模块中的工具显示HTML:

  • HTML
    是将HTML表示为文本的对象
  • display
    是一种显示对象的功能(如
    print
    ,但用于富媒体对象)
例如:

from IPython.display import display, HTML

# create a string template for the HTML snippet
link_t = "<a href='{href}'> Click here to download the result</a>"

result_file = "Revenue_per_city" + start_date + "_" + end_date + ".xlsx"

# create HTML object, using the string template
html = HTML(link_t.format(href=result_file))

# display the HTML object to put the link on the page:
display(html)
从IPython.display导入显示,HTML
#为HTML代码段创建字符串模板
link_t=“”
结果文件=“每个城市的收入”+开始日期+“\u”+结束日期+”.xlsx”
#使用字符串模板创建HTML对象
html=html(链接格式(href=result\u文件))
#显示HTML对象以在页面上放置链接:
显示(html)

有一个输入错误。代码中
href
的拼写。@JasonEstibeiro感谢您的更正,但这不是问题所在:)有一个拼写错误。代码中
href
的拼写。@JasonEstibeiro感谢您的更正,但这不是问题所在:)
from IPython.display import display, HTML

# create a string template for the HTML snippet
link_t = "<a href='{href}'> Click here to download the result</a>"

result_file = "Revenue_per_city" + start_date + "_" + end_date + ".xlsx"

# create HTML object, using the string template
html = HTML(link_t.format(href=result_file))

# display the HTML object to put the link on the page:
display(html)