在搜索引擎上搜过,未果
问题的详细描述:假设在桌面有一个“A.py”,当A.py被运行的时候会自动打开“B.py”(不在桌面,而是在其他路径,并且这个路径已知)。
实现效果类似于如下代码:
<span class="kn">import</span> <span class="nn">os</span> <span class="n">start_dire</span> <span class="o">=</span> <span class="s">r"E:\*.txt"</span> <span class="n">os</span><span class="o">.</span><span class="n">system</span><span class="p">(</span><span class="s">"explorer.exe </span><span class="si">%s</span><span class="s">"</span> <span class="o">%</span><span class="n">start_dire</span><span class="p">)</span>
<code class="language-text">system($^X, "another_script.pl");
</code>
先读.py的文件,然后使用eval函数执行.py的文件内容,或者用import
至少有两种方法,假定b.py在E盘的根目录:<code class="language-python"><span class="kn">import</span> <span class="nn">sys</span>
<span class="n">sys</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">'E:/'</span><span class="p">)</span>
<span class="kn">import</span> <span class="nn">b</span>
<span class="n">b</span><span class="o">.</span><span class="n">foo</span><span class="p">()</span>
</code>
把explorer.exe换成python.exe试试