• python os模块


    导入模块后,可以使用模块提供的通用变量获取与系统有关的信息

     

    >>> import os

    >>> len(dir(os))

    152

    >>> for i in dir(os):print(i)

     

    DirEntry

    F_OK

    MutableMapping

    O_APPEND

    O_BINARY

    O_CREAT

    O_EXCL

    O_NOINHERIT

    O_RANDOM

    O_RDONLY

    O_RDWR

    O_SEQUENTIAL

    O_SHORT_LIVED

    O_TEMPORARY

    O_TEXT

    O_TRUNC

    O_WRONLY

    P_DETACH

    P_NOWAIT

    P_NOWAITO

    P_OVERLAY

    P_WAIT

    PathLike

    R_OK

    SEEK_CUR

    SEEK_END

    SEEK_SET

    TMP_MAX

    W_OK

    X_OK

    _Environ

    __all__

    __builtins__

    __cached__

    __doc__

    __file__

    __loader__

    __name__

    __package__

    __spec__

    _execvpe

    _exists

    _exit

    _fspath

    _get_exports_list

    _putenv

    _unsetenv

    _wrap_close

    abc

    abort

    access

    altsep

    chdir把path设置为当前工作目录

    chmod

    close

    closerange

    cpu_count

    curdir

    defpath

    device_encoding

    devnull

    dup

    dup2

    environ

    errno

    error

    execl

    execle

    execlp

    execlpe

    execv

    execve

    execvp

    execvpe

    extsep

    fdopen

    fsdecode

    fsencode

    fspath

    fstat

    fsync

    ftruncate

    get_exec_path

    get_handle_inheritable

    get_inheritable

    get_terminal_size

    getcwd 返回当前的工作目录

    getcwdb

    getenv

    getlogin

    getpid

    getppid

    isatty

    kill

    linesep

    link

    listdir返回列表,存放指定路径下的文件和目录信息

    lseek

    lstat

    makedirs创建多级目录

    mkdir 创建目录

    name

    open

    pardir

    path 提供了一些操作目录的函数

    pathsep

    pipe

    popen

    putenv

    read

    readlink

    remove

    removedirs删除多级目录

    rename

    renames

    replace

    rmdir删除目录

    scandir

    sep

    set_handle_inheritable

    set_inheritable

    spawnl

    spawnle

    spawnv

    spawnve

    st

    startfile

    stat

    stat_float_times

    stat_result

    statvfs_result

    strerror

    supports_bytes_environ

    supports_dir_fd

    supports_effective_ids

    supports_fd

    supports_follow_symlinks

    symlink

    sys

    system

    terminal_size

    times

    times_result

    truncate

    umask

    uname_result

    unlink

    urandom

    utime

    waitpid

    walk遍历目录树,该方法返回一个元组,包括所有路径名、所有目录列表和文件列表3个元素

    write

     

     

    name:用于获取操作系统类型

     

    >>> os.name

    'nt'

     

    nt代表windows操作系统,posix代表linux、unix或者MAC OS系统

     

    linesep:用于获取当前操作系统的换行符

     

    >>> os.linesep

    ' '

     

    sep:用于获取当前操作系统的路径分隔符

    >>> os.sep

    '\'

  • 相关阅读:
    BrowserSync,自动刷新,解放F5,去掉更新提示
    js获取手机系统语言
    块元素,行内元素,行内块区别
    原生js判断某个元素是否有指定的class名的几种方法
    如何实现调用console.log(‘good’.repeat(3))时输出goodgoodgood?
    数组如何去除重复数据,只保留一条
    Sentinel笔记-Flow流控规则
    sentinel笔记 NodeSelectorSlot,ClusterBuilderSlot
    Sentinel笔记--Slotchain
    Sentinel笔记-核心类
  • 原文地址:https://www.cnblogs.com/jeancheng/p/13369580.html
Copyright © 2020-2023  润新知