diff --git a/examples/user_guide/k230_simulate-EN.ipynb b/examples/user_guide/k230_simulate-EN.ipynb index 309f8cd830..a8630394df 100644 --- a/examples/user_guide/k230_simulate-EN.ipynb +++ b/examples/user_guide/k230_simulate-EN.ipynb @@ -57,15 +57,17 @@ "\n", "result = subprocess.run([\"pip\", \"show\", \"nncase\"], capture_output=True)\n", "\n", + "split_flag = \"\\n\"\n", "if sys.platform == \"win32\":\n", - " location = result.stdout.decode().split(\"\\r\\n\")[7].split(\": \")[1]\n", - "else:\n", - " location = result.stdout.decode().split(\"\\n\")[7].split(\": \")[1]\n", + " split_flag = \"\\r\\n\"\n", + "\n", + "location_s = [i for i in result.stdout.decode().split(split_flag) if i.startswith(\"Location:\")]\n", + "location = location_s[0].split(\": \")[1]\n", "\n", "if \"PATH\" in os.environ:\n", " os.environ[\"PATH\"] += os.pathsep + location\n", "else:\n", - " os.environ[\"PATH\"] = location" + " os.environ[\"PATH\"] = location\n" ] }, { diff --git a/examples/user_guide/k230_simulate-ZH.ipynb b/examples/user_guide/k230_simulate-ZH.ipynb index e5a9a55d86..e9b9dc5329 100644 --- a/examples/user_guide/k230_simulate-ZH.ipynb +++ b/examples/user_guide/k230_simulate-ZH.ipynb @@ -57,10 +57,12 @@ "\n", "result = subprocess.run([\"pip\", \"show\", \"nncase\"], capture_output=True)\n", "\n", + "split_flag = \"\\n\"\n", "if sys.platform == \"win32\":\n", - " location = result.stdout.decode().split(\"\\r\\n\")[7].split(\": \")[1]\n", - "else:\n", - " location = result.stdout.decode().split(\"\\n\")[7].split(\": \")[1]\n", + " split_flag = \"\\r\\n\"\n", + " \n", + "location_s = [i for i in result.stdout.decode().split(split_flag) if i.startswith(\"Location:\")]\n", + "location = location_s[0].split(\": \")[1]\n", "\n", "if \"PATH\" in os.environ:\n", " os.environ[\"PATH\"] += os.pathsep + location\n",