読者です 読者をやめる 読者になる 読者になる

pythonのソースコードを調べる

179のファイルがどのフォルダーに分布しているのか調べた。

import glob
import os

c_file_list = ["_bisectmodule.c","_codecsmodule.c","_collectionsmodule.c","_csv.c",
"_functoolsmodule.c","_heapqmodule.c","_json.c","_localemodule.c",
"_lsprof.c","_math.c","_pickle.c","_randommodule.c","_sre.c","_stat.c",
"_struct.c","_weakref.c","arraymodule.c","atexitmodule.c","audioop.c",
"binascii.c","cmathmodule.c","_datetimemodule.c","errnomodule.c",
"faulthandler.c","gcmodule.c","hashtable.c","itertoolsmodule.c",
"main.c","mathmodule.c","md5module.c","mmapmodule.c","_opcode.c",
"_operator.c","parsermodule.c","posixmodule.c","rotatingtree.c",
"sha1module.c","sha256module.c","sha512module.c","signalmodule.c",
"symtablemodule.c","_threadmodule.c","_tracemalloc.c","timemodule.c",
"xxsubtype.c","zipimport.c","zlibmodule.c","fileio.c","bytesio.c",
"stringio.c","bufferedio.c","iobase.c","textio.c","_iomodule.c","adler32.c",
"compress.c","crc32.c","deflate.c","infback.c","inffast.c","inflate.c","inftrees.c",
"trees.c","uncompr.c","zutil.c","_codecs_cn.c","_codecs_hk.c","_codecs_iso2022.c",
"_codecs_jp.c","_codecs_kr.c","_codecs_tw.c","multibytecodec.c","_winapi.c",
"abstract.c","accu.c","boolobject.c","bytes_methods.c","bytearrayobject.c",
"bytesobject.c","capsule.c","cellobject.c","classobject.c","codeobject.c",
"complexobject.c","descrobject.c","dictobject.c","enumobject.c","exceptions.c",
"fileobject.c","floatobject.c","frameobject.c","funcobject.c","genobject.c",
"iterobject.c","listobject.c","longobject.c","memoryobject.c","methodobject.c",
"moduleobject.c","namespaceobject.c","object.c","obmalloc.c","odictobject.c",
"rangeobject.c","setobject.c","sliceobject.c","structseq.c","tupleobject.c",
"typeobject.c","unicodectype.c","unicodeobject.c","weakrefobject.c",
"acceler.c","bitset.c","firstsets.c","grammar.c","grammar1.c","listnode.c",
"metagrammar.c","myreadline.c","node.c","parser.c","parsetok.c","tokenizer.c",
"invalid_parameter_handler.c","winreg.c","config.c","getpathp.c","msvcrtmodule.c",
"pyhash.c","random.c","_warnings.c","asdl.c","ast.c","bltinmodule.c","ceval.c",
"codecs.c","compile.c","dynamic_annotations.c","dynload_win.c","errors.c",
"fileutils.c","formatter_unicode.c","frozen.c","future.c","getargs.c",
"getcompiler.c","getcopyright.c","getopt.c","getplatform.c","getversion.c",
"graminit.c","import.c","importdl.c","marshal.c","modsupport.c","mysnprintf.c",
"mystrtoul.c","peephole.c","pyarena.c","pyctype.c","pyfpe.c","pylifecycle.c",
"pymath.c","pytime.c","pystate.c","pystrcmp.c","pystrhex.c","pystrtod.c","dtoa.c",
"Python-ast.c","pythonrun.c","structmember.c","symtable.c","sysmodule.c",
"thread.c","traceback.c","dl_nt.c","getbuildinfo.c"]
path_name = []
file_name = []
dir_name = []
dir_count = dict(zip(['Modules\\zlib', 'Parser', 'Modules\\_io', 'Python', 'Objects', 'Modules', 'Modules\\cjkcodecs', 'PC'],[0,0,0,0,0,0,0,0]))
for p in glob.glob("**",recursive =True):
    if p.split(".")[-1] != "c":
        continue
    base_name = os.path.basename(p)
    parent_name = os.path.split(p)[0]
    if base_name in c_file_list:
        path_name.append(p)
        dir_name.append(parent_name)
        file_name.append(base_name)
        dir_count[parent_name] += 1
#targetとなっているファイルが所属するデリクトリの集約とそのデリクトリに所属するファイル数の計上    
for key in dir_count:
    print(key,dir_count[key])


<結果>
Objects 39
Modules\_io 7
Parser 12
Modules\zlib 11
Modules\cjkcodecs 7
Python 48
PC 6
Modules 49
Modules フォルダーが一番多く、次がPythonフォルダーが続く。