如何从文本 block 中读取 Markdown 表并导入到同一 PowerShell 笔记本中代码块中的变量中?
尝试使用 PowerShell 导入
$b=Import-Csv -Path <> -Delimiter '|'
无法弄清楚如何指向 -Path
同一笔记本中文本 block 的参数。在 Azure Data Studio 中使用 .ipynb 文件。
最佳答案
我相信您正在寻找的功能是不可能的。作为解决方法,我建议首先将单元格 Markdown 存储为 Python 中的变量,然后使用该变量填充打印的 Markdown 单元格。这是一个例子。我相信它适用于任何基于 iPython 构建的笔记本:
#running this cell in your notebook will print the variable as Markdown
mymd = "# Some markdown"
from IPython.display import display, Markdown
display(Markdown(mymd))
更新:如果您担心表示多行 Markdown 太复杂,您有两个不错的选择。首先,使用三引号将换行符读取为字符串的一部分:
mymd = """
| First Header | Second Header |
| ------------- | ------------- |
| Content Cell | Content Cell |
| Content Cell | Content Cell |
"""
选项 2:将 Markdown 放入文件中并将其读取为字符串:
with open("somefile.md") as f:
mymd = f.read()
任一选项都会受益于记录良好且严格遵循的工作流程,但对于此用例来说效果很好。
关于python - 从同一笔记本导入表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60264332/