<tfoot id='DehjE'></tfoot>
        <bdo id='DehjE'></bdo><ul id='DehjE'></ul>
        <legend id='DehjE'><style id='DehjE'><dir id='DehjE'><q id='DehjE'></q></dir></style></legend>
      1. <small id='DehjE'></small><noframes id='DehjE'>

        <i id='DehjE'><tr id='DehjE'><dt id='DehjE'><q id='DehjE'><span id='DehjE'><b id='DehjE'><form id='DehjE'><ins id='DehjE'></ins><ul id='DehjE'></ul><sub id='DehjE'></sub></form><legend id='DehjE'></legend><bdo id='DehjE'><pre id='DehjE'><center id='DehjE'></center></pre></bdo></b><th id='DehjE'></th></span></q></dt></tr></i><div id='DehjE'><tfoot id='DehjE'></tfoot><dl id='DehjE'><fieldset id='DehjE'></fieldset></dl></div>

        Python 导入:导入没有 .py 扩展名的模块?

        时间:2023-11-08
          <bdo id='W2oIt'></bdo><ul id='W2oIt'></ul>
          <tfoot id='W2oIt'></tfoot>

                  <tbody id='W2oIt'></tbody>

                  <small id='W2oIt'></small><noframes id='W2oIt'>

                  <legend id='W2oIt'><style id='W2oIt'><dir id='W2oIt'><q id='W2oIt'></q></dir></style></legend>
                  <i id='W2oIt'><tr id='W2oIt'><dt id='W2oIt'><q id='W2oIt'><span id='W2oIt'><b id='W2oIt'><form id='W2oIt'><ins id='W2oIt'></ins><ul id='W2oIt'></ul><sub id='W2oIt'></sub></form><legend id='W2oIt'></legend><bdo id='W2oIt'><pre id='W2oIt'><center id='W2oIt'></center></pre></bdo></b><th id='W2oIt'></th></span></q></dt></tr></i><div id='W2oIt'><tfoot id='W2oIt'></tfoot><dl id='W2oIt'><fieldset id='W2oIt'></fieldset></dl></div>
                • 本文介绍了Python 导入:导入没有 .py 扩展名的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  In a Python system for which I develop, we usually have this module structure.

                  mymodule/
                  mymodule/mymodule/feature.py
                  mymodule/test/feature.py
                  

                  This allows our little testing framework to easily import test/feature.py and run unit tests. However, we now have the need for some shell scripts (which are written in Python):

                  mymodule/
                  mymodule/scripts/yetanotherfeature.py
                  mymodule/test/yetanotherfeature.py
                  

                  yetanotherfeature.py is installed by the module Debian package into /usr/bin. But we obviously don't want the .py extension there. So, in order for the test framework to still be able to import the module I have to do this symbolic link thingie:

                  mymodule/
                  mymodule/scripts/yetanotherfeature
                  mymodule/scripts/yetanotherfeature.py @ -> mymodule/scripts/yetanotherfeature
                  mymodule/test/yetanotherfeature.py
                  

                  Is it possible to import a module by filename in Python, or can you think of a more elegant solution for this?

                  解决方案

                  You could most likely use some tricker by using import hooks, I wouldn't recommend it though. On the other hand I would also probably do it the other way around , have your .py scripts somewhere, and make '.py'less symbolic links to the .py files. So your library could be anywhere and you can run the test from within by importing it normall (since it has the py extension), and then /usr/bin/yetanotherfeature points to it, so you can run it without the py.

                  Edit: Nevermind this (at least the hooks part), the import imp solution looks very good to me :)

                  这篇关于Python 导入:导入没有 .py 扩展名的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:matplotlib 数据的 cx_freeze 错误 下一篇:configparser 在 Python 3.4 中不工作,NoSectionError 但在 PyCharm 中工作

                  相关文章

                  <small id='fhDHK'></small><noframes id='fhDHK'>

                    <bdo id='fhDHK'></bdo><ul id='fhDHK'></ul>

                    1. <i id='fhDHK'><tr id='fhDHK'><dt id='fhDHK'><q id='fhDHK'><span id='fhDHK'><b id='fhDHK'><form id='fhDHK'><ins id='fhDHK'></ins><ul id='fhDHK'></ul><sub id='fhDHK'></sub></form><legend id='fhDHK'></legend><bdo id='fhDHK'><pre id='fhDHK'><center id='fhDHK'></center></pre></bdo></b><th id='fhDHK'></th></span></q></dt></tr></i><div id='fhDHK'><tfoot id='fhDHK'></tfoot><dl id='fhDHK'><fieldset id='fhDHK'></fieldset></dl></div>
                    2. <tfoot id='fhDHK'></tfoot>
                      <legend id='fhDHK'><style id='fhDHK'><dir id='fhDHK'><q id='fhDHK'></q></dir></style></legend>