Bonjour,
Après avoir importer un fichier dans l'interpréteur interactif, quelle commande faut-il taper pour obtenir la liste des fonctions présentes dans ce fichier ainsi que leur documentation ?
Merci pour le renseignement et à bientôt
Version imprimable
Bonjour,
Après avoir importer un fichier dans l'interpréteur interactif, quelle commande faut-il taper pour obtenir la liste des fonctions présentes dans ce fichier ainsi que leur documentation ?
Merci pour le renseignement et à bientôt
:salut:
De manière basique tu peux avoir les infos d'une fonction particulière avec la commande help('nom de la fonction python à chercher').
Pour ton cas je te dirai d'avoir un fichier .pythonrc ou tu utiliseras les fonctions readline et rlcompleter
Voici un exemple de fichier .pythonrc qui me permet d'utiliser la tabulation pour completer automatiquement ( Pas de doc dispo, juste l'autocompletion.... pour la doc c'est help())
PS: Tu dois definir ta variable d'environnement $PYTHONSTARTUPCode:
1
2
3
4
5
6
7
8
9
10 import sys import os import readline, rlcompleter import atexit import pprint import datetime import re readline.parse_and_bind("tab: complete")
Salut,
Essaye ceci:
Code:
1
2
3
4
5
6
7
8 from spam import Spam funcs = Spam.__dict__ for f in funcs: print(funcs[f]) print(funcs[f].__doc__) print('/n')
Salut,
La méthode documentée est la fonction "dir":
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 >>> dir(sys) ['__displayhook__', '__doc__', '__egginsert', '__excepthook__', '__interactiveho ok__', '__loader__', '__name__', '__package__', '__plen', '__spec__', '__stderr_ _', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_debugma llocstats', '_getframe', '_home', '_mercurial', '_xoptions', 'api_version', 'arg v', 'base_exec_prefix', 'base_prefix', 'builtin_module_names', 'byteorder', 'cal l_tracing', 'callstats', 'copyright', 'displayhook', 'dllhandle', 'dont_write_by tecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'getallocatedblocks', 'getcheckinterval', 'ge tdefaultencoding', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', ' getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'getwindowsversion', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'last_traceb ack', 'last_type', 'last_value', 'maxsize', 'maxunicode', 'meta_path', 'modules' , 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'ps1', 'ps2 ', 'setcheckinterval', 'setprofile', 'setrecursionlimit', 'setswitchinterval', ' settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'version', 'version_info' , 'warnoptions', 'winver']
Cependant les "attributs"/"noms" d'un module ne sont pas tous fonctions (i.e. il faut peut être "tester" les objets associés à ces "noms" pour obtenir des résultats satisfaisants).Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 >>> help(dir) Help on built-in function dir in module builtins: dir(...) dir([object]) -> list of strings If called without an argument, return the names in the current scope. Else, return an alphabetized list of names comprising (some of) the attributes of the given object, and of attributes reachable from it. If the object supplies a method named __dir__, it will be used; otherwise the default dir() logic is used and returns: for a module object: the module's attributes. for a class object: its attributes, and recursively the attributes of its bases. for any other object: its attributes, its class's attributes, and recursively the attributes of its class's base classes. >>>
note: et de fait, on obtient une liste de noms que le module/package veut bien laisser "voir".
- W