<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 扩展名的模块?

        Python imports: importing a module without .py extension?(Python 导入:导入没有 .py 扩展名的模块?)
          <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 扩展名的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)

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

                    <tbody id='fhDHK'></tbody>

                    <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>
                        • <tfoot id='fhDHK'></tfoot>
                          <legend id='fhDHK'><style id='fhDHK'><dir id='fhDHK'><q id='fhDHK'></q></dir></style></legend>