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

example_1

code

coder@Ubuntu:~$ source activate py37
(py37) coder@Ubuntu:~$ ipython
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import os In [2]: os.mkdir('/home/coder/not_exist_dir_father/not_exist_dir_son')
---------------------------------------------------------------------------
FileNotFoundError Traceback (most recent call last)
<ipython-input-2-dfab67f068d5> in <module>()
----> 1 os.mkdir('/home/coder/not_exist_dir_father/not_exist_dir_son') FileNotFoundError: [Errno 2] No such file or directory: '/home/coder/not_exist_dir_father/not_exist_dir_son' In [3]: # 在父目录不存在的情况下,会抛异常的 In [4]: exit
(py37) coder@Ubuntu:~$ source deactivate
coder@Ubuntu:~$

example_2

code

coder@Ubuntu:~$ source activate py37
(py37) coder@Ubuntu:~$ ipython
Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help. In [1]: import os In [2]: # 一级一级的创建文件夹 In [3]: os.mkdir('/home/coder/not_exist_dir_father') In [4]: os.mkdir('/home/coder/not_exist_dir_father/not_exist_dir_son') In [5]: cd /home/coder/
/home/coder In [6]: tree not_exist_dir_father # 使用tree命令查看文件夹结构
File "<ipython-input-6-796e24880147>", line 1
tree not_exist_dir_father # 使用tree命令查看文件夹结构
^
SyntaxError: invalid syntax In [7]: exit
(py37) coder@Ubuntu:~$ source deactivate
coder@Ubuntu:~$

在终端中使用tree命令查看文件夹结构

coder@Ubuntu:~$ ls -l
总用量 88
drwxr-xr-x 23 coder coder 4096 9月 30 18:41 anaconda3
drwxr-xr-x 4 coder coder 4096 10月 2 11:57 Desktop
drwxr-xr-x 2 coder coder 4096 10月 1 01:40 Documents
drwxr-xr-x 2 coder coder 4096 10月 1 01:40 Downloads
-rw-r--r-- 1 coder coder 8980 9月 30 17:26 examples.desktop
-rwxrwxr-x 1 coder coder 2354 4月 28 2009 get-fonts.sh
-rw-rw-r-- 1 coder coder 1042 4月 28 2009 get-fonts.sh.zip
drwxr-xr-x 2 coder coder 4096 10月 1 01:40 Music
drwxr-xr-x 3 coder coder 4096 10月 2 14:22 not_exist_dir_father
drwxr-xr-x 3 coder coder 12288 10月 1 17:38 Pictures
drwxr-xr-x 2 coder coder 4096 10月 1 01:40 Public
drwxr-xr-x 11 coder coder 4096 9月 30 18:51 pycharm-2018.2.4
drwxrwxr-x 5 coder coder 4096 10月 2 12:04 PycharmProjects
drwxr-xr-x 3 coder coder 4096 9月 30 22:09 snap
drwxr-xr-x 2 coder coder 4096 10月 1 01:40 Templates
drwxr-xr-x 2 coder coder 4096 9月 30 18:51 ubuntu_software
drwxr-xr-x 2 coder coder 4096 10月 1 01:40 Videos
coder@Ubuntu:~$ tree not_exist_dir_father
not_exist_dir_father
└── not_exist_dir_son 1 directory, 0 files
coder@Ubuntu:~$

more knowledge

  • 有道是:

    不积跬步,无以至千里;不积小流,无以成江海。骐骥一跃,不能十步;驽马十驾,功在不舍。锲而舍之,朽木不折;锲而不舍,金石可镂。

