Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

165
Views
¿Es posible hacer que las importaciones dentro de `__init__.py` sean visibles para el comando python `help()`?

Supongamos que tengo un módulo:

mymodule/example.py :

 def add_one(number): return number + 1

Y mymodule/__init__.py :

 from .example import * foo = "FOO" def bar(): return 1

Ahora veo la función en la raíz de mymodule :

 >>> import mymodule >>> mymodule.add_one(3) 4 >>> mymodule.foo 'FOO'

Además, veo add_one importado a través de dir junto con el example :

 >>> dir(mymodule) ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', 'add_one', 'bar', 'example', 'foo']

Pero cuando help(mymodule) solo veo example , foo y bar , pero no add_one importado:

 Help on package mymodule: NAME mymodule PACKAGE CONTENTS example FUNCTIONS bar() DATA foo = 'FOO'

Pero puedo llamar a add_one() como la función raíz de mymodule . ¿Es posible verlo en la ayuda como función de root?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Desde el código fuente de ayuda () ( docmodule en pydoc.py )

 for key, value in inspect.getmembers(object, inspect.isroutine): # if __all__ exists, believe it. Otherwise use old heuristic. if (all is not None or inspect.isbuiltin(value) or inspect.getmodule(value) is object): if visiblename(key, all, object): funcs.append((key, value))

La parte importante es inspect.getmodule(value) is object) , aquí es donde se eliminan los valores que no son directamente parte del objeto en sí

Puedes agregar esta línea

 __all__ = ['bar', 'add_one', 'FOO']

a su archivo __init__.py , de esta manera la función de ayuda se asegurará de incluir estos objetos en la ayuda

Tenga en cuenta que si hace esto, todo lo que no esté incluido en esta lista no se incluirá.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!