【python】os.getcwd和getcwdu
print os.getcwd(), type(os.getcwd())
print os.getcwdu(), type(os.getcwdu())
结果如下:
C:\Users\Administrator\PycharmProjects\mypython_1 <type 'str'>
C:\Users\Administrator\PycharmProjects\mypython_1 <type 'unicode'>
可见,一个是返回str,一个是返回unicode
看下面的代码:
s = os.getcwd()
s+= '\测试1'
os.mkdir(s)
运行正常,但是创建的目录是乱码
要得到正确的结果,应该这样:
u = os.getcwdu()
u+= u'\测试2'
os.mkdir(u)
【python】os.getcwd和getcwdu的更多相关文章
- Python os.getcwd()
Python os.getcwd() 方法 Python OS 文件/目录方法 概述 os.getcwd() 方法用于返回当前工作目录. 语法 getcwd()方法语法格式如下: os.getcwd ...
- Python os.getcwd() 方法
Python os.getcwd() 方法 Python OS 文件/目录方法 概述 os.getcwd() 方法用于返回当前工作目录. 语法 getcwd()方法语法格式如下: os.getcwd ...
- python做中学(六)os.getcwd() 的用法
概述 os.getcwd() 方法用于返回当前工作目录. 语法 getcwd()方法语法格式如下: os.getcwd() 参数 无 返回值 返回当前进程的工作目录. 实例 以下实例演示了 getcw ...
- python慎用os.getcwd() ,除非你知道【文件路径与当前工作路径的区别】
当你搜索 "获取当前文件路径" 时,有的文章会提到用os.getcwd(),但是这玩意要慎用! 废话不多说,直接上例子: E:\program_software\Pycharm\y ...
- python 将os.getcwd()获取路径中的\替换成\\
通过os.getcwd()获取的路径为:D:\Auto\test\mobule,实际需要修改为:D://Auto//test//mobule 代码实现如下: import osb = os.getcw ...
- Python OS 文件/目录方法
Python OS 文件/目录方法 os 模块提供了非常丰富的方法用来处理文件和目录.常用的方法如下表所示: 序号 方法及描述 1 os.access(path, mode) 检验权限模式 2 os. ...
- Python OS 文件
Python OS 文件: 1 os.access(path, mode) 检验权限模式 2 os.chdir(path) 改变当前工作目录 3 os.chflags(path, flags) 设置路 ...
- 3 Python os 文件和目录
ile 对象使用 open 函数来创建,下表列出了 file 对象常用的函数: 序号 方法及描述 1 file.close() 关闭文件.关闭后文件不能再进行读写操作. 2 file.flush() ...
- Python os模块方法
os模块提供了大量有用的方法来处理文件和目录.本章节中的代码实例是在 Ubuntu Linux系统上运行来演示. 大多数有用的方法都列在这里 - 编号 方法 描述/说明 1 os.access(pat ...
随机推荐
- 13.multi_match实现dis_max+tie_breaker
主要知识点: 基于multi_match语法实现dis_max+tie_breaker 1.best_fields+tie_breaker GET /forum/article/_search ...
- https://github.com/MediaTek-Labs/linkit-smart-7688-feed编译失败
mkdir -p /home/fly/workdir/LinkltSmart7688Duo-20170626/openwrt/dl/home/fly/workdir/LinkltSmart7688Du ...
- MVC.Net: jqueryval错误
当使用Mvc.net创建Create表单后,firebug Create页面会出现404 Not Found - http://192.168.3.95:7001/bundles/jqueryval& ...
- HDU4882ZCC Loves Codefires(贪心)
ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 如何杀掉(kill)Oracle中的会话(Session)
Oracle中造成一些表被死锁或者会话异常退出,如执行了更新记录操作后,既没有commit也没有rollback,网络就断开了,也会造表或记录被锁住,待到超时后才会被解开,那样都会造成应用操作被阻塞. ...
- 【最短路算法】Dijkstra知识点&代码
代码: #include<iostream> #include<vector> #include<cstdio> #include<queue> #in ...
- 关于ajax技术
传统注册存在的弊端 : 当我们点击注册时,会存在以下几个问题. 首先,浏览器会销毁当前页面,如果注册失败返回的新页面所有之前 填写的数据丢失. 其次,如果网络通信较差,我们表单提交请求数据到服务端,而 ...
- git出错调试
https://stackoverflow.com/questions/6178401/how-can-i-debug-git-git-shell-related-problems git_trace ...
- word2vec和word embedding有什么区别?
word2vec和word embedding有什么区别? 我知道这两个都能将词向量化,但有什么区别?这两个术语的中文是什么? from: https://www.zhihu.com/question ...
- hihocoder 1677 翻转字符串 splay
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个字符串S,小Hi希望对S进行K次翻转操作. 每次翻转小Hi会指定两个整数Li和Ri,表示要将S[Li..Ri]进行 ...