Las librerias de python se denominan modulos, definen funciones y/o clases que podemos importar en nuestro programa
Podemos importar definiciones individuales, por ejemplo aqui importamos la funcion ctime del modulo time que convierte en milisegundos desde el epoch unix a una fecha, o la funcion que da el tiempo local en la estructura definida en time
from time import ctime
ctime(1234455676)
'Thu Feb 12 17:21:16 2009'
from time import localtime
localtime()
time.struct_time(tm_year=2019, tm_mon=2, tm_mday=5, tm_hour=14, tm_min=20, tm_sec=57, tm_wday=1, tm_yday=36, tm_isdst=0)
Podemos asignar un alias a lo que importamos
from time import localtime as lt
lt()
time.struct_time(tm_year=2019, tm_mon=2, tm_mday=5, tm_hour=14, tm_min=20, tm_sec=58, tm_wday=1, tm_yday=36, tm_isdst=0)
Podemos importar todas las definiciones de un modulo y a partir de ahi podremos usarlas indicando el nombre del modulo al que pertenecen
import time
time.ctime(1278797213)
'Sat Jul 10 23:26:53 2010'
O podemos importar todas las definiciones de modulo indicando el nombre que usaremos para acceder a ellas, en este caso importamos la estructura heapq que permite usar las listas como un heap
import heapq as hp
a = []
hp.heappush(a, 1)
hp.heappush(a, 7)
hp.heappush(a, 3)
hp.heappush(a, -1)
a
[-1, 1, 3, 7]
hp.heappop(a)
-1
Python nos permite acceder a la informacion de los modulos a partir de ciertos atributos especiales, __dict__ da toda la informacion disponible
time.__dict__
{'__name__': 'time', '__doc__': 'This module provides various functions to manipulate time values.\n\nThere are two standard representations of time. One is the number\nof seconds since the Epoch, in UTC (a.k.a. GMT). It may be an integer\nor a floating point number (to represent fractions of seconds).\nThe Epoch is system-defined; on Unix, it is generally January 1st, 1970.\nThe actual value can be retrieved by calling gmtime(0).\n\nThe other representation is a tuple of 9 integers giving local time.\nThe tuple items are:\n year (including century, e.g. 1998)\n month (1-12)\n day (1-31)\n hours (0-23)\n minutes (0-59)\n seconds (0-59)\n weekday (0-6, Monday is 0)\n Julian day (day in the year, 1-366)\n DST (Daylight Savings Time) flag (-1, 0 or 1)\nIf the DST flag is 0, the time is given in the regular time zone;\nif it is 1, the time is given in the DST time zone;\nif it is -1, mktime() should guess based on the date and time.\n', '__package__': '', '__loader__': _frozen_importlib.BuiltinImporter, '__spec__': ModuleSpec(name='time', loader=<class '_frozen_importlib.BuiltinImporter'>, origin='built-in'), 'time': <function time.time>, 'clock': <function time.clock>, 'clock_gettime': <function time.clock_gettime>, 'clock_settime': <function time.clock_settime>, 'clock_getres': <function time.clock_getres>, 'sleep': <function time.sleep>, 'gmtime': <function time.gmtime>, 'localtime': <function time.localtime>, 'asctime': <function time.asctime>, 'ctime': <function time.ctime>, 'mktime': <function time.mktime>, 'strftime': <function time.strftime>, 'strptime': <function time.strptime>, 'tzset': <function time.tzset>, 'monotonic': <function time.monotonic>, 'process_time': <function time.process_time>, 'perf_counter': <function time.perf_counter>, 'get_clock_info': <function time.get_clock_info>, 'timezone': -3600, 'altzone': -7200, 'daylight': 1, 'tzname': ('CET', 'CEST'), 'CLOCK_REALTIME': 0, 'CLOCK_MONOTONIC': 1, 'CLOCK_MONOTONIC_RAW': 4, 'CLOCK_PROCESS_CPUTIME_ID': 2, 'CLOCK_THREAD_CPUTIME_ID': 3, '_STRUCT_TM_ITEMS': 11, 'struct_time': time.struct_time}
o solo la documentacion
time.__doc__
'This module provides various functions to manipulate time values.\n\nThere are two standard representations of time. One is the number\nof seconds since the Epoch, in UTC (a.k.a. GMT). It may be an integer\nor a floating point number (to represent fractions of seconds).\nThe Epoch is system-defined; on Unix, it is generally January 1st, 1970.\nThe actual value can be retrieved by calling gmtime(0).\n\nThe other representation is a tuple of 9 integers giving local time.\nThe tuple items are:\n year (including century, e.g. 1998)\n month (1-12)\n day (1-31)\n hours (0-23)\n minutes (0-59)\n seconds (0-59)\n weekday (0-6, Monday is 0)\n Julian day (day in the year, 1-366)\n DST (Daylight Savings Time) flag (-1, 0 or 1)\nIf the DST flag is 0, the time is given in the regular time zone;\nif it is 1, the time is given in the DST time zone;\nif it is -1, mktime() should guess based on the date and time.\n'
El atributo __all__ permite acceder a todas las definiciones del modulo (si esta definida)
hp.__all__
['heappush', 'heappop', 'heapify', 'heapreplace', 'merge', 'nlargest', 'nsmallest', 'heappushpop']