reference

  • [1] blog.csdn.net/qq_28602957/article/details/52511529

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 mkdir 创建一层文件夹 在有父目录的情况下创建子目录的更多相关文章

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

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

  2. MVC为用户创建专属文件夹

    假设需要为用户创建专属文件夹,文件夹名为用户名,并且需要根据用户类型在不同的文件夹下创建目标文件夹. 在F盘创建"Users"文件夹,在其中创建"Gold"文件 ...

  3. Python 创建递归文件夹

    # 创建递归文件夹 def createfiles(filepathname): try: os.makedirs(filepathname) except Exception as err: pri ...

  4. bat如何创建多级文件夹(在android设备中)

    在android设备中要创建多个或者多级文件夹时,手动去创建费时费力(有点傻),一个bat文件就能很好的实现这个功能. 1.首先创建同级多个文件夹且在该文件夹下生成一个文件 @echo off ech ...

  5. Unity中一键创建常用文件夹

    Unity中一键创建常用文件夹 说明 项目测试版本Unity5.3. 这个一个小工具:功能非常简单,就是一键给新建工程添加所有文件夹.到此结束. 但是具体咋操作呢? 与把大象装进冰箱一样,三步,下载代 ...

  6. 在d盘中创建一个文件夹 在文件夹里创建三个txt文本

    import java.io.File; import java.io.IOException; public class FileDemo { public static void main(Str ...

  7. MFC 如何创建浏览文件夹的对话框

    如何创建浏览文件夹的对话框 如何创建浏览文件夹的对话框 CString CXXXXDlg::GetOpenfolderPath() { BROWSEINFO bi; ZeroMemory(&b ...

  8. 命令行创建畸形文件夹+畸形目录管理工具(DeformityPath)

    命令行创建畸形文件夹: 第一步:在运行中输入cmd,回车,打开命令行窗口 第二步:在命令行窗口中切换到想要建立文件夹的硬盘分区,如D盘(输入d:) 第三步:输入 MD 123..\ 回车,注意文件夹名 ...

  9. eclipse创建一个文件夹

    如何给eclipse创建一个文件夹,便于项目的管理:有时我们的eclipse中会有很多项目的,有的是公司的如Project1,Project2,Project3....还有的呢, 也可能是自己平时做的 ...

随机推荐

  1. Linux下缓冲区溢出攻击的原理及对策

    前言 从逻辑上讲进程的堆栈是由多个堆栈帧构成的,其中每个堆栈帧都对应一个函数调用.当函数调用发生时,新的堆栈 帧被压入堆栈:当函数返回时,相应的堆栈帧从堆栈中弹出.尽管堆栈帧结构的引入为在高级语言中实 ...

  2. 【深入理解javascript】原型

    1.一切都是对象 一切(引用类型)都是对象,对象是属性的集合 typeof函数输出的一共有几种类型,在此列出: function show(x) { console.log(typeof(x)); / ...

  3. [py][mx]django通过邮箱找回密码

    忘记密码处理流程 注意: 这个文章里的找回密码页面截取有问题. 找回密码页应该是让输入邮箱 直接上代码 class ActiveView(View): # 主要功能是修改user_profile里的i ...

  4. 用lua扩展你的Nginx(整理)

    首先得声明.这不是我的原创,是在网上搜索到的一篇文章,原著是谁也搞不清楚了.按风格应该是属于章亦春的文章. 整理花了不少时间,所以就暂写成原创吧. 一. 概述 Nginx是一个高性能.支持高并发的,轻 ...

  5. python 皮尔森相关系数

    皮尔森理解 皮尔森相关系数(Pearson correlation coefficient)也称皮尔森积矩相关系数(Pearson product-moment correlation coeffic ...

  6. CSS选择器可以用数字开头吗

    最好是字母开头,后面用数字可以,直接用数字开头不符合官方规范,虽然浏览器牛逼点也能解析出来,但是最初就不要这么做,坏习惯养成很难改.而且如果团队合作,css的命名都需要有固定的格式,还要有可读性方便他 ...

  7. php mysql_connect pmysql_connect区别

    <?php        mysql_pconnect('192.168.75.128', 'root', 'root');        mysql_close();        sleep ...

  8. #C++初学记录(ACM试题1)

    A - Diverse Strings A string is called diverse if it contains consecutive (adjacent) letters of the ...

  9. Mysql闭包表之关于国家区域的一个实践

    在电商系统中,我们总是会遇到一些树形结构数据的存储需求.如地理区域.位置信息存储,地理信息按照层级划分,会分为很多层级,就拿中国的行政区域划分为例,简单的省-市-县-镇-村就要五个级别.如果系统涉及到 ...

  10. input hidden的作用

    网上辣么多blabla的,我就总结一下 1 什么是hidden hidden 是input type的一个值,叫隐藏域,官方解释:“Hidden 对象代表一个 HTML 表单中的某个隐藏输入域. 这种 ...