python - Import a module into a module, can't explain what i'm trying to do -
so, following example. here's module (called feedy.py) in let's say, core directory:
import feedparser feed = feedparser.parse("http://site.com/feed") [...]
a bad example, anyway: problem in main script (parent dir), have do
import feedparser
as as
from core import feedy
however, there way eliminate need import feedparser, since it's imported in feedy.py?
hope understand, fike.
in principle, yes. however, it's not idea.
when import
module, declare local variable reference module. in feedy
have object called feedparser
, happens module feedparser
, although @ time reassign other python object.
when import feedy
, can refer of feedy
's exported variables feedy.name
. in case, feedy.feedparser
module feedparser
.
however, if change way feedy
implemented, doesn't import (or export) feedparser
, break main script. in general don't want export have defined, although it's fine quick hack.
Comments
Post a Comment