最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

class - Correct way to import Python classes with Git submodules? - Stack Overflow

programmeradmin3浏览0评论

I have a git repo, core, which I would like to use as a submodule within other git repos, e.g. example. core contains python files within which are classes that I would like to import into example. I have a set up which is working, however, now if I try to use core as a standalone repository I get an import error.

The file structure of core looks like:

core
    __init__.py
    myfile.py
    myotherfile.py
    mynotebook.ipynb

Where myfile.py looks like:

from .myotherfile import MyOtherFileClass
class MyFileClass():
    def __init__():
         mofc = MyOtherFileClass()

And myotherfile.py looks like:

class MyOtherFileClass():
    def __init__():
        #dostuff

The file structure of example looks like:

example
    > core (submodule)
    examplenotebook.ipynb

Where examplenotebook.ipynb contains:

from core.myfile import MyFileClass
mfc = MyFileClass()

The above all seems to be working ok using the github submodule feature.

mynotebook.ipynb looks like:

from myfile import MyFileClass

This returns an error at from .myotherfile import MyOtherFileClass within myfile. The error is ImportError: attempted relative import with no known parent package.

Have I set this up in the right way? Is this an acceptable way to work with submodules?

发布评论

评论列表(0)

  1. 暂无评论