Linked Questions

17 questions linked to/from Callable modules
12 votes
2 answers
69k views

I'm writing a module called foo that has many internal functions, but ultimately boils down to a single external function foo(). When using this module/function, I'd like to do import foo foo(...
user avatar
0 votes
0 answers
250 views

Considering a namespace package in python 3.7, how would I pass an argument to my package when I initialise it? my_package __init__.py I wish to be able to call my_package(arg). Thank you,
0 votes
2 answers
111 views

Apologies if this has been asked before, I'm not sure how to search for this. I'm trying to structure my module in a way that allows me to do this: import module module() How can I do this? My ...
nathancahill's user avatar
  • 10.9k
151 votes
9 answers
78k views

How can implement the equivalent of a __getattr__ on a class, on a module? Example When calling a function that does not exist in a module's statically defined attributes, I wish to create an ...
139 votes
8 answers
46k views

With python properties, I can make it such that obj.y calls a function rather than just returning a value. Is there a way to do this with modules? I have a case where I want module.y to call a ...
8 votes
5 answers
2k views

Can a python module have a __repr__? The idea would be to do something like: import mymodule print mymodule EDIT: precision: I mean a user-defined repr!
static_rtti's user avatar
13 votes
2 answers
5k views

Given a frame object, I need to get the corresponding module object. In other words, implement callers_module so this works: import sys from some_other_module import callers_module assert sys....
user avatar
10 votes
3 answers
350 views

I'm a minor contributor to a package where people are meant to do this (Foo.Bar.Bar is a class): >>> from Foo.Bar import Bar >>> s = Bar('a') Sometimes people do this by mistake (...
1 vote
1 answer
2k views

The documentation for __init__.py is quite hard to find. I can't find a place that explains all the things you can do in this file. The Python module documentation barely even mentions __init__.py nor ...
WobbaFetttttt's user avatar
0 votes
2 answers
1k views

I'm coming back to python and having trouble with import paths. Can someone explain the logic, or a better way of doing this? If I have a class called Sentence in structure like base.py models/...
dcsan's user avatar
  • 12.5k
-1 votes
1 answer
369 views

I do have the situation as follows: main.py moduleA.py moduleB.py moduleA contains main() function moduleB contains main() function I do in main: import moduleA, moduleB def main(): moduleA....
1 vote
3 answers
213 views

I have this module, wat.py import re import types import sys hello = "Hello World" class MyModule(types.ModuleType): def get_re(self): return re def get_hello(self): return ...
Eric's user avatar
  • 98.1k
1 vote
1 answer
378 views

Is it possible to make a module callable with parameters? I am trying to make a callable module on Python, following the question and its answers Callable modules, like so: foo.py import sys class ...
user avatar
1 vote
1 answer
182 views

I have a module with the structure: - mymodule - mymodule __init__.py core.py setup.py __init__.py contents: from .core import MyClass So now when I import my module I have to do: ...
xendi's user avatar
  • 2,562
-1 votes
1 answer
119 views

This is closely related to: Importing modules in Python - best practice , but the following case is not really discussed in details. If we have a module coordinates that defines one class ...
cglacet's user avatar
  • 11.4k

15 30 50 per page
1
2