Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
standard library modules
#1
where is located stored python standard library modules

I want to see the code
Reply
#2
Look at The Python Standard Library.
If eg go into calendar see link at top Source code: Lib/calendar.py

Do own exploring in interactive shell,better shell make it easier ptpython | IPython.
>>> import calendar
>>> 
>>> # Placement of source code 
>>> calendar.__file__
'C:\\Python37\\Lib\\calendar.py'
>>> 
>>> # All function\methods
>>> dir(calendar)
['Calendar',
 'EPOCH',
 'FRIDAY',
 'February',
 'HTMLCalendar',
 'IllegalMonthError',
 'IllegalWeekdayError',
 'January',
 'LocaleHTMLCalendar',
 'LocaleTextCalendar',
 'MONDAY',
 'SATURDAY',
 'SUNDAY',
 'THURSDAY',
 'TUESDAY',
 'TextCalendar',
 'WEDNESDAY',
 '_EPOCH_ORD',
 '__all__',
 '__builtins__',
 '__cached__',
 '__doc__',
 '__file__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 '_colwidth',
 '_locale',
 '_localized_day',
 '_localized_month',
 '_spacing',
 'c',
 'calendar',
 'datetime',
 'day_abbr',
 'day_name',
 'different_locale',
 'error',
 'firstweekday',
 'format',
 'formatstring',
 'isleap',
 'leapdays',
 'main',
 'mdays',
 'month',
 'month_abbr',
 'month_name',
 'monthcalendar',
 'monthlen',
 'monthrange',
 'nextmonth',
 'prcal',
 'prevmonth',
 'prmonth',
 'prweek',
 'repeat',
 'setfirstweekday',
 'sys',
 'timegm',
 'week',
 'weekday',
 'weekheader']

>>> print(calendar.calendar(2020))
                                  2020

      January                   February                   March
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
       1  2  3  4  5                      1  2                         1
 6  7  8  9 10 11 12       3  4  5  6  7  8  9       2  3  4  5  6  7  8
13 14 15 16 17 18 19      10 11 12 13 14 15 16       9 10 11 12 13 14 15
20 21 22 23 24 25 26      17 18 19 20 21 22 23      16 17 18 19 20 21 22
27 28 29 30 31            24 25 26 27 28 29         23 24 25 26 27 28 29
                                                    30 31

       April                      May                       June
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
       1  2  3  4  5                   1  2  3       1  2  3  4  5  6  7
 6  7  8  9 10 11 12       4  5  6  7  8  9 10       8  9 10 11 12 13 14
13 14 15 16 17 18 19      11 12 13 14 15 16 17      15 16 17 18 19 20 21
20 21 22 23 24 25 26      18 19 20 21 22 23 24      22 23 24 25 26 27 28
27 28 29 30               25 26 27 28 29 30 31      29 30

        July                     August                  September
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
       1  2  3  4  5                      1  2          1  2  3  4  5  6
 6  7  8  9 10 11 12       3  4  5  6  7  8  9       7  8  9 10 11 12 13
13 14 15 16 17 18 19      10 11 12 13 14 15 16      14 15 16 17 18 19 20
20 21 22 23 24 25 26      17 18 19 20 21 22 23      21 22 23 24 25 26 27
27 28 29 30 31            24 25 26 27 28 29 30      28 29 30
                          31

      October                   November                  December
Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su      Mo Tu We Th Fr Sa Su
          1  2  3  4                         1          1  2  3  4  5  6
 5  6  7  8  9 10 11       2  3  4  5  6  7  8       7  8  9 10 11 12 13
12 13 14 15 16 17 18       9 10 11 12 13 14 15      14 15 16 17 18 19 20
19 20 21 22 23 24 25      16 17 18 19 20 21 22      21 22 23 24 25 26 27
26 27 28 29 30 31         23 24 25 26 27 28 29      28 29 30 31
                          30
If have editor like VS Code , VS Code from start .
That has IntelliSense can go from any imported function\methods (Ctrl+left mouse) directly to Source code used.
Reply
#3
You can also look at the value of sys.path, which tells you where Python is looking for modules. On my Linux machine, that gives

Output:
>>> import sys >>> sys.path ['', '/usr/lib/python38.zip', '/usr/lib64/python3.8', '/usr/lib64/python3.8/lib-dynload', '/usr/lib64/python3.8/site-packages', '/usr/lib64/python3.8/_import_failed', '/usr/lib/python3.8/site-packages']
On my system, the modules are in /usr/lib64/python3.8.
Reply
#4
for example I want to see the math module and functions from it and source code from every function
Reply
#5
There are no direct link to source code as is written in C.
Code is on GitHub if want to look mathmodule.c
In interactive shell it work the same.
>>> import math
>>> 
>>> dir(math)
['__doc__',
 '__loader__',
 '__name__',
 '__package__',
 '__spec__',
 'acos',
 'acosh',
 'asin',
 'asinh',
 'atan',
 'atan2',
 'atanh',
 'ceil',
 'copysign',
 'cos',
 'cosh',
 'degrees',
 'e',
 'erf',
 'erfc',
 'exp',
 'expm1',
 'fabs',
 'factorial',
 'floor',
 'fmod',
 'frexp',
 'fsum',
 'gamma',
 'gcd',
 'hypot',
 'inf',
 'isclose',
 'isfinite',
 'isinf',
 'isnan',
 'ldexp',
 'lgamma',
 'log',
 'log10',
 'log1p',
 'log2',
 'modf',
 'nan',
 'pi',
 'pow',
 'radians',
 'remainder',
 'sin',
 'sinh',
 'sqrt',
 'tan',
 'tanh',
 'tau',
 'trunc']
>>> 
>>> math.asin.__doc__
'Return the arc sine (measured in radians) of x.'

>>> help(math.sqrt)
Help on built-in function sqrt in module math:

sqrt(x, /)
    Return the square root of x.
With pdir2 it look like this.
[Image: BoDGre.png]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python standard way of importing library mg24 1 918 Nov-15-2022, 01:41 AM
Last Post: deanhystad
  Winsorized Mean and Standard Deviation Wheeliam 0 1,830 Jul-11-2020, 05:27 PM
Last Post: Wheeliam
  Is there a standard for autocommit In PEP 249 zatlas1 10 5,295 Feb-06-2019, 04:56 PM
Last Post: buran
  Graphics and standard deviation rocioaraneda 3 2,740 Jan-09-2019, 10:53 PM
Last Post: micseydel
  standard data types rombertus 3 63,597 Dec-23-2018, 08:52 PM
Last Post: rombertus
  How to know modules contained by python3 library sylas 3 5,206 Sep-04-2018, 01:40 PM
Last Post: sylas
  Join the Python Standard Library to my project sylas 1 2,213 May-16-2018, 05:59 AM
Last Post: buran
  Do you know how to import Python Standard Library sylas 30 14,258 Jan-26-2018, 01:32 PM
Last Post: metulburr
  Modules issue, pip3 download modules only to pyhton3.5.2 not the latest 3.6.1 bmohanraj91 6 8,474 May-25-2017, 08:15 AM
Last Post: wavic
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,820 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020