•        Python : 3.7.0
  •          OS : Ubuntu 18.04.1 LTS
  •         IDE : PyCharm 2018.2.4
  •       Conda : 4.5.11
  •    typesetting : Markdown

code

  1. coder@Ubuntu:~$ source activate py37
  2. (py37) coder@Ubuntu:~$ ipython
  3. Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
  4. Type 'copyright', 'credits' or 'license' for more information
  5. IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
  6. In [1]: import os
  7. In [2]: os.getcwd()
  8. Out[2]: '/home/coder'
  9. In [3]: cd /home/coder/
  10. /home/coder
  11. In [4]: ls -a
  12. ./ Documents/ .mozilla/ .python_history
  13. ../ Downloads/ .mplayer/ .shutter/
  14. anaconda3/ examples.desktop Music/ snap/
  15. .bash_history .gconf/ .pam_environment .sogouinput/
  16. .bash_logout get-fonts.sh* Pictures/ .sudo_as_admin_successful
  17. .bashrc get-fonts.sh.zip .pki/ Templates/
  18. .byobu/ .gnome2/ .presage/ .thumbnails/
  19. .cache/ .gnupg/ .profile .thunderbird/
  20. .conda/ .ICEauthority Public/ ubuntu_software/
  21. .config/ .ipython/ .PyCharm2018.2/ Videos/
  22. .dbus/ .java/ pycharm-2018.2.4/ .vscode/
  23. Desktop/ .local/ PycharmProjects/ .xinputrc
  24. In [5]: os.listdir(os.curdir)
  25. Out[5]:
  26. ['.presage',
  27. '.sogouinput',
  28. 'snap',
  29. '.ipython',
  30. '.PyCharm2018.2',
  31. '.vscode',
  32. 'Pictures',
  33. '.dbus',
  34. '.xinputrc',
  35. 'Downloads',
  36. '.conda',
  37. 'get-fonts.sh.zip',
  38. 'Videos',
  39. '.local',
  40. 'ubuntu_software',
  41. '.mplayer',
  42. '.thunderbird',
  43. '.mozilla',
  44. 'examples.desktop',
  45. '.bash_logout',
  46. '.gconf',
  47. 'Music',
  48. '.byobu',
  49. '.gnupg',
  50. 'Desktop',
  51. 'pycharm-2018.2.4',
  52. '.bash_history',
  53. '.sudo_as_admin_successful',
  54. '.config',
  55. 'Templates',
  56. '.bashrc',
  57. 'get-fonts.sh',
  58. '.python_history',
  59. 'PycharmProjects',
  60. 'Public',
  61. '.pam_environment',
  62. '.profile',
  63. '.shutter',
  64. '.thumbnails',
  65. '.cache',
  66. 'Documents',
  67. '.pki',
  68. '.java',
  69. 'anaconda3',
  70. '.gnome2',
  71. '.ICEauthority']
  72. In [6]: os.listdir(os.pardir) # 上一级工作目录有啥
  73. Out[6]: ['lost+found', 'coder']
  74. In [7]: exit
  75. (py37) coder@Ubuntu:~$ source deactivate
  76. coder@Ubuntu:~$

more knowledge

  • 在执行os.listdir(os.pardir)后,看到['lost+found', 'coder'],有疑惑了。lost+found是啥?
  • lost+found目录的文件通常是未链接的文件(名字以及被删除),这些文件还被一些进程使用(数据没有删除),在系统突然关机时(内核panic或突然断电)出现。这些文件系统会删除的,你不需要担心[1]

    当因为软件或硬件出现错误,导致文件系统不一致,也有可能把有问题的文件放入到lost+found目录。它提供了恢复丢失文件的一种方法[1]

reference

  • [1] blog.csdn.net/hu_wen/article/details/70084267
  • [2] www.ttlsa.com/linux/lostfound-description

