Python学习:一个映射和过滤list的小练习


                                               
[color="#00c600"]>>> [color="#0000ff"]import [color="#800000"]os
[color="#00c600"]>>> [color="#0000ff"]import [color="#800000"]re
[color="#00c600"]>>> [color="#000000"][m [color="#0000ff"]for [color="#000000"]m [color="#0000ff"]in [color="#808000"]dir[color="#000000"]([color="#800000"]os[color="#000000"]) [color="#0000ff"]if [color="#808000"]callable[color="#000000"]([color="#808000"]getattr[color="#000000"]([color="#800000"]os[color="#000000"],m)) [color="#0000ff"]and [color="#800000"]re[color="#00c600"].[color="#808000"]search[color="#000000"]([color="#ff00ff"]'^[^_]'[color="#000000"],m)]  [color="#008080"]#列出os模块中的所有接口方法
[color="#000000"][[color="#ff00ff"]'abort'[color="#000000"], [color="#ff00ff"]'access'[color="#000000"], [color="#ff00ff"]'chdir'[color="#000000"], [color="#ff00ff"]'chmod'[color="#000000"], [color="#ff00ff"]'close'[color="#000000"], [color="#ff00ff"]'dup'[color="#000000"], [color="#ff00ff"]'dup2'[color="#000000"], [color="#ff00ff"]'error'[color="#000000"], [color="#ff00ff"]'execl'[color="#000000"], [color="#ff00ff"]'execle'[color="#000000"], [color="#ff00ff"]'execlp'[color="#000000"],[color="#ff00ff"]'execlpe'[color="#000000"], [color="#ff00ff"]'execv'[color="#000000"], [color="#ff00ff"]'execve'[color="#000000"], [color="#ff00ff"]'execvp'[color="#000000"], [color="#ff00ff"]'execvpe'[color="#000000"], [color="#ff00ff"]'fdopen'[color="#000000"], [color="#ff00ff"]'fstat'[color="#000000"], [color="#ff00ff"]'fsync'[color="#000000"], [color="#ff00ff"]'getcwd'[color="#000000"], [color="#ff00ff"]'getcwdu'[color="#000000"],[color="#ff00ff"]'getenv'[color="#000000"], [color="#ff00ff"]'getpid'[color="#000000"], [color="#ff00ff"]'isatty'[color="#000000"], [color="#ff00ff"]'listdir'[color="#000000"], [color="#ff00ff"]'lseek'[color="#000000"], [color="#ff00ff"]'lstat'[color="#000000"], [color="#ff00ff"]'makedirs'[color="#000000"], [color="#ff00ff"]'mkdir'[color="#000000"], [color="#ff00ff"]'open'[color="#000000"], [color="#ff00ff"]'pipe'[color="#000000"], [color="#ff00ff"]'popen'[color="#000000"], [color="#ff00ff"]'popen2'[color="#000000"], [color="#ff00ff"]'popen3'[color="#000000"], [color="#ff00ff"]'popen4'[color="#000000"], [color="#ff00ff"]'putenv'[color="#000000"], [color="#ff00ff"]'read'[color="#000000"], [color="#ff00ff"]'remove'[color="#000000"], [color="#ff00ff"]'removedirs'[color="#000000"], [color="#ff00ff"]'rename'[color="#000000"], [color="#ff00ff"]'renames'[color="#000000"], [color="#ff00ff"]'rmdir'[color="#000000"], [color="#ff00ff"]'spawnl'[color="#000000"], [color="#ff00ff"]'spawnle'[color="#000000"], [color="#ff00ff"]'spawnv'[color="#000000"], [color="#ff00ff"]'spawnve'[color="#000000"], [color="#ff00ff"]'startfile'[color="#000000"], [color="#ff00ff"]'stat'[color="#000000"], [color="#ff00ff"]'stat_float_times'[color="#000000"], [color="#ff00ff"]'stat_result'[color="#000000"], [color="#ff00ff"]'statvfs_result'[color="#000000"], [color="#ff00ff"]'strerror'[color="#000000"], [color="#ff00ff"]'system'[color="#000000"], [color="#ff00ff"]'tempnam'[color="#000000"], [color="#ff00ff"]'times'[color="#000000"], [color="#ff00ff"]'tmpfile'[color="#000000"], [color="#ff00ff"]'tmpnam'[color="#000000"], [color="#ff00ff"]'umask'[color="#000000"], [color="#ff00ff"]'unlink'[color="#000000"], [color="#ff00ff"]'unsetenv'[color="#000000"], [color="#ff00ff"]'urandom'[color="#000000"], [color="#ff00ff"]'utime'[color="#000000"], [color="#ff00ff"]'waitpid'[color="#000000"], [color="#ff00ff"]'walk'[color="#000000"], [color="#ff00ff"]'write'[color="#000000"]]
[color="#00c600"]>>> [color="#000000"][m [color="#0000ff"]for [color="#000000"]m [color="#0000ff"]in [color="#808000"]dir[color="#000000"]([color="#800000"]os[color="#000000"]) [color="#0000ff"]if [color="#808000"]callable[color="#000000"]([color="#808000"]getattr[color="#000000"]([color="#800000"]os[color="#000000"],m)) [color="#0000ff"]and [color="#800000"]re[color="#00c600"].[color="#808000"]search[color="#000000"]([color="#ff00ff"]'^_'[color="#000000"],m)]  [color="#008080"]#列出os模块中的所有私有方法
[color="#000000"][[color="#ff00ff"]'_Environ'[color="#000000"], [color="#ff00ff"]'_execvpe'[color="#000000"], [color="#ff00ff"]'_exists'[color="#000000"], [color="#ff00ff"]'_exit'[color="#000000"], [color="#ff00ff"]'_get_exports_list'[color="#000000"], [color="#ff00ff"]'_make_stat_result'[color="#000000"], [color="#ff00ff"]'_make_statvfs_result[color="#ff00ff"]', '[color="#ff00ff"]_pickle_stat_result[color="#ff00ff"]', '[color="#ff00ff"]_pickle_statvfs_result[color="#ff00ff"]']