我正在使用python 2.7,并且正在构建一个包含许多子目录的模块。结构看起来像这样:
>>> import mainmodule
>>> mainmodule.func(do_some_stuff)
现在导入i时,而不是这样:
var companySchema = new mongoose.Schema({
companyName: {
type: String,
required: true
},
estimatedAnnualEarnings: {
type: Number,
required: true
},
companyChildren: [{type: mongoose.Schema.Types.ObjectId, ref: 'Company'}],
companyType: {type: String, enum: ['Main', 'Subsidiary']}
})
module.exports = mongoose.model('Company', companySchema);
我想要这个:
router.get('/companies', function(req, res) {
Company.find({companyType: 'Main'}).populate({path: 'companyChildren'}).exec(function(err, list) {
if(err) {
console.log(err);
} else {
res.send(list);
}
})
});
提前致谢!
答案 0 :(得分:0)
然后,您应该在主模块__init__.py
中导入并公开您的功能:
from .submodule.somefunction import func