os.path.join里写3个变量

注:

必须为变量,不是变量需先定义为变量

dst="/home/ming"

Images = "Images"

d = open(‘/log/aa.txt‘,‘r‘)
for e in d.readlines():
d.close()
os.makedirs(os.path.join(dst,e.strip(),Images))

原文地址:http://blog.51cto.com/yangzhiming/2140126

时间: 2024-07-30 01:03:32

os.path.join里写3个变量的相关文章

os模块 os.stat('path/filename') os.path.dirname(path) os.path.exists(path)  os.path.join(path1[, path2[, ...]])

提供对操作系统进行调用的接口 1 os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 2 os.chdir("dirname")  改变当前脚本工作目录:相当于shell下cd 3 os.curdir  返回当前目录: ('.') 4 os.pardir  获取当前目录的父目录字符串名:('..') 5 os.makedirs('dirname1/dirname2')    可生成多层递归目录 6 os.removedirs('dirname1')    若

python 中os.path.join 双斜杠的解决办法

这两天在写东西的时候遇到了这个问题,主要是上传图片之后,无法在页面展示,原因就出在用join 拼接的路径中出现了"\"而造成的. >>> import os >>> m = os.path.join('路径','文件名.txt') >>> m '路径\\文件名.txt' >>> m.replace('\\','/') '路径/文件名.txt' >>> m = os.path.join('路径','

os.path.join路径拼接的问题

问题一: import os a = os.path.join("/test1", "/test2") print(a) b = os.path.join("/test1", "test2") print(b) 输出:/test2 /test1/test2 使用os.path.join第二个参数的首个字符如果是"/" , 拼接出来的路径会不包含第一个参数 问题二: os.path.join拼接的路径出现了反

Python——os.path.dirname(__file__) 与 os.path.join(str,str)

Python os.path.dirname(__file__) Python os.path.join(str,str) (1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: python d:\pythonSrc\test\test.py 那么将输出 d:\pythonSrc\test (2).当"print os.path.dirname(__file__)"所在脚本

Python os.path.dirname(__file__) os.path.join(str,str)

Python os.path.dirname(__file__) Python os.path.join(str,str) (1).当"print os.path.dirname(__file__)"所在脚本是以完整路径被运行的, 那么将输出该脚本所在的完整路径,比如: python d:\pythonSrc\test\test.py 那么将输出 d:\pythonSrc\test (2).当"print os.path.dirname(__file__)"所在脚本

os.path.join 的用法

Python中有join和os.path.join()两个函数,具体作用如下: join:连接字符串数组.将字符串.元组.列表中的元素以指定的字符(分隔符)连接生成一个新的字符串os.path.join():  将多个路径组合后返回 一.函数说明 1.join()函数 语法:'sep'.join(seq) 参数说明: sep:分隔符.可以为空 seq:要连接的元素序列.字符串.元组.字典等 上面的语法即:以sep作为分隔符,将seq所有的元素合并成一个新的字符串 返回值:返回一个以分隔符sep连

os.path.join()

os.path.join()函数功能:连接两个或更多的路径名组件 如果各组件名首字母不包含’/’,则函数会自动加上 如果有一个组件是一个绝对路径,则在它之前的所有组件均会被舍弃 如果最后一个组件为空,则生成的路径以一个’/’分隔符结尾 Demo1 import os Path1 = 'home' Path2 = 'develop' Path3 = 'code' Path10 = Path1 + Path2 + Path3 Path20 = os.path.join(Path1,Path2,Pat

os.path.join用法

os.path.join()函数:连接两个或更多的路径名组件 1.如果各组件名首字母不包含’/’,则函数会自动加上 2.如果有一个组件是一个绝对路径,则在它之前的所有组件均会被舍弃 3.如果最后一个组件为空,则生成的路径以一个’/’分隔符结尾 Demo1 import os Path1 = 'home'Path2 = 'develop'Path3 = 'code' Path10 = Path1 + Path2 + Path3Path20 = os.path.join(Path1,Path2,Pa

Python join() 方法与os.path.join()的区别

Python join() 方法与os.path.join()的区别 1. 函数作用: join() :将序列.字符串 .元组等中的元素以指定的字符连接生成一个新的字符串.os.path.join() : 将多个路径组合后返回 2. join()方法说明: join()方法语法:str.join(sequence)参数说明:str:指定的字符,即分隔符sequence:需要连接的元素 #字符串序列 seq = ("apple", "banana", "pe