python 将os.getcwd()获取路径中的\替换成\\

通过os.getcwd()获取的路径为:D:\Auto\test\mobule,实际需要修改为:D://Auto//test//mobule

代码实现如下:

import osb = os.getcwd()
c = r"\\".join(c.split("\\))
print c        #获取到的形式就为:D://Auto//test//mobule

原文地址:https://www.cnblogs.com/syw20170419/p/8279939.html

时间: 2024-08-02 10:34:15

python 将os.getcwd()获取路径中的\替换成\\的相关文章

python爬虫:解决请求路径中含义中文或特殊字符

一.解决请求路径中含义中文或特殊字符(/n,/t等): 1 httpurl=urllib.parse.quote(new_url, safe=string.printable)  注意:new_url必须是只有一个单引号或者双引号,如果是下面这个既有单引号,也有双引号,就会出现urlerror: new_url='"http://news.sina.com.cn/o/2017-06-08/doc-ifyfzaaq5698972.shtml"'

linux shell 获取路径中指定信息

file=/home/data/hunan/hn.2015-9-11.log.bbk file_log_name=`basename $file`  ## file_log_name 就等于 hn.2015-9-11.log.bbk file_test=`basename $file .bbk` ## file_test 就等于 hn.2015-9-11.log no_file_path=${file%/*}   ### 获取文件所在的路径  即 /home/data/hunan city=${

python中os模块获取路径的几种方式

一.代码 import os BASE_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) print(BASE_DIR) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) print(BASE_DIR) BASE_DIR = os.path.abspath(os.path.join(os.path.dirna

java中通过request获取路径中的不同信息

aa为工程中的项目名 bb为webRoot下的文件夹 1.request.getContextPath(); 输出结果:/aa 2.request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path; 输出结果:http://localhost:8080/aa 3.request.getServletPath();(获取客户端请求文件的路径)输出结果:/bb/conte

将python添加到DOS搜索路径中去

1.安装python,我的程序安装在C:\Python34中文件目录中. 2.设置环境变量: 例如你的程序为:C:\Python34,则你需要把这个地址粘贴在: 右键我的电脑->属性->高级->环境变量,然后再下边的 系统变量 选择框中,编辑path(不区分大小写),在变量值的框中,添加:" ;C:\Python26"双引号中的内容

C# 获取路径中文件名、目录、扩展名等

string path = "C:\\dir1\\dir2\\foo.txt"; string str = "GetFullPath:" + Path.GetFullPath(path) + "\r\n"; str += "GetDirectoryName:" + Path.GetDirectoryName(path) + "\r\n"; str += "GetFileName:" +

C# 轻松获取路径中文件名、目录、扩展名等

string path = "C:\\dir1\\dir2\\foo.txt"; string str = "GetFullPath:" + Path.GetFullPath(path) + "\r\n"; str += "GetDirectoryName:" + Path.GetDirectoryName(path) + "\r\n"; str += "GetFileName:" +

C#获取路径中最后一个文件夹的名字

1 using System; 2 using System.IO; 3 4 namespace ConsoleApplication1 5 { 6 class Program 7 { 8 static void Main(string[] args) 9 { 10 string path1 = @"E:\uniuProject5.6.2\art\UnityArt(u3d5.6.2)\Assets\Cloth\FBX\Character\Models"; 11 string path2

Python系统(os)相关操作

文件操作 python中常用于文件处理的模块有os,shutil等. 1 创建文件 文件的创建可以使用open()函数,如下创建一个test_file.txt的文件: >>> with open('/Users/xxx/test_file.txt','wt') as f_obj: ... print("This is the content from the test file---John",file=f_obj) ... >>> 执行完后,可以找