resource

  • [文档] docs.python.org/3
  • [规范] www.python.org/dev/peps/pep-0008
  • [规范] zh-google-styleguide.readthedocs.io/en/latest/google-python-styleguide/python_language_rules
  • [源码] www.python.org/downloads/source
  • [ PEP ] www.python.org/dev/peps
  • [平台] www.cnblogs.com
  • [平台] gitee.com


Python具有开源、跨平台、解释型、交互式等特性,值得学习。

Python的设计哲学:优雅,明确,简单。提倡用一种方法,最好是只有一种方法来做一件事。

代码的书写要遵守规范,这样有助于沟通和理解。

每种语言都有独特的思想,初学者需要转变思维、踏实践行、坚持积累。

Python3基础 os listdir curdir pardir 查看工作目录及其上一级目录的所有文件名的更多相关文章

  1. Python3基础 os listdir curdir 查看当前工作目录的所有文件的名字

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  2. Python3基础 os listdir 列举指定的所有文件及文件夹的名字

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  3. python,os操作文件,文件路径(上一级目录)

    python获取文件上一级目录:取文件所在目录的上一级目录 os.path.abspath(os.path.join(os.path.dirname('settings.py'),os.path.pa ...

  4. os.path.join合并 os.path.dirname返回上一级目录 os.path.exists(path) os.stat('path/filename')获取文件/目录信息

    import os str1 = "grsdgfd" str2 = "wddf" str3 = "gddgs" # print(str1 + ...

  5. Python3基础 os mkdirs 创建多层文件夹

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  6. Python基础-获取当前目录,上级目录,上上级目录

    import os print '***获取当前目录***' print os.getcwd() print os.path.abspath(os.path.dirname(__file__)) pr ...

  7. Python3基础 os chdir 改变工作目录

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Python3基础 os.path.getsize 获得文件的大小

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Python3基础 os mkdir 创建一层文件夹 在有父目录的情况下创建子目录

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

随机推荐

  1. kerberos (https://en.wikipedia.org/wiki/Kerberos_(protocol))

    Protocol[edit] Description[edit] The client authenticates itself to the Authentication Server (AS) w ...

  2. 自动布局又出问题-HPPGCTableViewCell

    [self.firstComment mas_makeConstraints:^(MASConstraintMaker *make) {        make.top.mas_equalTo(sel ...

  3. AndroidStudio自定义TODO

    1.增加自定义TODO标记 Preferences -> Editor -> TODO,然后点击左下角的加号,输入想要自定义的TODO的正则 输入\bX\b.*(X为TODO标签的名字), ...

  4. format格式化输出

    python格式化输出,format print("""********** Screen: {size} Density: {dpi} Device: {device} ...

  5. http如何301到https呢?

    HTTPS协议的站点信息更加安全,同时可降低网站被劫持的风险,Firefox和chrome浏览器对访问一些非https站点会提示风险,BD等搜索引擎也明确表态了对https站点的友好.那么我们如何部署 ...

  6. my.cnf 详解

    [client] port =3306 socket =/tmp/mysql.sock [mysqld] port =3306 socket =/tmp/mysql.sock basedir =/us ...

  7. Py中的多维数组ndarray学习【转载】

    转自:http://blog.sciencenet.cn/home.php?mod=space&uid=3031432&do=blog&id=1064033 1. NumPy中 ...

  8. mui笔记

    1.关闭当前页面执行上一个页面的方法 var preview = plus.webview.currentWebview().opener() //获取当前窗口的创建者,即A preview.eval ...

  9. Qt 布局管理器

    在一个颜值当道的今天,无论买衣服,买车还是追星,颜值的高低已经变成了大家最看重的(不管男性女性都一样,千万别和我说你不是):而对于程序猿来说,开发一款软件,不再只注重逻辑和稳定性,美观和用户友好性也是 ...

  10. zookeeper简单实战

    一.安装(单机模式.集群模式.伪集群模式) 1:安装JDK 2:解压zk压缩包 3:在conf目录下创建zoo.cfg配置文件. 设置超时时间,快照目录,事务日志文件目录,对外端口,服务IP 4:启动 ...