测试 2

Python 文件操作

判断文件是否存在

import os

os.path.exists('file.txt')
# True

os.path.exists('./dir')
# True
os.path.isfile('./dir')
# False

新建文件夹

# 在当前目录下新建文件夹
os.mkdir(path)

# 新建多层文件夹
os.makedirs(path) 

conda 的用法

管理环境

创建环境

conda create --name snowflakes

切换某个环境

  • Windows: activate snowflakes
  • Linux and macOS: source activate snowflakes

查看环境列表

conda info --envs

切换到默认环境

  • Windows: deactivate
  • Linux, macOS: source deactivate

管理 Python 版本

使用特定版本的 Python

在创建环境的时候,如果不指定 Python 的版本,那么会默认使用安装 anaconda 时候的 Python 版本。如果需要特定版本可以手动指定:

conda create --name snakes python=3.5

管理包

搜索包

在某个环境下,安装某个包,首先需要查找是否存在这个包:

conda search beautifulsoup4

安装某个包

如果存在,就可以使用如下命令安装:

conda install beautifulsoup4

罗列当前环境下已安装的包

conda list

猜你喜欢

转载自www.cnblogs.com/wy-ei/p/9251255.html
今日推荐