python path

import os

print os.path.relpath(‘/home/work/compasses_liantiao/auto-opt/framework‘)
print os.path.abspath(‘../../‘)

print os.path.exists("/home/work")
print os.path.exists("./test_path.py")

print os.path.isfile("/home/work")
print os.path.isfile(‘./test_path.py‘)

print os.path.isdir("/home/work")
print os.path.isdir("./test_path.py")

print os.path.dirname("./test_path.py")
print os.path.basename("./test_path.py")

relpath:  获取相对路径

abspath: 获取绝对路径

exists: 判断路径是否存在

isfile: 判断是否为文件

isdir: 判断是否为目录

dirname: 取路径所在目录

basename: 取路径中的文件名

时间: 2024-08-20 14:02:02

python path的相关文章

How to Add Locations to Python Path for Reusable D

In myprevious post I talk about reusable apps, but I don't really explain it that much. If you have an app that might be useful in another project, it's best to not refer to the project name in the application so you don't have to search and remove i

python的import与from...import的不同之处

在python用import或者from...import来导入相应的模块.模块其实就是一些函数和类的集合文件,它能实现一些相应的功能,当我们需要使用这些功能的时候,直接把相应的模块导入到我们的程序中,我们就可以使用了.这类似于C语言中的include头文件,Python中我们用import导入我们需要的模块. import sys print('================Python import mode=========================='); print ('The

python的参数类型

转:http://blog.useasp.net/archive/2014/06/23/the-python-function-or-method-parameter-types.aspx Python中函数的参数有4种形式,分别是: 位置或关键字参数(Positional-or-keyword parameter) 仅位置的参数(Positional-only parameter) 任意数量的位置参数(var-positional parameter) 任意数量的关键字参数(var-keywo

Python中的import和from import

一.Python路径介绍 在python用import或者from...import来导入相应的模块. 模块其实就是一些函数和类的集合文件,它能实现一些相应的功能,当我们需要使用这些功能的时候,直接把相应的模块导入到我们的程序中,我们就可以使用了. 这类似于C语言中的include头文件,Python中我们用import导入我们需要的模块. 二.搜索路径 Python会在以下路径中搜索它想要寻找的模块: 1. 程序所在的文件夹 2. 标准库的安装路径 3. 操作系统环境变量PYTHONPATH所

交叉编译 小米路由器mini 的 python(MIPS)

看了很多文章,要么说的是用opkg安装python,要么说的是小米路由器的交叉编译,就是没有mini的.学习了这篇文章(http://me.deepgully.com/post/5638916786880512),编译了小米路由mini的python. 已编译好的:http://download.csdn.net/detail/kowity/9611919 小米路由mini版的路由是mips的,跟小米路由的arm版不一样,所以脚本做了一些修改.先下载小米路由器mini版的开发包,里面有编译工具链

【转载】Getting Started with Spark (in Python)

Getting Started with Spark (in Python) Benjamin Bengfort Hadoop is the standard tool for distributed computing across really large data sets and is the reason why you see "Big Data" on advertisements as you walk through the airport. It has becom

python子进程模块subprocess详解

属性 1.Popen.poll():用于检查子进程是否已经结束.设置并返回returncode属性. 2.Popen.wait():等待子进程结束.设置并返回returncode属性. 3.Popen.communicate(input=None):与子进程进行交互.向stdin发送数据,或从stdout和stderr中读取数据.可选参数input指定发送到子进程的参数.Communicate()返回一个元组:(stdoutdata, stderrdata).注意:如果希望通过进程的stdin向

Python语言之模块

模块基本上就是一个包含了所有你定义的函数和变量的文件.它用处在于使你你能在别的程序中重用它提供的功能和服务. 1.模块的使用方法 模块的文件名必须以.py作为扩展名. 当我们需要使用某个模块时,我们需要在当前模块导入它.以系统标准库sys为例: 1 import sys 2 3 for i in sys.argv: 4 print( i ) 5 6 print( 'python path: ',sys.path) 也可以使用from...import语句,但是这种方法不推荐使用. 其中sys模块

Spark入门(Python)

Hadoop是对大数据集进行分布式计算的标准工具,这也是为什么当你穿过机场时能看到”大数据(Big Data)”广告的原因.它已经成为大数据的操作系统,提供了包括工具和技巧在内的丰富生态系统,允许使用相对便宜的商业硬件集群进行超级计算机级别的计算.2003和2004年,两个来自Google的观点使Hadoop成为可能:一个分布式存储框架(Google文件系统),在Hadoop中被实现为HDFS:一个分布式计算框架(MapReduce). 这两个观点成为过去十年规模分析(scaling analy