diff --git a/Docs/assets/images/展示程序执行结果.jpg b/Docs/assets/images/展示程序执行结果.jpg new file mode 100644 index 0000000..e45416d Binary files /dev/null and b/Docs/assets/images/展示程序执行结果.jpg differ diff --git a/Docs/assets/images/添加Jupyter内核.jpg b/Docs/assets/images/添加Jupyter内核.jpg new file mode 100644 index 0000000..0233141 Binary files /dev/null and b/Docs/assets/images/添加Jupyter内核.jpg differ diff --git a/Docs/多语言笔记.1.1.入门说明.ipynb b/Docs/多语言笔记.1.1.入门说明.ipynb index e6d3fb3..d408f52 100644 --- a/Docs/多语言笔记.1.1.入门说明.ipynb +++ b/Docs/多语言笔记.1.1.入门说明.ipynb @@ -30,7 +30,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -428,7 +428,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": { "dotnet_interactive": { "language": "csharp" @@ -437,7 +437,16 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "ename": "Error", + "evalue": "(1,8): error DNI103: Unrecognized parameter name '-h'", + "output_type": "error", + "traceback": [ + "(1,8): error DNI103: Unrecognized parameter name '-h'" + ] + } + ], "source": [ "#!time -h" ] diff --git a/Docs/多语言笔记.1.2.显示程序执行结果.ipynb b/Docs/多语言笔记.1.2.显示程序执行结果.ipynb index a41c194..e2f14b2 100644 --- a/Docs/多语言笔记.1.2.显示程序执行结果.ipynb +++ b/Docs/多语言笔记.1.2.显示程序执行结果.ipynb @@ -131,7 +131,7 @@ { "data": { "text/html": [ - "
{ Name = 张三, Age = 33, Adress = 河南周口 }
Name张三
Age
33
Adress河南周口
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "//获取运行时信息\n", + "{\n", + " //当前进程信息\n", + " System.Diagnostics.Process.GetCurrentProcess().Display();\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "3e5b5a8d", + "metadata": {}, + "source": [ + "## 路径工具:显示 `Polyglot Notebooks`执行时的各种路径" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6393976b", + "metadata": { + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Application.ExecutablePath => Application.ExecutablePath 只适用于WinForm\r\n", + "Application.StartupPath => Application.StartupPath 只适用于WinForm\r\n", + "AppContext.BaseDirectory => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\\r\n", + "AppDomain.CurrentDomain.BaseDirectory => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\\r\n", + "AppDomain.CurrentDomain.SetupInformation.ApplicationBase => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\\r\n", + "Process.GetCurrentProcess().MainModule.FileName => C:\\Program Files\\dotnet\\dotnet.exe\r\n", + "Environment.CurrentDirectory => c:\\Users\\ruyu\\Desktop\\多语言笔记学习\\Docs\r\n", + "Environment.GetCommandLineArgs()[0] => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\Microsoft.DotNet.Interactive.App.dll\r\n", + "Directory.GetCurrentDirectory => c:\\Users\\ruyu\\Desktop\\多语言笔记学习\\Docs\r\n", + "Assembly.GetExecutingAssembly().Location => \r\n", + "Assembly.GetEntryAssembly().Location => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\Microsoft.DotNet.Interactive.App.dll\r\n", + "Assembly.GetExecutingAssembly().CodeBase => file:///C:/Program Files/dotnet/shared/Microsoft.NETCore.App/9.0.4/System.Private.CoreLib.dll\r\n", + "Assembly.GetEntryAssembly().CodeBase => file:///C:/Users/ruyu/.nuget/packages/microsoft.dotnet-interactive/1.0.617701/tools/net9.0/any/Microsoft.DotNet.Interactive.App.dll\r\n", + "\r\n" + ] + } + ], + "source": [ + "using System;\n", + "using System.IO;\n", + "using System.Threading;\n", + "using System.Threading.Tasks;\n", + "using System.Diagnostics;\n", + "using System.Reflection;\n", + "\n", + "//查看各种程序路径\n", + "{\n", + " var pathDic = new Dictionary() \n", + " {\n", + " //当前运行的exe的完整路径,包含exe文件名,只用于WinForm\n", + " {\"Application.ExecutablePath\",(\"程序集基完整路径(仅WinForm)\", \"Application.ExecutablePath 只适用于WinForm\") },\n", + "\n", + " //程序的启动路径:只用于WinForm\n", + " {\"Application.StartupPath\",(\"程序集启动路径(仅WinForm)\", \"Application.StartupPath 只适用于WinForm\") },\n", + "\n", + " //当前执行的exe或启动项目的路径,通过AppContext\n", + " {\"AppContext.BaseDirectory\",(\"执行或启动路径\", AppContext.BaseDirectory) }, \n", + "\n", + " //当前执行的exe的目录,不包含exe名,使用AppDomain\n", + " {\"AppDomain.CurrentDomain.BaseDirectory\",(\"程序集解析程序用于探测程序集的基目录\", AppDomain.CurrentDomain.BaseDirectory) }, \n", + "\n", + " //程序安装或启动基目录 包含应用程序的目录的名称\n", + " {\"AppDomain.CurrentDomain.SetupInformation.ApplicationBase\",(\"程序安装或启动基目录\", AppDomain.CurrentDomain.SetupInformation.ApplicationBase) }, \n", + "\n", + " //当前进程的主模块路径,包含exe名\n", + " {\"Process.GetCurrentProcess().MainModule.FileName\",(\"当前进程的主模块路径\", Process.GetCurrentProcess()?.MainModule?.FileName) }, \n", + "\n", + " //环境变量:用户当前工作目录的完整限定路径\n", + " {\"Environment.CurrentDirectory\",(\"用户当前工作目录的完整限定路径\", Environment.CurrentDirectory) }, \n", + "\n", + " //环境变量:当前exe的完整路径,包含exe名,通过命令行参数\n", + " {\"Environment.GetCommandLineArgs()[0]\",(\"当前exe的完整路径\", Environment.GetCommandLineArgs()[0]) }, \n", + "\n", + " //当前工作目录的路径(可变)\n", + " {\"Directory.GetCurrentDirectory\",(\"当前工作目录的路径(可变)\", Directory.GetCurrentDirectory()) },\n", + " \n", + " //当前Assembly的加载路径,包含dll或exe名\n", + " {\"Assembly.GetExecutingAssembly().Location\",(\"当前Assembly的加载路径\", Assembly.GetExecutingAssembly().Location) },\n", + "\n", + " //入口程序集的路径\n", + " {\"Assembly.GetEntryAssembly().Location\",(\"入口程序集的路径\", Assembly.GetEntryAssembly()?.Location) },\n", + "\n", + " //已过时:当前程序集的CodeBase路径,可能为file URI格式\n", + " {\"Assembly.GetExecutingAssembly().CodeBase\",(\"当前程序集的CodeBase路径\", Assembly.GetExecutingAssembly()?.CodeBase) },\n", + "\n", + " //已过时:入口程序集的CodeBase路径,可能为file URI格式\n", + " {\"Assembly.GetEntryAssembly().CodeBase\",(\"入口程序集的CodeBase路径\", Assembly.GetEntryAssembly()?.CodeBase) },\n", + " };\n", + "\n", + " var message = string.Empty;\n", + " foreach (var item in pathDic)\n", + " {\n", + " message += $\"{item.Key} => {item.Value.path}{Environment.NewLine}\";\n", + " }\n", + "\n", + " Console.WriteLine(message);\n", + "}" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "languageName": "csharp", + "name": "csharp" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Docs/多语言笔记.9.2.使用python内核.ipynb b/Docs/多语言笔记.9.2.使用python内核.ipynb index e208211..7b36b2a 100644 --- a/Docs/多语言笔记.9.2.使用python内核.ipynb +++ b/Docs/多语言笔记.9.2.使用python内核.ipynb @@ -124,16 +124,35 @@ "kernelName": "csharp" } }, - "outputs": [], + "outputs": [ + { + "data": { + "text/markdown": [ + "The `#!connect jupyter` feature is in preview. Please report any feedback or issues at https://github.com/dotnet/interactive/issues/new/choose." + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "Kernel added: #!pythonkernel2" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "using Microsoft.DotNet.Interactive;\n", "using Microsoft.DotNet.Interactive.Commands;\n", "\n", "//引入Python内核:使用C# 执行引入语句\n", - "if(Kernel.Root.FindKernelByName(\"pythonkernel\") == null)\n", + "if(Kernel.Root.FindKernelByName(\"pythonkernel2\") == null)\n", "{\n", " //Console.WriteLine(\"正在导入Python内核....\");\n", - " var importPythonkernel = \"#!connect jupyter --kernel-name pythonkernel --kernel-spec python3\";\n", + " var importPythonkernel = \"#!connect jupyter --kernel-name pythonkernel2 --kernel-spec python3\";\n", " await Kernel.Root.SendAsync(new SubmitCode( importPythonkernel, \"csharp\"));\n", " //Console.WriteLine(\"Python内核导入完成\");\n", "}\n", @@ -177,7 +196,7 @@ ], "source": [ "# 明确指定内核:优先级高于 \"单元格选择的内核\"\n", - "#!pythonkernel\n", + "#!pythonkernel2\n", "\n", "print(\"你好,我是 Ployglot Notebooks 使用 Python语言内核,打印的内容!\")" ] @@ -187,7 +206,7 @@ "execution_count": 4, "metadata": { "polyglot_notebook": { - "kernelName": "pythonkernel" + "kernelName": "pythonkernel2" } }, "outputs": [ @@ -203,17 +222,6 @@ "# 右下方选择 内核\n", "print(\"右下方选择Python内核\");" ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "polyglot_notebook": { - "kernelName": "pythonkernel" - } - }, - "outputs": [], - "source": [] } ], "metadata": {