Python os.getcwd() 方法

 Python OS 文件/目录方法


概述

os.getcwd() 方法用于返回当前工作目录。

语法

getcwd()方法语法格式如下:

os.getcwd()

参数

返回值

返回当前进程的工作目录。

实例

以下实例演示了 getcwd() 方法的使用:

#!/usr/bin/python
# -*- coding: UTF-8 -*- import os, sys # 切换到 "/var/www/html" 目录
os.chdir("/var/www/html" ) # 打印当前目录
print "当前工作目录 : %s" % os.getcwd() # 打开 "/tmp"
fd = os.open( "/tmp", os.O_RDONLY ) # 使用 os.fchdir() 方法修改目录
os.fchdir(fd) # 打印当前目录
print "当前工作目录 : %s" % os.getcwd() # 关闭文件
os.close( fd )

执行以上程序输出结果为:

当前工作目录 : /var/www/html
当前工作目录 : /tmp

Python os.getcwd()的更多相关文章

  1. Python os.getcwd() 方法

    Python os.getcwd() 方法  Python OS 文件/目录方法 概述 os.getcwd() 方法用于返回当前工作目录. 语法 getcwd()方法语法格式如下: os.getcwd ...

  2. python做中学(六)os.getcwd() 的用法

    概述 os.getcwd() 方法用于返回当前工作目录. 语法 getcwd()方法语法格式如下: os.getcwd() 参数 无 返回值 返回当前进程的工作目录. 实例 以下实例演示了 getcw ...

  3. python慎用os.getcwd() ,除非你知道【文件路径与当前工作路径的区别】

    当你搜索 "获取当前文件路径" 时,有的文章会提到用os.getcwd(),但是这玩意要慎用! 废话不多说,直接上例子: E:\program_software\Pycharm\y ...

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

    通过os.getcwd()获取的路径为:D:\Auto\test\mobule,实际需要修改为:D://Auto//test//mobule 代码实现如下: import osb = os.getcw ...

  5. 【python】os.getcwd和getcwdu

    print os.getcwd(), type(os.getcwd()) print os.getcwdu(), type(os.getcwdu()) 结果如下: C:\Users\Administr ...

  6. Python OS模块常用函数说明

    Python的标准库中的os模块包含普遍的操作系统功能.如果你希望你的程序能够与平台无关的话,这个模块是尤为重要的.即它允许一个程序在编写后不需要任何改动,也不会发生任何问题,就可以在Linux和Wi ...

  7. Python os模块介绍

    os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径 os.chdir("dirname") 改变当前脚本工作目录:相当于shell下cd os.curd ...

  8. python os.path

    os.path 提供了一些处理文件路径的函数. os.path.abspath(path) 返回绝对路径, 在大多数平台上, os.path.abspath(path) == os.path.norm ...

  9. Python os 标准库使用

    os模块是python自带的一个核心模块,用于和操作系统对象进行交互. 1.导入模块获取帮助 >>> import os>>> help(os)>>&g ...

随机推荐

  1. leetcode990

    class Finder: def __init__(self): self.Parent = [i for i in range(26)] def union(self, p, q): self.P ...

  2. H5自动准备杂记

    由于之前没做过UI自动化,近期准备做H5自动化,要学的东西还是很多. 1.本地debug环境:android studio + android SDK(想要调试通要关注:驱动.手机开发者模式要打开) ...

  3. Git 上传文件到 码云 gitee

    1:git bash 执行如下 git config –global user.name “eason” git config –global user.email “your email@qq.co ...

  4. Linux swap 使用

    使用的背景 内存吃紧的时候可以考虑使用swap. swap新增 http://www.cnblogs.com/wuxie1989/p/5888595.html swap 使用 https://www. ...

  5. 重置mysql5.7密码

    其实想要重置 5.7 的密码很简单,就一层窗户纸: 1.修改 /etc/my.cnf,在 [mysqld] 小节下添加一行:skip-grant-tables=1 这一行配置让 mysqld 启动时不 ...

  6. 查看已打包app的entitlements文件内容

    执行以下命令: codesign -d --ent :- /path/to/the.app https://developer.apple.com/library/content/technotes/ ...

  7. U3D MemoryProfiler

    MemoryProfiler Unity 5.3a4 has a new very lowlevel memory profiler API. It can tell you which object ...

  8. NETIF_F_LLTX 的属性

    在bond初始化的时候,我们可以看到如下属性: /* don't acquire bond device's netif_tx_lock when transmitting */     bond_d ...

  9. VS Code 使用笔记

    改变 UI 语言 How to change UI language in Visual Studio Code? 设置 Tab 空格 How to set tab-space style?

  10. python机器学习一:KNN算法实现

    所谓的KNN算法,或者说K最近邻(kNN,k-NearestNeighbor)分类算法是数据挖掘分类技术中最简单的方法之一.所谓K最近邻,就是k个最近的邻居的意思,说的是每个样本都可以用它最接近的k个 ...