Linux ip-148-66-134-25.ip.secureserver.net 3.10.0-1160.119.1.el7.tuxcare.els11.x86_64 #1 SMP Sun Nov 3 09:06:59 UTC 2024 x86_64
Apache
: 148.66.134.25 | : 13.58.200.16
66 Domain
8.0.30
amvm
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
BLACK DEFEND!
README
+ Create Folder
+ Create File
/
usr /
share /
doc /
python-docs-2.7.5 /
html /
library /
[ HOME SHELL ]
Name
Size
Permission
Action
2to3.html
49.27
KB
-rw-r--r--
__builtin__.html
10.26
KB
-rw-r--r--
__future__.html
13.79
KB
-rw-r--r--
__main__.html
7.05
KB
-rw-r--r--
_winreg.html
59.21
KB
-rw-r--r--
abc.html
23.9
KB
-rw-r--r--
aepack.html
13.16
KB
-rw-r--r--
aetools.html
14.91
KB
-rw-r--r--
aetypes.html
18.88
KB
-rw-r--r--
aifc.html
22.4
KB
-rw-r--r--
al.html
17.34
KB
-rw-r--r--
allos.html
33.72
KB
-rw-r--r--
anydbm.html
16.33
KB
-rw-r--r--
archiving.html
9.26
KB
-rw-r--r--
argparse.html
237.62
KB
-rw-r--r--
array.html
29.29
KB
-rw-r--r--
ast.html
34.98
KB
-rw-r--r--
asynchat.html
31.43
KB
-rw-r--r--
asyncore.html
36.51
KB
-rw-r--r--
atexit.html
16.8
KB
-rw-r--r--
audioop.html
31.36
KB
-rw-r--r--
autogil.html
8.19
KB
-rw-r--r--
base64.html
19.67
KB
-rw-r--r--
basehttpserver.html
34.04
KB
-rw-r--r--
bastion.html
11.04
KB
-rw-r--r--
bdb.html
36.68
KB
-rw-r--r--
binascii.html
20.67
KB
-rw-r--r--
binhex.html
10.58
KB
-rw-r--r--
bisect.html
23.24
KB
-rw-r--r--
bsddb.html
26.43
KB
-rw-r--r--
bz2.html
26.08
KB
-rw-r--r--
calendar.html
37.79
KB
-rw-r--r--
carbon.html
48.94
KB
-rw-r--r--
cd.html
27.96
KB
-rw-r--r--
cgi.html
49.92
KB
-rw-r--r--
cgihttpserver.html
13.1
KB
-rw-r--r--
cgitb.html
11.41
KB
-rw-r--r--
chunk.html
14.66
KB
-rw-r--r--
cmath.html
25.63
KB
-rw-r--r--
cmd.html
26.09
KB
-rw-r--r--
code.html
24.58
KB
-rw-r--r--
codecs.html
100.64
KB
-rw-r--r--
codeop.html
14.84
KB
-rw-r--r--
collections.html
133.96
KB
-rw-r--r--
colorpicker.html
7.52
KB
-rw-r--r--
colorsys.html
11.04
KB
-rw-r--r--
commands.html
14.36
KB
-rw-r--r--
compileall.html
16.83
KB
-rw-r--r--
compiler.html
67.75
KB
-rw-r--r--
configparser.html
62.13
KB
-rw-r--r--
constants.html
12.83
KB
-rw-r--r--
contextlib.html
19.39
KB
-rw-r--r--
cookie.html
39.07
KB
-rw-r--r--
cookielib.html
83.82
KB
-rw-r--r--
copy.html
12.19
KB
-rw-r--r--
copy_reg.html
13.76
KB
-rw-r--r--
crypt.html
10.04
KB
-rw-r--r--
crypto.html
7.59
KB
-rw-r--r--
csv.html
67.37
KB
-rw-r--r--
ctypes.html
238.78
KB
-rw-r--r--
curses.ascii.html
22.29
KB
-rw-r--r--
curses.html
146.63
KB
-rw-r--r--
curses.panel.html
14.39
KB
-rw-r--r--
custominterp.html
7.62
KB
-rw-r--r--
datatypes.html
16.84
KB
-rw-r--r--
datetime.html
226.59
KB
-rw-r--r--
dbhash.html
15.48
KB
-rw-r--r--
dbm.html
12.07
KB
-rw-r--r--
debug.html
10.15
KB
-rw-r--r--
decimal.html
194.44
KB
-rw-r--r--
development.html
14.17
KB
-rw-r--r--
difflib.html
84.83
KB
-rw-r--r--
dircache.html
11.41
KB
-rw-r--r--
dis.html
69.95
KB
-rw-r--r--
distutils.html
8.05
KB
-rw-r--r--
dl.html
16.33
KB
-rw-r--r--
doctest.html
165.54
KB
-rw-r--r--
docxmlrpcserver.html
16.43
KB
-rw-r--r--
dumbdbm.html
14.02
KB
-rw-r--r--
dummy_thread.html
9.43
KB
-rw-r--r--
dummy_threading.html
8.37
KB
-rw-r--r--
easydialogs.html
30.55
KB
-rw-r--r--
email-examples.html
45.65
KB
-rw-r--r--
email.charset.html
26.8
KB
-rw-r--r--
email.encoders.html
11.86
KB
-rw-r--r--
email.errors.html
15.77
KB
-rw-r--r--
email.generator.html
20.77
KB
-rw-r--r--
email.header.html
26.92
KB
-rw-r--r--
email.html
44.24
KB
-rw-r--r--
email.iterators.html
11.52
KB
-rw-r--r--
email.message.html
63.16
KB
-rw-r--r--
email.mime.html
27.93
KB
-rw-r--r--
email.parser.html
30.45
KB
-rw-r--r--
email.util.html
24.46
KB
-rw-r--r--
errno.html
37.99
KB
-rw-r--r--
exceptions.html
56.13
KB
-rw-r--r--
fcntl.html
22.67
KB
-rw-r--r--
filecmp.html
22.3
KB
-rw-r--r--
fileformats.html
9.14
KB
-rw-r--r--
fileinput.html
24.28
KB
-rw-r--r--
filesys.html
10.2
KB
-rw-r--r--
fl.html
49.92
KB
-rw-r--r--
fm.html
11.91
KB
-rw-r--r--
fnmatch.html
14.58
KB
-rw-r--r--
formatter.html
34.06
KB
-rw-r--r--
fpectl.html
16.01
KB
-rw-r--r--
fpformat.html
10.59
KB
-rw-r--r--
fractions.html
22.61
KB
-rw-r--r--
framework.html
33.34
KB
-rw-r--r--
frameworks.html
7.14
KB
-rw-r--r--
ftplib.html
43.99
KB
-rw-r--r--
functions.html
183.14
KB
-rw-r--r--
functools.html
27.17
KB
-rw-r--r--
future_builtins.html
13.04
KB
-rw-r--r--
gc.html
25.75
KB
-rw-r--r--
gdbm.html
15.96
KB
-rw-r--r--
gensuitemodule.html
11.51
KB
-rw-r--r--
getopt.html
23.66
KB
-rw-r--r--
getpass.html
10.65
KB
-rw-r--r--
gettext.html
78.76
KB
-rw-r--r--
gl.html
22.09
KB
-rw-r--r--
glob.html
13.26
KB
-rw-r--r--
grp.html
10.49
KB
-rw-r--r--
gzip.html
18.99
KB
-rw-r--r--
hashlib.html
18.2
KB
-rw-r--r--
heapq.html
31.61
KB
-rw-r--r--
hmac.html
10.46
KB
-rw-r--r--
hotshot.html
18.65
KB
-rw-r--r--
htmllib.html
25.32
KB
-rw-r--r--
htmlparser.html
39.11
KB
-rw-r--r--
httplib.html
62.95
KB
-rw-r--r--
i18n.html
9.52
KB
-rw-r--r--
ic.html
17.17
KB
-rw-r--r--
idle.html
20.9
KB
-rw-r--r--
imageop.html
14.76
KB
-rw-r--r--
imaplib.html
51.99
KB
-rw-r--r--
imgfile.html
11.71
KB
-rw-r--r--
imghdr.html
11.3
KB
-rw-r--r--
imp.html
34.34
KB
-rw-r--r--
importlib.html
8.26
KB
-rw-r--r--
imputil.html
31.81
KB
-rw-r--r--
index.html
72.78
KB
-rw-r--r--
inspect.html
50.71
KB
-rw-r--r--
internet.html
24.87
KB
-rw-r--r--
intro.html
8.93
KB
-rw-r--r--
io.html
98.13
KB
-rw-r--r--
ipc.html
13.41
KB
-rw-r--r--
itertools.html
115.91
KB
-rw-r--r--
jpeg.html
12.74
KB
-rw-r--r--
json.html
67.04
KB
-rw-r--r--
keyword.html
7.68
KB
-rw-r--r--
language.html
11.03
KB
-rw-r--r--
linecache.html
10.59
KB
-rw-r--r--
locale.html
55.14
KB
-rw-r--r--
logging.config.html
63.36
KB
-rw-r--r--
logging.handlers.html
69.64
KB
-rw-r--r--
logging.html
95.64
KB
-rw-r--r--
mac.html
21.79
KB
-rw-r--r--
macos.html
14.76
KB
-rw-r--r--
macosa.html
12.96
KB
-rw-r--r--
macostools.html
15.52
KB
-rw-r--r--
macpath.html
7.76
KB
-rw-r--r--
mailbox.html
156.75
KB
-rw-r--r--
mailcap.html
13.21
KB
-rw-r--r--
markup.html
18.77
KB
-rw-r--r--
marshal.html
17.98
KB
-rw-r--r--
math.html
39.24
KB
-rw-r--r--
md5.html
13.97
KB
-rw-r--r--
mhlib.html
21.54
KB
-rw-r--r--
mimetools.html
19.25
KB
-rw-r--r--
mimetypes.html
28.39
KB
-rw-r--r--
mimewriter.html
15.02
KB
-rw-r--r--
mimify.html
13.36
KB
-rw-r--r--
miniaeframe.html
12.2
KB
-rw-r--r--
misc.html
6.87
KB
-rw-r--r--
mm.html
9.03
KB
-rw-r--r--
mmap.html
28.36
KB
-rw-r--r--
modulefinder.html
15.31
KB
-rw-r--r--
modules.html
8.46
KB
-rw-r--r--
msilib.html
52.43
KB
-rw-r--r--
msvcrt.html
19.37
KB
-rw-r--r--
multifile.html
24.3
KB
-rw-r--r--
multiprocessing.html
365.71
KB
-rw-r--r--
mutex.html
11.23
KB
-rw-r--r--
netdata.html
16.98
KB
-rw-r--r--
netrc.html
12.3
KB
-rw-r--r--
new.html
12.12
KB
-rw-r--r--
nis.html
10.64
KB
-rw-r--r--
nntplib.html
41.92
KB
-rw-r--r--
numbers.html
37.75
KB
-rw-r--r--
numeric.html
13.55
KB
-rw-r--r--
operator.html
82
KB
-rw-r--r--
optparse.html
222.56
KB
-rw-r--r--
os.html
214.25
KB
-rw-r--r--
os.path.html
38.34
KB
-rw-r--r--
ossaudiodev.html
41.5
KB
-rw-r--r--
othergui.html
9.08
KB
-rw-r--r--
parser.html
39.36
KB
-rw-r--r--
pdb.html
33.96
KB
-rw-r--r--
persistence.html
14.87
KB
-rw-r--r--
pickle.html
102.27
KB
-rw-r--r--
pickletools.html
10.63
KB
-rw-r--r--
pipes.html
18.01
KB
-rw-r--r--
pkgutil.html
25.11
KB
-rw-r--r--
platform.html
28.37
KB
-rw-r--r--
plistlib.html
17.03
KB
-rw-r--r--
popen2.html
25.43
KB
-rw-r--r--
poplib.html
22.32
KB
-rw-r--r--
posix.html
14.41
KB
-rw-r--r--
posixfile.html
19.76
KB
-rw-r--r--
pprint.html
29.92
KB
-rw-r--r--
profile.html
63.56
KB
-rw-r--r--
pty.html
9.48
KB
-rw-r--r--
pwd.html
11.43
KB
-rw-r--r--
py_compile.html
11.12
KB
-rw-r--r--
pyclbr.html
14.71
KB
-rw-r--r--
pydoc.html
11.48
KB
-rw-r--r--
pyexpat.html
71.53
KB
-rw-r--r--
python.html
12.27
KB
-rw-r--r--
queue.html
24.22
KB
-rw-r--r--
quopri.html
11.9
KB
-rw-r--r--
random.html
37.83
KB
-rw-r--r--
re.html
134.74
KB
-rw-r--r--
readline.html
28.24
KB
-rw-r--r--
repr.html
20.43
KB
-rw-r--r--
resource.html
26.48
KB
-rw-r--r--
restricted.html
11.65
KB
-rw-r--r--
rexec.html
37.41
KB
-rw-r--r--
rfc822.html
42.22
KB
-rw-r--r--
rlcompleter.html
13.51
KB
-rw-r--r--
robotparser.html
12.27
KB
-rw-r--r--
runpy.html
19.34
KB
-rw-r--r--
sched.html
18.54
KB
-rw-r--r--
scrolledtext.html
9.32
KB
-rw-r--r--
select.html
39.67
KB
-rw-r--r--
sets.html
36.92
KB
-rw-r--r--
sgi.html
9.71
KB
-rw-r--r--
sgmllib.html
30.77
KB
-rw-r--r--
sha.html
12.09
KB
-rw-r--r--
shelve.html
27.02
KB
-rw-r--r--
shlex.html
32.1
KB
-rw-r--r--
shutil.html
40.22
KB
-rw-r--r--
signal.html
31.14
KB
-rw-r--r--
simplehttpserver.html
18.41
KB
-rw-r--r--
simplexmlrpcserver.html
31.39
KB
-rw-r--r--
site.html
23.64
KB
-rw-r--r--
smtpd.html
12.46
KB
-rw-r--r--
smtplib.html
42.13
KB
-rw-r--r--
sndhdr.html
10.02
KB
-rw-r--r--
socket.html
106.34
KB
-rw-r--r--
socketserver.html
59.83
KB
-rw-r--r--
someos.html
15.11
KB
-rw-r--r--
spwd.html
10.33
KB
-rw-r--r--
sqlite3.html
139.5
KB
-rw-r--r--
ssl.html
65.62
KB
-rw-r--r--
stat.html
32.31
KB
-rw-r--r--
statvfs.html
10.6
KB
-rw-r--r--
stdtypes.html
260.4
KB
-rw-r--r--
string.html
106.65
KB
-rw-r--r--
stringio.html
18.81
KB
-rw-r--r--
stringprep.html
16.13
KB
-rw-r--r--
strings.html
14.93
KB
-rw-r--r--
struct.html
40.88
KB
-rw-r--r--
subprocess.html
84.91
KB
-rw-r--r--
sun.html
6.84
KB
-rw-r--r--
sunau.html
27.1
KB
-rw-r--r--
sunaudio.html
17.79
KB
-rw-r--r--
symbol.html
7.66
KB
-rw-r--r--
symtable.html
22.94
KB
-rw-r--r--
sys.html
98.7
KB
-rw-r--r--
sysconfig.html
23.84
KB
-rw-r--r--
syslog.html
17.92
KB
-rw-r--r--
tabnanny.html
10.63
KB
-rw-r--r--
tarfile.html
78.68
KB
-rw-r--r--
telnetlib.html
25.48
KB
-rw-r--r--
tempfile.html
29.42
KB
-rw-r--r--
termios.html
16.01
KB
-rw-r--r--
test.html
52.62
KB
-rw-r--r--
textwrap.html
27.25
KB
-rw-r--r--
thread.html
20.47
KB
-rw-r--r--
threading.html
76.69
KB
-rw-r--r--
time.html
56.93
KB
-rw-r--r--
timeit.html
36.27
KB
-rw-r--r--
tix.html
46.96
KB
-rw-r--r--
tk.html
23.64
KB
-rw-r--r--
tkinter.html
67.67
KB
-rw-r--r--
token.html
19.62
KB
-rw-r--r--
tokenize.html
18.45
KB
-rw-r--r--
trace.html
25.54
KB
-rw-r--r--
traceback.html
33.44
KB
-rw-r--r--
ttk.html
101.75
KB
-rw-r--r--
tty.html
9.06
KB
-rw-r--r--
turtle.html
211.74
KB
-rw-r--r--
types.html
27.59
KB
-rw-r--r--
undoc.html
23.16
KB
-rw-r--r--
unicodedata.html
18.55
KB
-rw-r--r--
unittest.html
202.85
KB
-rw-r--r--
unix.html
10.55
KB
-rw-r--r--
urllib.html
58.68
KB
-rw-r--r--
urllib2.html
100.58
KB
-rw-r--r--
urlparse.html
40.41
KB
-rw-r--r--
user.html
11.83
KB
-rw-r--r--
userdict.html
29.73
KB
-rw-r--r--
uu.html
11.03
KB
-rw-r--r--
uuid.html
28.19
KB
-rw-r--r--
warnings.html
46.6
KB
-rw-r--r--
wave.html
22.22
KB
-rw-r--r--
weakref.html
36.52
KB
-rw-r--r--
webbrowser.html
23.07
KB
-rw-r--r--
whichdb.html
8.85
KB
-rw-r--r--
windows.html
9.33
KB
-rw-r--r--
winsound.html
18.75
KB
-rw-r--r--
wsgiref.html
81.04
KB
-rw-r--r--
xdrlib.html
29.94
KB
-rw-r--r--
xml.dom.html
89.04
KB
-rw-r--r--
xml.dom.minidom.html
40.42
KB
-rw-r--r--
xml.dom.pulldom.html
12.71
KB
-rw-r--r--
xml.etree.elementtree.html
93.22
KB
-rw-r--r--
xml.html
16.49
KB
-rw-r--r--
xml.sax.handler.html
38.63
KB
-rw-r--r--
xml.sax.html
20.22
KB
-rw-r--r--
xml.sax.reader.html
39.09
KB
-rw-r--r--
xml.sax.utils.html
14.26
KB
-rw-r--r--
xmlrpclib.html
60.79
KB
-rw-r--r--
zipfile.html
53.14
KB
-rw-r--r--
zipimport.html
20.42
KB
-rw-r--r--
zlib.html
25.46
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : os.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>15.1. os — Miscellaneous operating system interfaces — Python 2.7.5 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.7.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.5 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="top" title="Python 2.7.5 documentation" href="../index.html" /> <link rel="up" title="15. Generic Operating System Services" href="allos.html" /> <link rel="next" title="15.2. io — Core tools for working with streams" href="io.html" /> <link rel="prev" title="15. Generic Operating System Services" href="allos.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="io.html" title="15.2. io — Core tools for working with streams" accesskey="N">next</a> |</li> <li class="right" > <a href="allos.html" title="15. Generic Operating System Services" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="allos.html" accesskey="U">15. Generic Operating System Services</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-os"> <span id="os-miscellaneous-operating-system-interfaces"></span><h1>15.1. <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> — Miscellaneous operating system interfaces<a class="headerlink" href="#module-os" title="Permalink to this headline">¶</a></h1> <p>This module provides a portable way of using operating system dependent functionality. If you just want to read or write a file see <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>, if you want to manipulate paths, see the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a> module, and if you want to read all the lines in all the files on the command line see the <a class="reference internal" href="fileinput.html#module-fileinput" title="fileinput: Loop over standard input or a list of files."><tt class="xref py py-mod docutils literal"><span class="pre">fileinput</span></tt></a> module. For creating temporary files and directories see the <a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><tt class="xref py py-mod docutils literal"><span class="pre">tempfile</span></tt></a> module, and for high-level file and directory handling see the <a class="reference internal" href="shutil.html#module-shutil" title="shutil: High-level file operations, including copying."><tt class="xref py py-mod docutils literal"><span class="pre">shutil</span></tt></a> module.</p> <p>Notes on the availability of these functions:</p> <ul class="simple"> <li>The design of all built-in operating system dependent modules of Python is such that as long as the same functionality is available, it uses the same interface; for example, the function <tt class="docutils literal"><span class="pre">os.stat(path)</span></tt> returns stat information about <em>path</em> in the same format (which happens to have originated with the POSIX interface).</li> <li>Extensions peculiar to a particular operating system are also available through the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module, but using them is of course a threat to portability.</li> <li>An “Availability: Unix” note means that this function is commonly found on Unix systems. It does not make any claims about its existence on a specific operating system.</li> <li>If not separately noted, all functions that claim “Availability: Unix” are supported on Mac OS X, which builds on a Unix core.</li> </ul> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">All functions in this module raise <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> in the case of invalid or inaccessible file names and paths, or other arguments that have the correct type, but are not accepted by the operating system.</p> </div> <dl class="exception"> <dt id="os.error"> <em class="property">exception </em><tt class="descclassname">os.</tt><tt class="descname">error</tt><a class="headerlink" href="#os.error" title="Permalink to this definition">¶</a></dt> <dd><p>An alias for the built-in <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> exception.</p> </dd></dl> <dl class="data"> <dt id="os.name"> <tt class="descclassname">os.</tt><tt class="descname">name</tt><a class="headerlink" href="#os.name" title="Permalink to this definition">¶</a></dt> <dd><p>The name of the operating system dependent module imported. The following names have currently been registered: <tt class="docutils literal"><span class="pre">'posix'</span></tt>, <tt class="docutils literal"><span class="pre">'nt'</span></tt>, <tt class="docutils literal"><span class="pre">'os2'</span></tt>, <tt class="docutils literal"><span class="pre">'ce'</span></tt>, <tt class="docutils literal"><span class="pre">'java'</span></tt>, <tt class="docutils literal"><span class="pre">'riscos'</span></tt>.</p> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <p><a class="reference internal" href="sys.html#sys.platform" title="sys.platform"><tt class="xref py py-attr docutils literal"><span class="pre">sys.platform</span></tt></a> has a finer granularity. <a class="reference internal" href="#os.uname" title="os.uname"><tt class="xref py py-func docutils literal"><span class="pre">os.uname()</span></tt></a> gives system-dependent version information.</p> <p class="last">The <a class="reference internal" href="platform.html#module-platform" title="platform: Retrieves as much platform identifying data as possible."><tt class="xref py py-mod docutils literal"><span class="pre">platform</span></tt></a> module provides detailed checks for the system’s identity.</p> </div> </dd></dl> <div class="section" id="process-parameters"> <span id="os-procinfo"></span><h2>15.1.1. Process Parameters<a class="headerlink" href="#process-parameters" title="Permalink to this headline">¶</a></h2> <p>These functions and data items provide information and operate on the current process and user.</p> <dl class="data"> <dt id="os.environ"> <tt class="descclassname">os.</tt><tt class="descname">environ</tt><a class="headerlink" href="#os.environ" title="Permalink to this definition">¶</a></dt> <dd><p>A <a class="reference internal" href="../glossary.html#term-mapping"><em class="xref std std-term">mapping</em></a> object representing the string environment. For example, <tt class="docutils literal"><span class="pre">environ['HOME']</span></tt> is the pathname of your home directory (on some platforms), and is equivalent to <tt class="docutils literal"><span class="pre">getenv("HOME")</span></tt> in C.</p> <p>This mapping is captured the first time the <a class="reference internal" href="#module-os" title="os: Miscellaneous operating system interfaces."><tt class="xref py py-mod docutils literal"><span class="pre">os</span></tt></a> module is imported, typically during Python startup as part of processing <tt class="file docutils literal"><span class="pre">site.py</span></tt>. Changes to the environment made after this time are not reflected in <tt class="docutils literal"><span class="pre">os.environ</span></tt>, except for changes made by modifying <tt class="docutils literal"><span class="pre">os.environ</span></tt> directly.</p> <p>If the platform supports the <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> function, this mapping may be used to modify the environment as well as query the environment. <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> will be called automatically when the mapping is modified.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Calling <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> directly does not change <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it’s better to modify <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p> </div> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">On some platforms, including FreeBSD and Mac OS X, setting <tt class="docutils literal"><span class="pre">environ</span></tt> may cause memory leaks. Refer to the system documentation for <tt class="xref c c-func docutils literal"><span class="pre">putenv()</span></tt>.</p> </div> <p>If <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> is not provided, a modified copy of this mapping may be passed to the appropriate process-creation functions to cause child processes to use a modified environment.</p> <p>If the platform supports the <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> function, you can delete items in this mapping to unset environment variables. <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> will be called automatically when an item is deleted from <tt class="docutils literal"><span class="pre">os.environ</span></tt>, and when one of the <tt class="xref py py-meth docutils literal"><span class="pre">pop()</span></tt> or <tt class="xref py py-meth docutils literal"><span class="pre">clear()</span></tt> methods is called.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.6: </span>Also unset environment variables when calling <tt class="xref py py-meth docutils literal"><span class="pre">os.environ.clear()</span></tt> and <tt class="xref py py-meth docutils literal"><span class="pre">os.environ.pop()</span></tt>.</p> </dd></dl> <dl class="function"> <dt> <tt class="descclassname">os.</tt><tt class="descname">chdir</tt><big>(</big><em>path</em><big>)</big></dt> <dt> <tt class="descclassname">os.</tt><tt class="descname">fchdir</tt><big>(</big><em>fd</em><big>)</big></dt> <dt> <tt class="descclassname">os.</tt><tt class="descname">getcwd</tt><big>(</big><big>)</big></dt> <dd><p>These functions are described in <a class="reference internal" href="#os-file-dir"><em>Files and Directories</em></a>.</p> </dd></dl> <dl class="function"> <dt id="os.ctermid"> <tt class="descclassname">os.</tt><tt class="descname">ctermid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.ctermid" title="Permalink to this definition">¶</a></dt> <dd><p>Return the filename corresponding to the controlling terminal of the process.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getegid"> <tt class="descclassname">os.</tt><tt class="descname">getegid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getegid" title="Permalink to this definition">¶</a></dt> <dd><p>Return the effective group id of the current process. This corresponds to the “set id” bit on the file being executed in the current process.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.geteuid"> <tt class="descclassname">os.</tt><tt class="descname">geteuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.geteuid" title="Permalink to this definition">¶</a></dt> <dd><p id="index-0">Return the current process’s effective user id.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getgid"> <tt class="descclassname">os.</tt><tt class="descname">getgid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getgid" title="Permalink to this definition">¶</a></dt> <dd><p id="index-1">Return the real group id of the current process.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getgroups"> <tt class="descclassname">os.</tt><tt class="descname">getgroups</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getgroups" title="Permalink to this definition">¶</a></dt> <dd><p>Return list of supplemental group ids associated with the current process.</p> <p>Availability: Unix.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">On Mac OS X, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><tt class="xref py py-func docutils literal"><span class="pre">getgroups()</span></tt></a> behavior differs somewhat from other Unix platforms. If the Python interpreter was built with a deployment target of <tt class="xref py py-const docutils literal"><span class="pre">10.5</span></tt> or earlier, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><tt class="xref py py-func docutils literal"><span class="pre">getgroups()</span></tt></a> returns the list of effective group ids associated with the current user process; this list is limited to a system-defined number of entries, typically 16, and may be modified by calls to <a class="reference internal" href="#os.setgroups" title="os.setgroups"><tt class="xref py py-func docutils literal"><span class="pre">setgroups()</span></tt></a> if suitably privileged. If built with a deployment target greater than <tt class="xref py py-const docutils literal"><span class="pre">10.5</span></tt>, <a class="reference internal" href="#os.getgroups" title="os.getgroups"><tt class="xref py py-func docutils literal"><span class="pre">getgroups()</span></tt></a> returns the current group access list for the user associated with the effective user id of the process; the group access list may change over the lifetime of the process, it is not affected by calls to <a class="reference internal" href="#os.setgroups" title="os.setgroups"><tt class="xref py py-func docutils literal"><span class="pre">setgroups()</span></tt></a>, and its length is not limited to 16. The deployment target value, <tt class="xref py py-const docutils literal"><span class="pre">MACOSX_DEPLOYMENT_TARGET</span></tt>, can be obtained with <a class="reference internal" href="sysconfig.html#sysconfig.get_config_var" title="sysconfig.get_config_var"><tt class="xref py py-func docutils literal"><span class="pre">sysconfig.get_config_var()</span></tt></a>.</p> </div> </dd></dl> <dl class="function"> <dt id="os.initgroups"> <tt class="descclassname">os.</tt><tt class="descname">initgroups</tt><big>(</big><em>username</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.initgroups" title="Permalink to this definition">¶</a></dt> <dd><p>Call the system initgroups() to initialize the group access list with all of the groups of which the specified username is a member, plus the specified group id.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.7.</span></p> </dd></dl> <dl class="function"> <dt id="os.getlogin"> <tt class="descclassname">os.</tt><tt class="descname">getlogin</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getlogin" title="Permalink to this definition">¶</a></dt> <dd><p>Return the name of the user logged in on the controlling terminal of the process. For most purposes, it is more useful to use the environment variable <span class="target" id="index-2"></span><tt class="xref std std-envvar docutils literal"><span class="pre">LOGNAME</span></tt> to find out who the user is, or <tt class="docutils literal"><span class="pre">pwd.getpwuid(os.getuid())[0]</span></tt> to get the login name of the currently effective user id.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getpgid"> <tt class="descclassname">os.</tt><tt class="descname">getpgid</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.getpgid" title="Permalink to this definition">¶</a></dt> <dd><p>Return the process group id of the process with process id <em>pid</em>. If <em>pid</em> is 0, the process group id of the current process is returned.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.getpgrp"> <tt class="descclassname">os.</tt><tt class="descname">getpgrp</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getpgrp" title="Permalink to this definition">¶</a></dt> <dd><p id="index-3">Return the id of the current process group.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getpid"> <tt class="descclassname">os.</tt><tt class="descname">getpid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getpid" title="Permalink to this definition">¶</a></dt> <dd><p id="index-4">Return the current process id.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.getppid"> <tt class="descclassname">os.</tt><tt class="descname">getppid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getppid" title="Permalink to this definition">¶</a></dt> <dd><p id="index-5">Return the parent’s process id.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getresuid"> <tt class="descclassname">os.</tt><tt class="descname">getresuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getresuid" title="Permalink to this definition">¶</a></dt> <dd><p>Return a tuple (ruid, euid, suid) denoting the current process’s real, effective, and saved user ids.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.7.</span></p> </dd></dl> <dl class="function"> <dt id="os.getresgid"> <tt class="descclassname">os.</tt><tt class="descname">getresgid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getresgid" title="Permalink to this definition">¶</a></dt> <dd><p>Return a tuple (rgid, egid, sgid) denoting the current process’s real, effective, and saved group ids.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.7.</span></p> </dd></dl> <dl class="function"> <dt id="os.getuid"> <tt class="descclassname">os.</tt><tt class="descname">getuid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getuid" title="Permalink to this definition">¶</a></dt> <dd><p id="index-6">Return the current process’s user id.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getenv"> <tt class="descclassname">os.</tt><tt class="descname">getenv</tt><big>(</big><em>varname</em><span class="optional">[</span>, <em>value</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.getenv" title="Permalink to this definition">¶</a></dt> <dd><p>Return the value of the environment variable <em>varname</em> if it exists, or <em>value</em> if it doesn’t. <em>value</em> defaults to <tt class="docutils literal"><span class="pre">None</span></tt>.</p> <p>Availability: most flavors of Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.putenv"> <tt class="descclassname">os.</tt><tt class="descname">putenv</tt><big>(</big><em>varname</em>, <em>value</em><big>)</big><a class="headerlink" href="#os.putenv" title="Permalink to this definition">¶</a></dt> <dd><p id="index-7">Set the environment variable named <em>varname</em> to the string <em>value</em>. Such changes to the environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">os.system()</span></tt></a>, <a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or <a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a> and <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>.</p> <p>Availability: most flavors of Unix, Windows.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">On some platforms, including FreeBSD and Mac OS X, setting <tt class="docutils literal"><span class="pre">environ</span></tt> may cause memory leaks. Refer to the system documentation for putenv.</p> </div> <p>When <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> is supported, assignments to items in <tt class="docutils literal"><span class="pre">os.environ</span></tt> are automatically translated into corresponding calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a>; however, calls to <a class="reference internal" href="#os.putenv" title="os.putenv"><tt class="xref py py-func docutils literal"><span class="pre">putenv()</span></tt></a> don’t update <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it is actually preferable to assign to items of <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p> </dd></dl> <dl class="function"> <dt id="os.setegid"> <tt class="descclassname">os.</tt><tt class="descname">setegid</tt><big>(</big><em>egid</em><big>)</big><a class="headerlink" href="#os.setegid" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current process’s effective group id.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.seteuid"> <tt class="descclassname">os.</tt><tt class="descname">seteuid</tt><big>(</big><em>euid</em><big>)</big><a class="headerlink" href="#os.seteuid" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current process’s effective user id.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.setgid"> <tt class="descclassname">os.</tt><tt class="descname">setgid</tt><big>(</big><em>gid</em><big>)</big><a class="headerlink" href="#os.setgid" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current process’ group id.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.setgroups"> <tt class="descclassname">os.</tt><tt class="descname">setgroups</tt><big>(</big><em>groups</em><big>)</big><a class="headerlink" href="#os.setgroups" title="Permalink to this definition">¶</a></dt> <dd><p>Set the list of supplemental group ids associated with the current process to <em>groups</em>. <em>groups</em> must be a sequence, and each element must be an integer identifying a group. This operation is typically available only to the superuser.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.2.</span></p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">On Mac OS X, the length of <em>groups</em> may not exceed the system-defined maximum number of effective group ids, typically 16. See the documentation for <a class="reference internal" href="#os.getgroups" title="os.getgroups"><tt class="xref py py-func docutils literal"><span class="pre">getgroups()</span></tt></a> for cases where it may not return the same group list set by calling setgroups().</p> </div> </dd></dl> <dl class="function"> <dt id="os.setpgrp"> <tt class="descclassname">os.</tt><tt class="descname">setpgrp</tt><big>(</big><big>)</big><a class="headerlink" href="#os.setpgrp" title="Permalink to this definition">¶</a></dt> <dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setpgrp()</span></tt> or <tt class="xref c c-func docutils literal"><span class="pre">setpgrp(0,</span> <span class="pre">0)()</span></tt> depending on which version is implemented (if any). See the Unix manual for the semantics.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.setpgid"> <tt class="descclassname">os.</tt><tt class="descname">setpgid</tt><big>(</big><em>pid</em>, <em>pgrp</em><big>)</big><a class="headerlink" href="#os.setpgid" title="Permalink to this definition">¶</a></dt> <dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setpgid()</span></tt> to set the process group id of the process with id <em>pid</em> to the process group with id <em>pgrp</em>. See the Unix manual for the semantics.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.setregid"> <tt class="descclassname">os.</tt><tt class="descname">setregid</tt><big>(</big><em>rgid</em>, <em>egid</em><big>)</big><a class="headerlink" href="#os.setregid" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current process’s real and effective group ids.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.setresgid"> <tt class="descclassname">os.</tt><tt class="descname">setresgid</tt><big>(</big><em>rgid</em>, <em>egid</em>, <em>sgid</em><big>)</big><a class="headerlink" href="#os.setresgid" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current process’s real, effective, and saved group ids.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.7.</span></p> </dd></dl> <dl class="function"> <dt id="os.setresuid"> <tt class="descclassname">os.</tt><tt class="descname">setresuid</tt><big>(</big><em>ruid</em>, <em>euid</em>, <em>suid</em><big>)</big><a class="headerlink" href="#os.setresuid" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current process’s real, effective, and saved user ids.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.7.</span></p> </dd></dl> <dl class="function"> <dt id="os.setreuid"> <tt class="descclassname">os.</tt><tt class="descname">setreuid</tt><big>(</big><em>ruid</em>, <em>euid</em><big>)</big><a class="headerlink" href="#os.setreuid" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current process’s real and effective user ids.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getsid"> <tt class="descclassname">os.</tt><tt class="descname">getsid</tt><big>(</big><em>pid</em><big>)</big><a class="headerlink" href="#os.getsid" title="Permalink to this definition">¶</a></dt> <dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">getsid()</span></tt>. See the Unix manual for the semantics.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.4.</span></p> </dd></dl> <dl class="function"> <dt id="os.setsid"> <tt class="descclassname">os.</tt><tt class="descname">setsid</tt><big>(</big><big>)</big><a class="headerlink" href="#os.setsid" title="Permalink to this definition">¶</a></dt> <dd><p>Call the system call <tt class="xref c c-func docutils literal"><span class="pre">setsid()</span></tt>. See the Unix manual for the semantics.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.setuid"> <tt class="descclassname">os.</tt><tt class="descname">setuid</tt><big>(</big><em>uid</em><big>)</big><a class="headerlink" href="#os.setuid" title="Permalink to this definition">¶</a></dt> <dd><p id="index-8">Set the current process’s user id.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.strerror"> <tt class="descclassname">os.</tt><tt class="descname">strerror</tt><big>(</big><em>code</em><big>)</big><a class="headerlink" href="#os.strerror" title="Permalink to this definition">¶</a></dt> <dd><p>Return the error message corresponding to the error code in <em>code</em>. On platforms where <tt class="xref c c-func docutils literal"><span class="pre">strerror()</span></tt> returns <tt class="docutils literal"><span class="pre">NULL</span></tt> when given an unknown error number, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.umask"> <tt class="descclassname">os.</tt><tt class="descname">umask</tt><big>(</big><em>mask</em><big>)</big><a class="headerlink" href="#os.umask" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current numeric umask and return the previous umask.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.uname"> <tt class="descclassname">os.</tt><tt class="descname">uname</tt><big>(</big><big>)</big><a class="headerlink" href="#os.uname" title="Permalink to this definition">¶</a></dt> <dd><p id="index-9">Return a 5-tuple containing information identifying the current operating system. The tuple contains 5 strings: <tt class="docutils literal"><span class="pre">(sysname,</span> <span class="pre">nodename,</span> <span class="pre">release,</span> <span class="pre">version,</span> <span class="pre">machine)</span></tt>. Some systems truncate the nodename to 8 characters or to the leading component; a better way to get the hostname is <a class="reference internal" href="socket.html#socket.gethostname" title="socket.gethostname"><tt class="xref py py-func docutils literal"><span class="pre">socket.gethostname()</span></tt></a> or even <tt class="docutils literal"><span class="pre">socket.gethostbyaddr(socket.gethostname())</span></tt>.</p> <p>Availability: recent flavors of Unix.</p> </dd></dl> <dl class="function"> <dt id="os.unsetenv"> <tt class="descclassname">os.</tt><tt class="descname">unsetenv</tt><big>(</big><em>varname</em><big>)</big><a class="headerlink" href="#os.unsetenv" title="Permalink to this definition">¶</a></dt> <dd><p id="index-10">Unset (delete) the environment variable named <em>varname</em>. Such changes to the environment affect subprocesses started with <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">os.system()</span></tt></a>, <a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or <a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a> and <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>.</p> <p>When <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> is supported, deletion of items in <tt class="docutils literal"><span class="pre">os.environ</span></tt> is automatically translated into a corresponding call to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a>; however, calls to <a class="reference internal" href="#os.unsetenv" title="os.unsetenv"><tt class="xref py py-func docutils literal"><span class="pre">unsetenv()</span></tt></a> don’t update <tt class="docutils literal"><span class="pre">os.environ</span></tt>, so it is actually preferable to delete items of <tt class="docutils literal"><span class="pre">os.environ</span></tt>.</p> <p>Availability: most flavors of Unix, Windows.</p> </dd></dl> </div> <div class="section" id="file-object-creation"> <span id="os-newstreams"></span><h2>15.1.2. File Object Creation<a class="headerlink" href="#file-object-creation" title="Permalink to this headline">¶</a></h2> <p>These functions create new file objects. (See also <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>.)</p> <dl class="function"> <dt id="os.fdopen"> <tt class="descclassname">os.</tt><tt class="descname">fdopen</tt><big>(</big><em>fd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.fdopen" title="Permalink to this definition">¶</a></dt> <dd><p id="index-11">Return an open file object connected to the file descriptor <em>fd</em>. The <em>mode</em> and <em>bufsize</em> arguments have the same meaning as the corresponding arguments to the built-in <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> function.</p> <p>Availability: Unix, Windows.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.3: </span>When specified, the <em>mode</em> argument must now start with one of the letters <tt class="docutils literal"><span class="pre">'r'</span></tt>, <tt class="docutils literal"><span class="pre">'w'</span></tt>, or <tt class="docutils literal"><span class="pre">'a'</span></tt>, otherwise a <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.5: </span>On Unix, when the <em>mode</em> argument starts with <tt class="docutils literal"><span class="pre">'a'</span></tt>, the <em>O_APPEND</em> flag is set on the file descriptor (which the <tt class="xref c c-func docutils literal"><span class="pre">fdopen()</span></tt> implementation already does on most platforms).</p> </dd></dl> <dl class="function"> <dt id="os.popen"> <tt class="descclassname">os.</tt><tt class="descname">popen</tt><big>(</big><em>command</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.popen" title="Permalink to this definition">¶</a></dt> <dd><p>Open a pipe to or from <em>command</em>. The return value is an open file object connected to the pipe, which can be read or written depending on whether <em>mode</em> is <tt class="docutils literal"><span class="pre">'r'</span></tt> (default) or <tt class="docutils literal"><span class="pre">'w'</span></tt>. The <em>bufsize</em> argument has the same meaning as the corresponding argument to the built-in <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> function. The exit status of the command (encoded in the format specified for <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>) is available as the return value of the <a class="reference internal" href="stdtypes.html#file.close" title="file.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a> method of the file object, except that when the exit status is zero (termination without errors), <tt class="docutils literal"><span class="pre">None</span></tt> is returned.</p> <p>Availability: Unix, Windows.</p> <p class="deprecated"> <span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete. Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module. Check especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.0: </span>This function worked unreliably under Windows in earlier versions of Python. This was due to the use of the <tt class="xref c c-func docutils literal"><span class="pre">_popen()</span></tt> function from the libraries provided with Windows. Newer versions of Python do not use the broken implementation from the Windows libraries.</p> </dd></dl> <dl class="function"> <dt id="os.tmpfile"> <tt class="descclassname">os.</tt><tt class="descname">tmpfile</tt><big>(</big><big>)</big><a class="headerlink" href="#os.tmpfile" title="Permalink to this definition">¶</a></dt> <dd><p>Return a new file object opened in update mode (<tt class="docutils literal"><span class="pre">w+b</span></tt>). The file has no directory entries associated with it and will be automatically deleted once there are no file descriptors for the file.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <p>There are a number of different <tt class="xref py py-func docutils literal"><span class="pre">popen*()</span></tt> functions that provide slightly different ways to create subprocesses.</p> <p class="deprecated"> <span class="versionmodified">Deprecated since version 2.6: </span>All of the <tt class="xref py py-func docutils literal"><span class="pre">popen*()</span></tt> functions are obsolete. Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module.</p> <p>For each of the <tt class="xref py py-func docutils literal"><span class="pre">popen*()</span></tt> variants, if <em>bufsize</em> is specified, it specifies the buffer size for the I/O pipes. <em>mode</em>, if provided, should be the string <tt class="docutils literal"><span class="pre">'b'</span></tt> or <tt class="docutils literal"><span class="pre">'t'</span></tt>; on Windows this is needed to determine whether the file objects should be opened in binary or text mode. The default value for <em>mode</em> is <tt class="docutils literal"><span class="pre">'t'</span></tt>.</p> <p>Also, for each of these variants, on Unix, <em>cmd</em> may be a sequence, in which case arguments will be passed directly to the program without shell intervention (as with <a class="reference internal" href="#os.spawnv" title="os.spawnv"><tt class="xref py py-func docutils literal"><span class="pre">os.spawnv()</span></tt></a>). If <em>cmd</em> is a string it will be passed to the shell (as with <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">os.system()</span></tt></a>).</p> <p>These methods do not make it possible to retrieve the exit status from the child processes. The only way to control the input and output streams and also retrieve the return codes is to use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module; these are only available on Unix.</p> <p>For a discussion of possible deadlock conditions related to the use of these functions, see <a class="reference internal" href="popen2.html#popen2-flow-control"><em>Flow Control Issues</em></a>.</p> <dl class="function"> <dt id="os.popen2"> <tt class="descclassname">os.</tt><tt class="descname">popen2</tt><big>(</big><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.popen2" title="Permalink to this definition">¶</a></dt> <dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <tt class="docutils literal"><span class="pre">(child_stdin,</span> <span class="pre">child_stdout)</span></tt>.</p> <p class="deprecated"> <span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete. Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module. Check especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p> <p>Availability: Unix, Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.0.</span></p> </dd></dl> <dl class="function"> <dt id="os.popen3"> <tt class="descclassname">os.</tt><tt class="descname">popen3</tt><big>(</big><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.popen3" title="Permalink to this definition">¶</a></dt> <dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <tt class="docutils literal"><span class="pre">(child_stdin,</span> <span class="pre">child_stdout,</span> <span class="pre">child_stderr)</span></tt>.</p> <p class="deprecated"> <span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete. Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module. Check especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p> <p>Availability: Unix, Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.0.</span></p> </dd></dl> <dl class="function"> <dt id="os.popen4"> <tt class="descclassname">os.</tt><tt class="descname">popen4</tt><big>(</big><em>cmd</em><span class="optional">[</span>, <em>mode</em><span class="optional">[</span>, <em>bufsize</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.popen4" title="Permalink to this definition">¶</a></dt> <dd><p>Execute <em>cmd</em> as a sub-process and return the file objects <tt class="docutils literal"><span class="pre">(child_stdin,</span> <span class="pre">child_stdout_and_stderr)</span></tt>.</p> <p class="deprecated"> <span class="versionmodified">Deprecated since version 2.6: </span>This function is obsolete. Use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module. Check especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.</p> <p>Availability: Unix, Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.0.</span></p> </dd></dl> <p>(Note that <tt class="docutils literal"><span class="pre">child_stdin,</span> <span class="pre">child_stdout,</span> <span class="pre">and</span> <span class="pre">child_stderr</span></tt> are named from the point of view of the child process, so <em>child_stdin</em> is the child’s standard input.)</p> <p>This functionality is also available in the <a class="reference internal" href="popen2.html#module-popen2" title="popen2: Subprocesses with accessible standard I/O streams. (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">popen2</span></tt></a> module using functions of the same names, but the return values of those functions have a different order.</p> </div> <div class="section" id="file-descriptor-operations"> <span id="os-fd-ops"></span><h2>15.1.3. File Descriptor Operations<a class="headerlink" href="#file-descriptor-operations" title="Permalink to this headline">¶</a></h2> <p>These functions operate on I/O streams referenced using file descriptors.</p> <p>File descriptors are small integers corresponding to a file that has been opened by the current process. For example, standard input is usually file descriptor 0, standard output is 1, and standard error is 2. Further files opened by a process will then be assigned 3, 4, 5, and so forth. The name “file descriptor” is slightly deceptive; on Unix platforms, sockets and pipes are also referenced by file descriptors.</p> <p>The <a class="reference internal" href="stdtypes.html#file.fileno" title="file.fileno"><tt class="xref py py-meth docutils literal"><span class="pre">fileno()</span></tt></a> method can be used to obtain the file descriptor associated with a file object when required. Note that using the file descriptor directly will bypass the file object methods, ignoring aspects such as internal buffering of data.</p> <dl class="function"> <dt id="os.close"> <tt class="descclassname">os.</tt><tt class="descname">close</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.close" title="Permalink to this definition">¶</a></dt> <dd><p>Close file descriptor <em>fd</em>.</p> <p>Availability: Unix, Windows.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This function is intended for low-level I/O and must be applied to a file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>. To close a “file object” returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or <a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, use its <a class="reference internal" href="stdtypes.html#file.close" title="file.close"><tt class="xref py py-meth docutils literal"><span class="pre">close()</span></tt></a> method.</p> </div> </dd></dl> <dl class="function"> <dt id="os.closerange"> <tt class="descclassname">os.</tt><tt class="descname">closerange</tt><big>(</big><em>fd_low</em>, <em>fd_high</em><big>)</big><a class="headerlink" href="#os.closerange" title="Permalink to this definition">¶</a></dt> <dd><p>Close all file descriptors from <em>fd_low</em> (inclusive) to <em>fd_high</em> (exclusive), ignoring errors. Equivalent to:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">for</span> <span class="n">fd</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="n">fd_low</span><span class="p">,</span> <span class="n">fd_high</span><span class="p">):</span> <span class="k">try</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">close</span><span class="p">(</span><span class="n">fd</span><span class="p">)</span> <span class="k">except</span> <span class="ne">OSError</span><span class="p">:</span> <span class="k">pass</span> </pre></div> </div> <p>Availability: Unix, Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.6.</span></p> </dd></dl> <dl class="function"> <dt id="os.dup"> <tt class="descclassname">os.</tt><tt class="descname">dup</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.dup" title="Permalink to this definition">¶</a></dt> <dd><p>Return a duplicate of file descriptor <em>fd</em>.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.dup2"> <tt class="descclassname">os.</tt><tt class="descname">dup2</tt><big>(</big><em>fd</em>, <em>fd2</em><big>)</big><a class="headerlink" href="#os.dup2" title="Permalink to this definition">¶</a></dt> <dd><p>Duplicate file descriptor <em>fd</em> to <em>fd2</em>, closing the latter first if necessary.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.fchmod"> <tt class="descclassname">os.</tt><tt class="descname">fchmod</tt><big>(</big><em>fd</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.fchmod" title="Permalink to this definition">¶</a></dt> <dd><p>Change the mode of the file given by <em>fd</em> to the numeric <em>mode</em>. See the docs for <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a> for possible values of <em>mode</em>.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.6.</span></p> </dd></dl> <dl class="function"> <dt id="os.fchown"> <tt class="descclassname">os.</tt><tt class="descname">fchown</tt><big>(</big><em>fd</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.fchown" title="Permalink to this definition">¶</a></dt> <dd><p>Change the owner and group id of the file given by <em>fd</em> to the numeric <em>uid</em> and <em>gid</em>. To leave one of the ids unchanged, set it to -1.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.6.</span></p> </dd></dl> <dl class="function"> <dt id="os.fdatasync"> <tt class="descclassname">os.</tt><tt class="descname">fdatasync</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fdatasync" title="Permalink to this definition">¶</a></dt> <dd><p>Force write of file with filedescriptor <em>fd</em> to disk. Does not force update of metadata.</p> <p>Availability: Unix.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This function is not available on MacOS.</p> </div> </dd></dl> <dl class="function"> <dt id="os.fpathconf"> <tt class="descclassname">os.</tt><tt class="descname">fpathconf</tt><big>(</big><em>fd</em>, <em>name</em><big>)</big><a class="headerlink" href="#os.fpathconf" title="Permalink to this definition">¶</a></dt> <dd><p>Return system configuration information relevant to an open file. <em>name</em> specifies the configuration value to retrieve; it may be a string which is the name of a defined system value; these names are specified in a number of standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms define additional names as well. The names known to the host operating system are given in the <tt class="docutils literal"><span class="pre">pathconf_names</span></tt> dictionary. For configuration variables not included in that mapping, passing an integer for <em>name</em> is also accepted.</p> <p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised. If a specific value for <em>name</em> is not supported by the host system, even if it is included in <tt class="docutils literal"><span class="pre">pathconf_names</span></tt>, an <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with <a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.fstat"> <tt class="descclassname">os.</tt><tt class="descname">fstat</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fstat" title="Permalink to this definition">¶</a></dt> <dd><p>Return status for file descriptor <em>fd</em>, like <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.fstatvfs"> <tt class="descclassname">os.</tt><tt class="descname">fstatvfs</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fstatvfs" title="Permalink to this definition">¶</a></dt> <dd><p>Return information about the filesystem containing the file associated with file descriptor <em>fd</em>, like <a class="reference internal" href="statvfs.html#module-statvfs" title="statvfs: Constants for interpreting the result of os.statvfs(). (deprecated)"><tt class="xref py py-func docutils literal"><span class="pre">statvfs()</span></tt></a>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.fsync"> <tt class="descclassname">os.</tt><tt class="descname">fsync</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fsync" title="Permalink to this definition">¶</a></dt> <dd><p>Force write of file with filedescriptor <em>fd</em> to disk. On Unix, this calls the native <tt class="xref c c-func docutils literal"><span class="pre">fsync()</span></tt> function; on Windows, the MS <tt class="xref c c-func docutils literal"><span class="pre">_commit()</span></tt> function.</p> <p>If you’re starting with a Python file object <em>f</em>, first do <tt class="docutils literal"><span class="pre">f.flush()</span></tt>, and then do <tt class="docutils literal"><span class="pre">os.fsync(f.fileno())</span></tt>, to ensure that all internal buffers associated with <em>f</em> are written to disk.</p> <p>Availability: Unix, and Windows starting in 2.2.3.</p> </dd></dl> <dl class="function"> <dt id="os.ftruncate"> <tt class="descclassname">os.</tt><tt class="descname">ftruncate</tt><big>(</big><em>fd</em>, <em>length</em><big>)</big><a class="headerlink" href="#os.ftruncate" title="Permalink to this definition">¶</a></dt> <dd><p>Truncate the file corresponding to file descriptor <em>fd</em>, so that it is at most <em>length</em> bytes in size.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.isatty"> <tt class="descclassname">os.</tt><tt class="descname">isatty</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.isatty" title="Permalink to this definition">¶</a></dt> <dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the file descriptor <em>fd</em> is open and connected to a tty(-like) device, else <tt class="docutils literal"><span class="pre">False</span></tt>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.lseek"> <tt class="descclassname">os.</tt><tt class="descname">lseek</tt><big>(</big><em>fd</em>, <em>pos</em>, <em>how</em><big>)</big><a class="headerlink" href="#os.lseek" title="Permalink to this definition">¶</a></dt> <dd><p>Set the current position of file descriptor <em>fd</em> to position <em>pos</em>, modified by <em>how</em>: <a class="reference internal" href="#os.SEEK_SET" title="os.SEEK_SET"><tt class="xref py py-const docutils literal"><span class="pre">SEEK_SET</span></tt></a> or <tt class="docutils literal"><span class="pre">0</span></tt> to set the position relative to the beginning of the file; <a class="reference internal" href="#os.SEEK_CUR" title="os.SEEK_CUR"><tt class="xref py py-const docutils literal"><span class="pre">SEEK_CUR</span></tt></a> or <tt class="docutils literal"><span class="pre">1</span></tt> to set it relative to the current position; <a class="reference internal" href="#os.SEEK_END" title="os.SEEK_END"><tt class="xref py py-const docutils literal"><span class="pre">os.SEEK_END</span></tt></a> or <tt class="docutils literal"><span class="pre">2</span></tt> to set it relative to the end of the file.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="data"> <dt id="os.SEEK_SET"> <tt class="descclassname">os.</tt><tt class="descname">SEEK_SET</tt><a class="headerlink" href="#os.SEEK_SET" title="Permalink to this definition">¶</a></dt> <dt id="os.SEEK_CUR"> <tt class="descclassname">os.</tt><tt class="descname">SEEK_CUR</tt><a class="headerlink" href="#os.SEEK_CUR" title="Permalink to this definition">¶</a></dt> <dt id="os.SEEK_END"> <tt class="descclassname">os.</tt><tt class="descname">SEEK_END</tt><a class="headerlink" href="#os.SEEK_END" title="Permalink to this definition">¶</a></dt> <dd><p>Parameters to the <a class="reference internal" href="#os.lseek" title="os.lseek"><tt class="xref py py-func docutils literal"><span class="pre">lseek()</span></tt></a> function. Their values are 0, 1, and 2, respectively.</p> <p>Availability: Windows, Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.5.</span></p> </dd></dl> <dl class="function"> <dt id="os.open"> <tt class="descclassname">os.</tt><tt class="descname">open</tt><big>(</big><em>file</em>, <em>flags</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.open" title="Permalink to this definition">¶</a></dt> <dd><p>Open the file <em>file</em> and set various flags according to <em>flags</em> and possibly its mode according to <em>mode</em>. The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0777</span></tt> (octal), and the current umask value is first masked out. Return the file descriptor for the newly opened file.</p> <p>For a description of the flag and mode values, see the C run-time documentation; flag constants (like <a class="reference internal" href="#os.O_RDONLY" title="os.O_RDONLY"><tt class="xref py py-const docutils literal"><span class="pre">O_RDONLY</span></tt></a> and <a class="reference internal" href="#os.O_WRONLY" title="os.O_WRONLY"><tt class="xref py py-const docutils literal"><span class="pre">O_WRONLY</span></tt></a>) are defined in this module too (see <a class="reference internal" href="#open-constants"><em>open() flag constants</em></a>). In particular, on Windows adding <a class="reference internal" href="#os.O_BINARY" title="os.O_BINARY"><tt class="xref py py-const docutils literal"><span class="pre">O_BINARY</span></tt></a> is needed to open files in binary mode.</p> <p>Availability: Unix, Windows.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This function is intended for low-level I/O. For normal usage, use the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a>, which returns a “file object” with <a class="reference internal" href="stdtypes.html#file.read" title="file.read"><tt class="xref py py-meth docutils literal"><span class="pre">read()</span></tt></a> and <a class="reference internal" href="stdtypes.html#file.write" title="file.write"><tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt></a> methods (and many more). To wrap a file descriptor in a “file object”, use <a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>.</p> </div> </dd></dl> <dl class="function"> <dt id="os.openpty"> <tt class="descclassname">os.</tt><tt class="descname">openpty</tt><big>(</big><big>)</big><a class="headerlink" href="#os.openpty" title="Permalink to this definition">¶</a></dt> <dd><p id="index-12">Open a new pseudo-terminal pair. Return a pair of file descriptors <tt class="docutils literal"><span class="pre">(master,</span> <span class="pre">slave)</span></tt> for the pty and the tty, respectively. For a (slightly) more portable approach, use the <a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Linux. (Linux)"><tt class="xref py py-mod docutils literal"><span class="pre">pty</span></tt></a> module.</p> <p>Availability: some flavors of Unix.</p> </dd></dl> <dl class="function"> <dt id="os.pipe"> <tt class="descclassname">os.</tt><tt class="descname">pipe</tt><big>(</big><big>)</big><a class="headerlink" href="#os.pipe" title="Permalink to this definition">¶</a></dt> <dd><p>Create a pipe. Return a pair of file descriptors <tt class="docutils literal"><span class="pre">(r,</span> <span class="pre">w)</span></tt> usable for reading and writing, respectively.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.read"> <tt class="descclassname">os.</tt><tt class="descname">read</tt><big>(</big><em>fd</em>, <em>n</em><big>)</big><a class="headerlink" href="#os.read" title="Permalink to this definition">¶</a></dt> <dd><p>Read at most <em>n</em> bytes from file descriptor <em>fd</em>. Return a string containing the bytes read. If the end of the file referred to by <em>fd</em> has been reached, an empty string is returned.</p> <p>Availability: Unix, Windows.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This function is intended for low-level I/O and must be applied to a file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>. To read a “file object” returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or <a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, or <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdin</span></tt></a>, use its <a class="reference internal" href="stdtypes.html#file.read" title="file.read"><tt class="xref py py-meth docutils literal"><span class="pre">read()</span></tt></a> or <a class="reference internal" href="stdtypes.html#file.readline" title="file.readline"><tt class="xref py py-meth docutils literal"><span class="pre">readline()</span></tt></a> methods.</p> </div> </dd></dl> <dl class="function"> <dt id="os.tcgetpgrp"> <tt class="descclassname">os.</tt><tt class="descname">tcgetpgrp</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.tcgetpgrp" title="Permalink to this definition">¶</a></dt> <dd><p>Return the process group associated with the terminal given by <em>fd</em> (an open file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a>).</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.tcsetpgrp"> <tt class="descclassname">os.</tt><tt class="descname">tcsetpgrp</tt><big>(</big><em>fd</em>, <em>pg</em><big>)</big><a class="headerlink" href="#os.tcsetpgrp" title="Permalink to this definition">¶</a></dt> <dd><p>Set the process group associated with the terminal given by <em>fd</em> (an open file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a>) to <em>pg</em>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.ttyname"> <tt class="descclassname">os.</tt><tt class="descname">ttyname</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.ttyname" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string which specifies the terminal device associated with file descriptor <em>fd</em>. If <em>fd</em> is not associated with a terminal device, an exception is raised.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.write"> <tt class="descclassname">os.</tt><tt class="descname">write</tt><big>(</big><em>fd</em>, <em>str</em><big>)</big><a class="headerlink" href="#os.write" title="Permalink to this definition">¶</a></dt> <dd><p>Write the string <em>str</em> to file descriptor <em>fd</em>. Return the number of bytes actually written.</p> <p>Availability: Unix, Windows.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This function is intended for low-level I/O and must be applied to a file descriptor as returned by <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">os.open()</span></tt></a> or <a class="reference internal" href="#os.pipe" title="os.pipe"><tt class="xref py py-func docutils literal"><span class="pre">pipe()</span></tt></a>. To write a “file object” returned by the built-in function <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> or by <a class="reference internal" href="#os.popen" title="os.popen"><tt class="xref py py-func docutils literal"><span class="pre">popen()</span></tt></a> or <a class="reference internal" href="#os.fdopen" title="os.fdopen"><tt class="xref py py-func docutils literal"><span class="pre">fdopen()</span></tt></a>, or <a class="reference internal" href="sys.html#sys.stdout" title="sys.stdout"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdout</span></tt></a> or <a class="reference internal" href="sys.html#sys.stderr" title="sys.stderr"><tt class="xref py py-data docutils literal"><span class="pre">sys.stderr</span></tt></a>, use its <a class="reference internal" href="stdtypes.html#file.write" title="file.write"><tt class="xref py py-meth docutils literal"><span class="pre">write()</span></tt></a> method.</p> </div> </dd></dl> <div class="section" id="open-flag-constants"> <span id="open-constants"></span><h3>15.1.3.1. <tt class="docutils literal"><span class="pre">open()</span></tt> flag constants<a class="headerlink" href="#open-flag-constants" title="Permalink to this headline">¶</a></h3> <p>The following constants are options for the <em>flags</em> parameter to the <a class="reference internal" href="#os.open" title="os.open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> function. They can be combined using the bitwise OR operator <tt class="docutils literal"><span class="pre">|</span></tt>. Some of them are not available on all platforms. For descriptions of their availability and use, consult the <em class="manpage">open(2)</em> manual page on Unix or <a class="reference external" href="http://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx">the MSDN</a> on Windows.</p> <dl class="data"> <dt id="os.O_RDONLY"> <tt class="descclassname">os.</tt><tt class="descname">O_RDONLY</tt><a class="headerlink" href="#os.O_RDONLY" title="Permalink to this definition">¶</a></dt> <dt id="os.O_WRONLY"> <tt class="descclassname">os.</tt><tt class="descname">O_WRONLY</tt><a class="headerlink" href="#os.O_WRONLY" title="Permalink to this definition">¶</a></dt> <dt id="os.O_RDWR"> <tt class="descclassname">os.</tt><tt class="descname">O_RDWR</tt><a class="headerlink" href="#os.O_RDWR" title="Permalink to this definition">¶</a></dt> <dt id="os.O_APPEND"> <tt class="descclassname">os.</tt><tt class="descname">O_APPEND</tt><a class="headerlink" href="#os.O_APPEND" title="Permalink to this definition">¶</a></dt> <dt id="os.O_CREAT"> <tt class="descclassname">os.</tt><tt class="descname">O_CREAT</tt><a class="headerlink" href="#os.O_CREAT" title="Permalink to this definition">¶</a></dt> <dt id="os.O_EXCL"> <tt class="descclassname">os.</tt><tt class="descname">O_EXCL</tt><a class="headerlink" href="#os.O_EXCL" title="Permalink to this definition">¶</a></dt> <dt id="os.O_TRUNC"> <tt class="descclassname">os.</tt><tt class="descname">O_TRUNC</tt><a class="headerlink" href="#os.O_TRUNC" title="Permalink to this definition">¶</a></dt> <dd><p>These constants are available on Unix and Windows.</p> </dd></dl> <dl class="data"> <dt id="os.O_DSYNC"> <tt class="descclassname">os.</tt><tt class="descname">O_DSYNC</tt><a class="headerlink" href="#os.O_DSYNC" title="Permalink to this definition">¶</a></dt> <dt id="os.O_RSYNC"> <tt class="descclassname">os.</tt><tt class="descname">O_RSYNC</tt><a class="headerlink" href="#os.O_RSYNC" title="Permalink to this definition">¶</a></dt> <dt id="os.O_SYNC"> <tt class="descclassname">os.</tt><tt class="descname">O_SYNC</tt><a class="headerlink" href="#os.O_SYNC" title="Permalink to this definition">¶</a></dt> <dt id="os.O_NDELAY"> <tt class="descclassname">os.</tt><tt class="descname">O_NDELAY</tt><a class="headerlink" href="#os.O_NDELAY" title="Permalink to this definition">¶</a></dt> <dt id="os.O_NONBLOCK"> <tt class="descclassname">os.</tt><tt class="descname">O_NONBLOCK</tt><a class="headerlink" href="#os.O_NONBLOCK" title="Permalink to this definition">¶</a></dt> <dt id="os.O_NOCTTY"> <tt class="descclassname">os.</tt><tt class="descname">O_NOCTTY</tt><a class="headerlink" href="#os.O_NOCTTY" title="Permalink to this definition">¶</a></dt> <dt id="os.O_SHLOCK"> <tt class="descclassname">os.</tt><tt class="descname">O_SHLOCK</tt><a class="headerlink" href="#os.O_SHLOCK" title="Permalink to this definition">¶</a></dt> <dt id="os.O_EXLOCK"> <tt class="descclassname">os.</tt><tt class="descname">O_EXLOCK</tt><a class="headerlink" href="#os.O_EXLOCK" title="Permalink to this definition">¶</a></dt> <dd><p>These constants are only available on Unix.</p> </dd></dl> <dl class="data"> <dt id="os.O_BINARY"> <tt class="descclassname">os.</tt><tt class="descname">O_BINARY</tt><a class="headerlink" href="#os.O_BINARY" title="Permalink to this definition">¶</a></dt> <dt id="os.O_NOINHERIT"> <tt class="descclassname">os.</tt><tt class="descname">O_NOINHERIT</tt><a class="headerlink" href="#os.O_NOINHERIT" title="Permalink to this definition">¶</a></dt> <dt id="os.O_SHORT_LIVED"> <tt class="descclassname">os.</tt><tt class="descname">O_SHORT_LIVED</tt><a class="headerlink" href="#os.O_SHORT_LIVED" title="Permalink to this definition">¶</a></dt> <dt id="os.O_TEMPORARY"> <tt class="descclassname">os.</tt><tt class="descname">O_TEMPORARY</tt><a class="headerlink" href="#os.O_TEMPORARY" title="Permalink to this definition">¶</a></dt> <dt id="os.O_RANDOM"> <tt class="descclassname">os.</tt><tt class="descname">O_RANDOM</tt><a class="headerlink" href="#os.O_RANDOM" title="Permalink to this definition">¶</a></dt> <dt id="os.O_SEQUENTIAL"> <tt class="descclassname">os.</tt><tt class="descname">O_SEQUENTIAL</tt><a class="headerlink" href="#os.O_SEQUENTIAL" title="Permalink to this definition">¶</a></dt> <dt id="os.O_TEXT"> <tt class="descclassname">os.</tt><tt class="descname">O_TEXT</tt><a class="headerlink" href="#os.O_TEXT" title="Permalink to this definition">¶</a></dt> <dd><p>These constants are only available on Windows.</p> </dd></dl> <dl class="data"> <dt id="os.O_ASYNC"> <tt class="descclassname">os.</tt><tt class="descname">O_ASYNC</tt><a class="headerlink" href="#os.O_ASYNC" title="Permalink to this definition">¶</a></dt> <dt id="os.O_DIRECT"> <tt class="descclassname">os.</tt><tt class="descname">O_DIRECT</tt><a class="headerlink" href="#os.O_DIRECT" title="Permalink to this definition">¶</a></dt> <dt id="os.O_DIRECTORY"> <tt class="descclassname">os.</tt><tt class="descname">O_DIRECTORY</tt><a class="headerlink" href="#os.O_DIRECTORY" title="Permalink to this definition">¶</a></dt> <dt id="os.O_NOFOLLOW"> <tt class="descclassname">os.</tt><tt class="descname">O_NOFOLLOW</tt><a class="headerlink" href="#os.O_NOFOLLOW" title="Permalink to this definition">¶</a></dt> <dt id="os.O_NOATIME"> <tt class="descclassname">os.</tt><tt class="descname">O_NOATIME</tt><a class="headerlink" href="#os.O_NOATIME" title="Permalink to this definition">¶</a></dt> <dd><p>These constants are GNU extensions and not present if they are not defined by the C library.</p> </dd></dl> </div> </div> <div class="section" id="files-and-directories"> <span id="os-file-dir"></span><h2>15.1.4. Files and Directories<a class="headerlink" href="#files-and-directories" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="os.access"> <tt class="descclassname">os.</tt><tt class="descname">access</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.access" title="Permalink to this definition">¶</a></dt> <dd><p>Use the real uid/gid to test for access to <em>path</em>. Note that most operations will use the effective uid/gid, therefore this routine can be used in a suid/sgid environment to test if the invoking user has the specified access to <em>path</em>. <em>mode</em> should be <a class="reference internal" href="#os.F_OK" title="os.F_OK"><tt class="xref py py-const docutils literal"><span class="pre">F_OK</span></tt></a> to test the existence of <em>path</em>, or it can be the inclusive OR of one or more of <a class="reference internal" href="#os.R_OK" title="os.R_OK"><tt class="xref py py-const docutils literal"><span class="pre">R_OK</span></tt></a>, <a class="reference internal" href="#os.W_OK" title="os.W_OK"><tt class="xref py py-const docutils literal"><span class="pre">W_OK</span></tt></a>, and <a class="reference internal" href="#os.X_OK" title="os.X_OK"><tt class="xref py py-const docutils literal"><span class="pre">X_OK</span></tt></a> to test permissions. Return <a class="reference internal" href="constants.html#True" title="True"><tt class="xref py py-const docutils literal"><span class="pre">True</span></tt></a> if access is allowed, <a class="reference internal" href="constants.html#False" title="False"><tt class="xref py py-const docutils literal"><span class="pre">False</span></tt></a> if not. See the Unix man page <em class="manpage">access(2)</em> for more information.</p> <p>Availability: Unix, Windows.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p>Using <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to check if a user is authorized to e.g. open a file before actually doing so using <a class="reference internal" href="functions.html#open" title="open"><tt class="xref py py-func docutils literal"><span class="pre">open()</span></tt></a> creates a security hole, because the user might exploit the short time interval between checking and opening the file to manipulate it. It’s preferable to use <a class="reference internal" href="../glossary.html#term-eafp"><em class="xref std std-term">EAFP</em></a> techniques. For example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">if</span> <span class="n">os</span><span class="o">.</span><span class="n">access</span><span class="p">(</span><span class="s">"myfile"</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">R_OK</span><span class="p">):</span> <span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="s">"myfile"</span><span class="p">)</span> <span class="k">as</span> <span class="n">fp</span><span class="p">:</span> <span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> <span class="k">return</span> <span class="s">"some default data"</span> </pre></div> </div> <p>is better written as:</p> <div class="last highlight-python"><div class="highlight"><pre><span class="k">try</span><span class="p">:</span> <span class="n">fp</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s">"myfile"</span><span class="p">)</span> <span class="k">except</span> <span class="ne">IOError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span> <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">errno</span> <span class="o">==</span> <span class="n">errno</span><span class="o">.</span><span class="n">EACCES</span><span class="p">:</span> <span class="k">return</span> <span class="s">"some default data"</span> <span class="c"># Not a permission error.</span> <span class="k">raise</span> <span class="k">else</span><span class="p">:</span> <span class="k">with</span> <span class="n">fp</span><span class="p">:</span> <span class="k">return</span> <span class="n">fp</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> </pre></div> </div> </div> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">I/O operations may fail even when <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> indicates that they would succeed, particularly for operations on network filesystems which may have permissions semantics beyond the usual POSIX permission-bit model.</p> </div> </dd></dl> <dl class="data"> <dt id="os.F_OK"> <tt class="descclassname">os.</tt><tt class="descname">F_OK</tt><a class="headerlink" href="#os.F_OK" title="Permalink to this definition">¶</a></dt> <dd><p>Value to pass as the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to test the existence of <em>path</em>.</p> </dd></dl> <dl class="data"> <dt id="os.R_OK"> <tt class="descclassname">os.</tt><tt class="descname">R_OK</tt><a class="headerlink" href="#os.R_OK" title="Permalink to this definition">¶</a></dt> <dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to test the readability of <em>path</em>.</p> </dd></dl> <dl class="data"> <dt id="os.W_OK"> <tt class="descclassname">os.</tt><tt class="descname">W_OK</tt><a class="headerlink" href="#os.W_OK" title="Permalink to this definition">¶</a></dt> <dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to test the writability of <em>path</em>.</p> </dd></dl> <dl class="data"> <dt id="os.X_OK"> <tt class="descclassname">os.</tt><tt class="descname">X_OK</tt><a class="headerlink" href="#os.X_OK" title="Permalink to this definition">¶</a></dt> <dd><p>Value to include in the <em>mode</em> parameter of <a class="reference internal" href="#os.access" title="os.access"><tt class="xref py py-func docutils literal"><span class="pre">access()</span></tt></a> to determine if <em>path</em> can be executed.</p> </dd></dl> <dl class="function"> <dt id="os.chdir"> <tt class="descclassname">os.</tt><tt class="descname">chdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.chdir" title="Permalink to this definition">¶</a></dt> <dd><p id="index-13">Change the current working directory to <em>path</em>.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.fchdir"> <tt class="descclassname">os.</tt><tt class="descname">fchdir</tt><big>(</big><em>fd</em><big>)</big><a class="headerlink" href="#os.fchdir" title="Permalink to this definition">¶</a></dt> <dd><p>Change the current working directory to the directory represented by the file descriptor <em>fd</em>. The descriptor must refer to an opened directory, not an open file.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.getcwd"> <tt class="descclassname">os.</tt><tt class="descname">getcwd</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getcwd" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string representing the current working directory.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.getcwdu"> <tt class="descclassname">os.</tt><tt class="descname">getcwdu</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getcwdu" title="Permalink to this definition">¶</a></dt> <dd><p>Return a Unicode object representing the current working directory.</p> <p>Availability: Unix, Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.chflags"> <tt class="descclassname">os.</tt><tt class="descname">chflags</tt><big>(</big><em>path</em>, <em>flags</em><big>)</big><a class="headerlink" href="#os.chflags" title="Permalink to this definition">¶</a></dt> <dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>. <em>flags</em> may take a combination (bitwise OR) of the following values (as defined in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> module):</p> <ul class="simple"> <li><a class="reference internal" href="stat.html#stat.UF_NODUMP" title="stat.UF_NODUMP"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_NODUMP</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.UF_IMMUTABLE" title="stat.UF_IMMUTABLE"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_IMMUTABLE</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.UF_APPEND" title="stat.UF_APPEND"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_APPEND</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.UF_OPAQUE" title="stat.UF_OPAQUE"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_OPAQUE</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.UF_NOUNLINK" title="stat.UF_NOUNLINK"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_NOUNLINK</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.UF_COMPRESSED" title="stat.UF_COMPRESSED"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_COMPRESSED</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.UF_HIDDEN" title="stat.UF_HIDDEN"><tt class="xref py py-data docutils literal"><span class="pre">stat.UF_HIDDEN</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.SF_ARCHIVED" title="stat.SF_ARCHIVED"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_ARCHIVED</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.SF_IMMUTABLE" title="stat.SF_IMMUTABLE"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_IMMUTABLE</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.SF_APPEND" title="stat.SF_APPEND"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_APPEND</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.SF_NOUNLINK" title="stat.SF_NOUNLINK"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_NOUNLINK</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.SF_SNAPSHOT" title="stat.SF_SNAPSHOT"><tt class="xref py py-data docutils literal"><span class="pre">stat.SF_SNAPSHOT</span></tt></a></li> </ul> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.6.</span></p> </dd></dl> <dl class="function"> <dt id="os.chroot"> <tt class="descclassname">os.</tt><tt class="descname">chroot</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.chroot" title="Permalink to this definition">¶</a></dt> <dd><p>Change the root directory of the current process to <em>path</em>. Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.2.</span></p> </dd></dl> <dl class="function"> <dt id="os.chmod"> <tt class="descclassname">os.</tt><tt class="descname">chmod</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.chmod" title="Permalink to this definition">¶</a></dt> <dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. <em>mode</em> may take one of the following values (as defined in the <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> module) or bitwise ORed combinations of them:</p> <ul class="simple"> <li><a class="reference internal" href="stat.html#stat.S_ISUID" title="stat.S_ISUID"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISUID</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_ISGID" title="stat.S_ISGID"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISGID</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_ENFMT" title="stat.S_ENFMT"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ENFMT</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_ISVTX" title="stat.S_ISVTX"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_ISVTX</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IREAD" title="stat.S_IREAD"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IREAD</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IWRITE" title="stat.S_IWRITE"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWRITE</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IEXEC" title="stat.S_IEXEC"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IEXEC</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IRWXU" title="stat.S_IRWXU"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXU</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IRUSR" title="stat.S_IRUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRUSR</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IWUSR" title="stat.S_IWUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWUSR</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IXUSR" title="stat.S_IXUSR"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXUSR</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IRWXG" title="stat.S_IRWXG"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXG</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IRGRP" title="stat.S_IRGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRGRP</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IWGRP" title="stat.S_IWGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWGRP</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IXGRP" title="stat.S_IXGRP"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXGRP</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IRWXO" title="stat.S_IRWXO"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IRWXO</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IROTH" title="stat.S_IROTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IROTH</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IWOTH" title="stat.S_IWOTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IWOTH</span></tt></a></li> <li><a class="reference internal" href="stat.html#stat.S_IXOTH" title="stat.S_IXOTH"><tt class="xref py py-data docutils literal"><span class="pre">stat.S_IXOTH</span></tt></a></li> </ul> <p>Availability: Unix, Windows.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Although Windows supports <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a>, you can only set the file’s read-only flag with it (via the <tt class="docutils literal"><span class="pre">stat.S_IWRITE</span></tt> and <tt class="docutils literal"><span class="pre">stat.S_IREAD</span></tt> constants or a corresponding integer value). All other bits are ignored.</p> </div> </dd></dl> <dl class="function"> <dt id="os.chown"> <tt class="descclassname">os.</tt><tt class="descname">chown</tt><big>(</big><em>path</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.chown" title="Permalink to this definition">¶</a></dt> <dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. To leave one of the ids unchanged, set it to -1.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.lchflags"> <tt class="descclassname">os.</tt><tt class="descname">lchflags</tt><big>(</big><em>path</em>, <em>flags</em><big>)</big><a class="headerlink" href="#os.lchflags" title="Permalink to this definition">¶</a></dt> <dd><p>Set the flags of <em>path</em> to the numeric <em>flags</em>, like <a class="reference internal" href="#os.chflags" title="os.chflags"><tt class="xref py py-func docutils literal"><span class="pre">chflags()</span></tt></a>, but do not follow symbolic links.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.6.</span></p> </dd></dl> <dl class="function"> <dt id="os.lchmod"> <tt class="descclassname">os.</tt><tt class="descname">lchmod</tt><big>(</big><em>path</em>, <em>mode</em><big>)</big><a class="headerlink" href="#os.lchmod" title="Permalink to this definition">¶</a></dt> <dd><p>Change the mode of <em>path</em> to the numeric <em>mode</em>. If path is a symlink, this affects the symlink rather than the target. See the docs for <a class="reference internal" href="#os.chmod" title="os.chmod"><tt class="xref py py-func docutils literal"><span class="pre">chmod()</span></tt></a> for possible values of <em>mode</em>.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.6.</span></p> </dd></dl> <dl class="function"> <dt id="os.lchown"> <tt class="descclassname">os.</tt><tt class="descname">lchown</tt><big>(</big><em>path</em>, <em>uid</em>, <em>gid</em><big>)</big><a class="headerlink" href="#os.lchown" title="Permalink to this definition">¶</a></dt> <dd><p>Change the owner and group id of <em>path</em> to the numeric <em>uid</em> and <em>gid</em>. This function will not follow symbolic links.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.link"> <tt class="descclassname">os.</tt><tt class="descname">link</tt><big>(</big><em>source</em>, <em>link_name</em><big>)</big><a class="headerlink" href="#os.link" title="Permalink to this definition">¶</a></dt> <dd><p>Create a hard link pointing to <em>source</em> named <em>link_name</em>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.listdir"> <tt class="descclassname">os.</tt><tt class="descname">listdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.listdir" title="Permalink to this definition">¶</a></dt> <dd><p>Return a list containing the names of the entries in the directory given by <em>path</em>. The list is in arbitrary order. It does not include the special entries <tt class="docutils literal"><span class="pre">'.'</span></tt> and <tt class="docutils literal"><span class="pre">'..'</span></tt> even if they are present in the directory.</p> <p>Availability: Unix, Windows.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.3: </span>On Windows NT/2k/XP and Unix, if <em>path</em> is a Unicode object, the result will be a list of Unicode objects. Undecodable filenames will still be returned as string objects.</p> </dd></dl> <dl class="function"> <dt id="os.lstat"> <tt class="descclassname">os.</tt><tt class="descname">lstat</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.lstat" title="Permalink to this definition">¶</a></dt> <dd><p>Perform the equivalent of an <tt class="xref c c-func docutils literal"><span class="pre">lstat()</span></tt> system call on the given path. Similar to <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>, but does not follow symbolic links. On platforms that do not support symbolic links, this is an alias for <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>.</p> </dd></dl> <dl class="function"> <dt id="os.mkfifo"> <tt class="descclassname">os.</tt><tt class="descname">mkfifo</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mkfifo" title="Permalink to this definition">¶</a></dt> <dd><p>Create a FIFO (a named pipe) named <em>path</em> with numeric mode <em>mode</em>. The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0666</span></tt> (octal). The current umask value is first masked out from the mode.</p> <p>Availability: Unix.</p> <p>FIFOs are pipes that can be accessed like regular files. FIFOs exist until they are deleted (for example with <a class="reference internal" href="#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">os.unlink()</span></tt></a>). Generally, FIFOs are used as rendezvous between “client” and “server” type processes: the server opens the FIFO for reading, and the client opens it for writing. Note that <a class="reference internal" href="#os.mkfifo" title="os.mkfifo"><tt class="xref py py-func docutils literal"><span class="pre">mkfifo()</span></tt></a> doesn’t open the FIFO — it just creates the rendezvous point.</p> </dd></dl> <dl class="function"> <dt id="os.mknod"> <tt class="descclassname">os.</tt><tt class="descname">mknod</tt><big>(</big><em>filename</em><span class="optional">[</span>, <em>mode=0600</em><span class="optional">[</span>, <em>device=0</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mknod" title="Permalink to this definition">¶</a></dt> <dd><p>Create a filesystem node (file, device special file or named pipe) named <em>filename</em>. <em>mode</em> specifies both the permissions to use and the type of node to be created, being combined (bitwise OR) with one of <tt class="docutils literal"><span class="pre">stat.S_IFREG</span></tt>, <tt class="docutils literal"><span class="pre">stat.S_IFCHR</span></tt>, <tt class="docutils literal"><span class="pre">stat.S_IFBLK</span></tt>, and <tt class="docutils literal"><span class="pre">stat.S_IFIFO</span></tt> (those constants are available in <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a>). For <tt class="docutils literal"><span class="pre">stat.S_IFCHR</span></tt> and <tt class="docutils literal"><span class="pre">stat.S_IFBLK</span></tt>, <em>device</em> defines the newly created device special file (probably using <a class="reference internal" href="#os.makedev" title="os.makedev"><tt class="xref py py-func docutils literal"><span class="pre">os.makedev()</span></tt></a>), otherwise it is ignored.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.major"> <tt class="descclassname">os.</tt><tt class="descname">major</tt><big>(</big><em>device</em><big>)</big><a class="headerlink" href="#os.major" title="Permalink to this definition">¶</a></dt> <dd><p>Extract the device major number from a raw device number (usually the <tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt> or <tt class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></tt> field from <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt>).</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.minor"> <tt class="descclassname">os.</tt><tt class="descname">minor</tt><big>(</big><em>device</em><big>)</big><a class="headerlink" href="#os.minor" title="Permalink to this definition">¶</a></dt> <dd><p>Extract the device minor number from a raw device number (usually the <tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt> or <tt class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></tt> field from <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt>).</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.makedev"> <tt class="descclassname">os.</tt><tt class="descname">makedev</tt><big>(</big><em>major</em>, <em>minor</em><big>)</big><a class="headerlink" href="#os.makedev" title="Permalink to this definition">¶</a></dt> <dd><p>Compose a raw device number from the major and minor device numbers.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.mkdir"> <tt class="descclassname">os.</tt><tt class="descname">mkdir</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.mkdir" title="Permalink to this definition">¶</a></dt> <dd><p>Create a directory named <em>path</em> with numeric mode <em>mode</em>. The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0777</span></tt> (octal). On some systems, <em>mode</em> is ignored. Where it is used, the current umask value is first masked out. If the directory already exists, <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p> <p>It is also possible to create temporary directories; see the <a class="reference internal" href="tempfile.html#module-tempfile" title="tempfile: Generate temporary files and directories."><tt class="xref py py-mod docutils literal"><span class="pre">tempfile</span></tt></a> module’s <a class="reference internal" href="tempfile.html#tempfile.mkdtemp" title="tempfile.mkdtemp"><tt class="xref py py-func docutils literal"><span class="pre">tempfile.mkdtemp()</span></tt></a> function.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.makedirs"> <tt class="descclassname">os.</tt><tt class="descname">makedirs</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>mode</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.makedirs" title="Permalink to this definition">¶</a></dt> <dd><p id="index-14">Recursive directory creation function. Like <a class="reference internal" href="#os.mkdir" title="os.mkdir"><tt class="xref py py-func docutils literal"><span class="pre">mkdir()</span></tt></a>, but makes all intermediate-level directories needed to contain the leaf directory. Raises an <a class="reference internal" href="#os.error" title="os.error"><tt class="xref py py-exc docutils literal"><span class="pre">error</span></tt></a> exception if the leaf directory already exists or cannot be created. The default <em>mode</em> is <tt class="docutils literal"><span class="pre">0777</span></tt> (octal). On some systems, <em>mode</em> is ignored. Where it is used, the current umask value is first masked out.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last"><a class="reference internal" href="#os.makedirs" title="os.makedirs"><tt class="xref py py-func docutils literal"><span class="pre">makedirs()</span></tt></a> will become confused if the path elements to create include <a class="reference internal" href="#os.pardir" title="os.pardir"><tt class="xref py py-data docutils literal"><span class="pre">os.pardir</span></tt></a>.</p> </div> <p class="versionadded"> <span class="versionmodified">New in version 1.5.2.</span></p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.3: </span>This function now handles UNC paths correctly.</p> </dd></dl> <dl class="function"> <dt id="os.pathconf"> <tt class="descclassname">os.</tt><tt class="descname">pathconf</tt><big>(</big><em>path</em>, <em>name</em><big>)</big><a class="headerlink" href="#os.pathconf" title="Permalink to this definition">¶</a></dt> <dd><p>Return system configuration information relevant to a named file. <em>name</em> specifies the configuration value to retrieve; it may be a string which is the name of a defined system value; these names are specified in a number of standards (POSIX.1, Unix 95, Unix 98, and others). Some platforms define additional names as well. The names known to the host operating system are given in the <tt class="docutils literal"><span class="pre">pathconf_names</span></tt> dictionary. For configuration variables not included in that mapping, passing an integer for <em>name</em> is also accepted.</p> <p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised. If a specific value for <em>name</em> is not supported by the host system, even if it is included in <tt class="docutils literal"><span class="pre">pathconf_names</span></tt>, an <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with <a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="data"> <dt id="os.pathconf_names"> <tt class="descclassname">os.</tt><tt class="descname">pathconf_names</tt><a class="headerlink" href="#os.pathconf_names" title="Permalink to this definition">¶</a></dt> <dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.pathconf" title="os.pathconf"><tt class="xref py py-func docutils literal"><span class="pre">pathconf()</span></tt></a> and <a class="reference internal" href="#os.fpathconf" title="os.fpathconf"><tt class="xref py py-func docutils literal"><span class="pre">fpathconf()</span></tt></a> to the integer values defined for those names by the host operating system. This can be used to determine the set of names known to the system. Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.readlink"> <tt class="descclassname">os.</tt><tt class="descname">readlink</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.readlink" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string representing the path to which the symbolic link points. The result may be either an absolute or relative pathname; if it is relative, it may be converted to an absolute pathname using <tt class="docutils literal"><span class="pre">os.path.join(os.path.dirname(path),</span> <span class="pre">result)</span></tt>.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.6: </span>If the <em>path</em> is a Unicode object the result will also be a Unicode object.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.remove"> <tt class="descclassname">os.</tt><tt class="descname">remove</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.remove" title="Permalink to this definition">¶</a></dt> <dd><p>Remove (delete) the file <em>path</em>. If <em>path</em> is a directory, <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised; see <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> below to remove a directory. This is identical to the <a class="reference internal" href="#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">unlink()</span></tt></a> function documented below. On Windows, attempting to remove a file that is in use causes an exception to be raised; on Unix, the directory entry is removed but the storage allocated to the file is not made available until the original file is no longer in use.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.removedirs"> <tt class="descclassname">os.</tt><tt class="descname">removedirs</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.removedirs" title="Permalink to this definition">¶</a></dt> <dd><p id="index-15">Remove directories recursively. Works like <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> except that, if the leaf directory is successfully removed, <a class="reference internal" href="#os.removedirs" title="os.removedirs"><tt class="xref py py-func docutils literal"><span class="pre">removedirs()</span></tt></a> tries to successively remove every parent directory mentioned in <em>path</em> until an error is raised (which is ignored, because it generally means that a parent directory is not empty). For example, <tt class="docutils literal"><span class="pre">os.removedirs('foo/bar/baz')</span></tt> will first remove the directory <tt class="docutils literal"><span class="pre">'foo/bar/baz'</span></tt>, and then remove <tt class="docutils literal"><span class="pre">'foo/bar'</span></tt> and <tt class="docutils literal"><span class="pre">'foo'</span></tt> if they are empty. Raises <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> if the leaf directory could not be successfully removed.</p> <p class="versionadded"> <span class="versionmodified">New in version 1.5.2.</span></p> </dd></dl> <dl class="function"> <dt id="os.rename"> <tt class="descclassname">os.</tt><tt class="descname">rename</tt><big>(</big><em>src</em>, <em>dst</em><big>)</big><a class="headerlink" href="#os.rename" title="Permalink to this definition">¶</a></dt> <dd><p>Rename the file or directory <em>src</em> to <em>dst</em>. If <em>dst</em> is a directory, <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> will be raised. On Unix, if <em>dst</em> exists and is a file, it will be replaced silently if the user has permission. The operation may fail on some Unix flavors if <em>src</em> and <em>dst</em> are on different filesystems. If successful, the renaming will be an atomic operation (this is a POSIX requirement). On Windows, if <em>dst</em> already exists, <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> will be raised even if it is a file; there may be no way to implement an atomic rename when <em>dst</em> names an existing file.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.renames"> <tt class="descclassname">os.</tt><tt class="descname">renames</tt><big>(</big><em>old</em>, <em>new</em><big>)</big><a class="headerlink" href="#os.renames" title="Permalink to this definition">¶</a></dt> <dd><p>Recursive directory or file renaming function. Works like <a class="reference internal" href="#os.rename" title="os.rename"><tt class="xref py py-func docutils literal"><span class="pre">rename()</span></tt></a>, except creation of any intermediate directories needed to make the new pathname good is attempted first. After the rename, directories corresponding to rightmost path segments of the old name will be pruned away using <a class="reference internal" href="#os.removedirs" title="os.removedirs"><tt class="xref py py-func docutils literal"><span class="pre">removedirs()</span></tt></a>.</p> <p class="versionadded"> <span class="versionmodified">New in version 1.5.2.</span></p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">This function can fail with the new directory structure made if you lack permissions needed to remove the leaf directory or file.</p> </div> </dd></dl> <dl class="function"> <dt id="os.rmdir"> <tt class="descclassname">os.</tt><tt class="descname">rmdir</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.rmdir" title="Permalink to this definition">¶</a></dt> <dd><p>Remove (delete) the directory <em>path</em>. Only works when the directory is empty, otherwise, <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised. In order to remove whole directory trees, <a class="reference internal" href="shutil.html#shutil.rmtree" title="shutil.rmtree"><tt class="xref py py-func docutils literal"><span class="pre">shutil.rmtree()</span></tt></a> can be used.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.stat"> <tt class="descclassname">os.</tt><tt class="descname">stat</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.stat" title="Permalink to this definition">¶</a></dt> <dd><p>Perform the equivalent of a <tt class="xref c c-func docutils literal"><span class="pre">stat()</span></tt> system call on the given path. (This function follows symlinks; to stat a symlink use <a class="reference internal" href="#os.lstat" title="os.lstat"><tt class="xref py py-func docutils literal"><span class="pre">lstat()</span></tt></a>.)</p> <p>The return value is an object whose attributes correspond to the members of the <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure, namely:</p> <ul class="simple"> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_mode</span></tt> - protection bits,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_ino</span></tt> - inode number,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt> - device,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_nlink</span></tt> - number of hard links,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_uid</span></tt> - user id of owner,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_gid</span></tt> - group id of owner,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_size</span></tt> - size of file, in bytes,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt> - time of most recent access,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt> - time of most recent content modification,</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt> - platform dependent; time of most recent metadata change on Unix, or the time of creation on Windows)</li> </ul> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.3: </span>If <a class="reference internal" href="#os.stat_float_times" title="os.stat_float_times"><tt class="xref py py-func docutils literal"><span class="pre">stat_float_times()</span></tt></a> returns <tt class="docutils literal"><span class="pre">True</span></tt>, the time values are floats, measuring seconds. Fractions of a second may be reported if the system supports that. On Mac OS, the times are always floats. See <a class="reference internal" href="#os.stat_float_times" title="os.stat_float_times"><tt class="xref py py-func docutils literal"><span class="pre">stat_float_times()</span></tt></a> for further discussion.</p> <p>On some Unix systems (such as Linux), the following attributes may also be available:</p> <ul class="simple"> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_blocks</span></tt> - number of blocks allocated for file</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_blksize</span></tt> - filesystem blocksize</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_rdev</span></tt> - type of device if an inode device</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_flags</span></tt> - user defined flags for file</li> </ul> <p>On other Unix systems (such as FreeBSD), the following attributes may be available (but may be only filled out if root tries to use them):</p> <ul class="simple"> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_gen</span></tt> - file generation number</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_birthtime</span></tt> - time of file creation</li> </ul> <p>On Mac OS systems, the following attributes may also be available:</p> <ul class="simple"> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_rsize</span></tt></li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_creator</span></tt></li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_type</span></tt></li> </ul> <p>On RISCOS systems, the following attributes are also available:</p> <ul class="simple"> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_ftype</span></tt> (file type)</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_attrs</span></tt> (attributes)</li> <li><tt class="xref py py-attr docutils literal"><span class="pre">st_obtype</span></tt> (object type).</li> </ul> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The exact meaning and resolution of the <tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt>, and <tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt> attributes depend on the operating system and the file system. For example, on Windows systems using the FAT or FAT32 file systems, <tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt> has 2-second resolution, and <tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt> has only 1-day resolution. See your operating system documentation for details.</p> </div> <p>For backward compatibility, the return value of <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> is also accessible as a tuple of at least 10 integers giving the most important (and portable) members of the <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure, in the order <tt class="xref py py-attr docutils literal"><span class="pre">st_mode</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_ino</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_dev</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_nlink</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_uid</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_gid</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_size</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_atime</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_mtime</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">st_ctime</span></tt>. More items may be added at the end by some implementations.</p> <p id="index-16">The standard module <a class="reference internal" href="stat.html#module-stat" title="stat: Utilities for interpreting the results of os.stat(), os.lstat() and os.fstat()."><tt class="xref py py-mod docutils literal"><span class="pre">stat</span></tt></a> defines functions and constants that are useful for extracting information from a <tt class="xref c c-type docutils literal"><span class="pre">stat</span></tt> structure. (On Windows, some items are filled with dummy values.)</p> <p>Example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="kn">import</span> <span class="nn">os</span> <span class="gp">>>> </span><span class="n">statinfo</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">stat</span><span class="p">(</span><span class="s">'somefile.txt'</span><span class="p">)</span> <span class="gp">>>> </span><span class="n">statinfo</span> <span class="go">(33188, 422511, 769, 1, 1032, 100, 926, 1105022698,1105022732, 1105022732)</span> <span class="gp">>>> </span><span class="n">statinfo</span><span class="o">.</span><span class="n">st_size</span> <span class="go">926</span> </pre></div> </div> <p>Availability: Unix, Windows.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.2: </span>Added access to values as attributes of the returned object.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.5: </span>Added <tt class="xref py py-attr docutils literal"><span class="pre">st_gen</span></tt> and <tt class="xref py py-attr docutils literal"><span class="pre">st_birthtime</span></tt>.</p> </dd></dl> <dl class="function"> <dt id="os.stat_float_times"> <tt class="descclassname">os.</tt><tt class="descname">stat_float_times</tt><big>(</big><span class="optional">[</span><em>newvalue</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.stat_float_times" title="Permalink to this definition">¶</a></dt> <dd><p>Determine whether <tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt> represents time stamps as float objects. If <em>newvalue</em> is <tt class="docutils literal"><span class="pre">True</span></tt>, future calls to <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> return floats, if it is <tt class="docutils literal"><span class="pre">False</span></tt>, future calls return ints. If <em>newvalue</em> is omitted, return the current setting.</p> <p>For compatibility with older Python versions, accessing <tt class="xref py py-class docutils literal"><span class="pre">stat_result</span></tt> as a tuple always returns integers.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.5: </span>Python now returns float values by default. Applications which do not work correctly with floating point time stamps can use this function to restore the old behaviour.</p> <p>The resolution of the timestamps (that is the smallest possible fraction) depends on the system. Some systems only support second resolution; on these systems, the fraction will always be zero.</p> <p>It is recommended that this setting is only changed at program startup time in the <em>__main__</em> module; libraries should never change this setting. If an application uses a library that works incorrectly if floating point time stamps are processed, this application should turn the feature off until the library has been corrected.</p> </dd></dl> <dl class="function"> <dt id="os.statvfs"> <tt class="descclassname">os.</tt><tt class="descname">statvfs</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.statvfs" title="Permalink to this definition">¶</a></dt> <dd><p>Perform a <tt class="xref c c-func docutils literal"><span class="pre">statvfs()</span></tt> system call on the given path. The return value is an object whose attributes describe the filesystem on the given path, and correspond to the members of the <tt class="xref c c-type docutils literal"><span class="pre">statvfs</span></tt> structure, namely: <tt class="xref py py-attr docutils literal"><span class="pre">f_bsize</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_frsize</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_blocks</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_bfree</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_bavail</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_files</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_ffree</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_favail</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_flag</span></tt>, <tt class="xref py py-attr docutils literal"><span class="pre">f_namemax</span></tt>.</p> <p id="index-17">For backward compatibility, the return value is also accessible as a tuple whose values correspond to the attributes, in the order given above. The standard module <a class="reference internal" href="statvfs.html#module-statvfs" title="statvfs: Constants for interpreting the result of os.statvfs(). (deprecated)"><tt class="xref py py-mod docutils literal"><span class="pre">statvfs</span></tt></a> defines constants that are useful for extracting information from a <tt class="xref c c-type docutils literal"><span class="pre">statvfs</span></tt> structure when accessing it as a sequence; this remains useful when writing code that needs to work with versions of Python that don’t support accessing the fields as attributes.</p> <p>Availability: Unix.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.2: </span>Added access to values as attributes of the returned object.</p> </dd></dl> <dl class="function"> <dt id="os.symlink"> <tt class="descclassname">os.</tt><tt class="descname">symlink</tt><big>(</big><em>source</em>, <em>link_name</em><big>)</big><a class="headerlink" href="#os.symlink" title="Permalink to this definition">¶</a></dt> <dd><p>Create a symbolic link pointing to <em>source</em> named <em>link_name</em>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.tempnam"> <tt class="descclassname">os.</tt><tt class="descname">tempnam</tt><big>(</big><span class="optional">[</span><em>dir</em><span class="optional">[</span>, <em>prefix</em><span class="optional">]</span><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.tempnam" title="Permalink to this definition">¶</a></dt> <dd><p>Return a unique path name that is reasonable for creating a temporary file. This will be an absolute path that names a potential directory entry in the directory <em>dir</em> or a common location for temporary files if <em>dir</em> is omitted or <tt class="docutils literal"><span class="pre">None</span></tt>. If given and not <tt class="docutils literal"><span class="pre">None</span></tt>, <em>prefix</em> is used to provide a short prefix to the filename. Applications are responsible for properly creating and managing files created using paths returned by <a class="reference internal" href="#os.tempnam" title="os.tempnam"><tt class="xref py py-func docutils literal"><span class="pre">tempnam()</span></tt></a>; no automatic cleanup is provided. On Unix, the environment variable <span class="target" id="index-18"></span><tt class="xref std std-envvar docutils literal"><span class="pre">TMPDIR</span></tt> overrides <em>dir</em>, while on Windows <span class="target" id="index-19"></span><tt class="xref std std-envvar docutils literal"><span class="pre">TMP</span></tt> is used. The specific behavior of this function depends on the C library implementation; some aspects are underspecified in system documentation.</p> <div class="admonition warning"> <p class="first admonition-title">Warning</p> <p class="last">Use of <a class="reference internal" href="#os.tempnam" title="os.tempnam"><tt class="xref py py-func docutils literal"><span class="pre">tempnam()</span></tt></a> is vulnerable to symlink attacks; consider using <a class="reference internal" href="#os.tmpfile" title="os.tmpfile"><tt class="xref py py-func docutils literal"><span class="pre">tmpfile()</span></tt></a> (section <a class="reference internal" href="#os-newstreams"><em>File Object Creation</em></a>) instead.</p> </div> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.tmpnam"> <tt class="descclassname">os.</tt><tt class="descname">tmpnam</tt><big>(</big><big>)</big><a class="headerlink" href="#os.tmpnam" title="Permalink to this definition">¶</a></dt> <dd><p>Return a unique path name that is reasonable for creating a temporary file. This will be an absolute path that names a potential directory entry in a common location for temporary files. Applications are responsible for properly creating and managing files created using paths returned by <a class="reference internal" href="#os.tmpnam" title="os.tmpnam"><tt class="xref py py-func docutils literal"><span class="pre">tmpnam()</span></tt></a>; no automatic cleanup is provided.</p> <div class="admonition warning"> <p class="first admonition-title">Warning</p> <p class="last">Use of <a class="reference internal" href="#os.tmpnam" title="os.tmpnam"><tt class="xref py py-func docutils literal"><span class="pre">tmpnam()</span></tt></a> is vulnerable to symlink attacks; consider using <a class="reference internal" href="#os.tmpfile" title="os.tmpfile"><tt class="xref py py-func docutils literal"><span class="pre">tmpfile()</span></tt></a> (section <a class="reference internal" href="#os-newstreams"><em>File Object Creation</em></a>) instead.</p> </div> <p>Availability: Unix, Windows. This function probably shouldn’t be used on Windows, though: Microsoft’s implementation of <a class="reference internal" href="#os.tmpnam" title="os.tmpnam"><tt class="xref py py-func docutils literal"><span class="pre">tmpnam()</span></tt></a> always creates a name in the root directory of the current drive, and that’s generally a poor location for a temp file (depending on privileges, you may not even be able to open a file using this name).</p> </dd></dl> <dl class="data"> <dt id="os.TMP_MAX"> <tt class="descclassname">os.</tt><tt class="descname">TMP_MAX</tt><a class="headerlink" href="#os.TMP_MAX" title="Permalink to this definition">¶</a></dt> <dd><p>The maximum number of unique names that <a class="reference internal" href="#os.tmpnam" title="os.tmpnam"><tt class="xref py py-func docutils literal"><span class="pre">tmpnam()</span></tt></a> will generate before reusing names.</p> </dd></dl> <dl class="function"> <dt id="os.unlink"> <tt class="descclassname">os.</tt><tt class="descname">unlink</tt><big>(</big><em>path</em><big>)</big><a class="headerlink" href="#os.unlink" title="Permalink to this definition">¶</a></dt> <dd><p>Remove (delete) the file <em>path</em>. This is the same function as <a class="reference internal" href="#os.remove" title="os.remove"><tt class="xref py py-func docutils literal"><span class="pre">remove()</span></tt></a>; the <a class="reference internal" href="#os.unlink" title="os.unlink"><tt class="xref py py-func docutils literal"><span class="pre">unlink()</span></tt></a> name is its traditional Unix name.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.utime"> <tt class="descclassname">os.</tt><tt class="descname">utime</tt><big>(</big><em>path</em>, <em>times</em><big>)</big><a class="headerlink" href="#os.utime" title="Permalink to this definition">¶</a></dt> <dd><p>Set the access and modified times of the file specified by <em>path</em>. If <em>times</em> is <tt class="docutils literal"><span class="pre">None</span></tt>, then the file’s access and modified times are set to the current time. (The effect is similar to running the Unix program <strong class="program">touch</strong> on the path.) Otherwise, <em>times</em> must be a 2-tuple of numbers, of the form <tt class="docutils literal"><span class="pre">(atime,</span> <span class="pre">mtime)</span></tt> which is used to set the access and modified times, respectively. Whether a directory can be given for <em>path</em> depends on whether the operating system implements directories as files (for example, Windows does not). Note that the exact times you set here may not be returned by a subsequent <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a> call, depending on the resolution with which your operating system records access and modification times; see <a class="reference internal" href="#os.stat" title="os.stat"><tt class="xref py py-func docutils literal"><span class="pre">stat()</span></tt></a>.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.0: </span>Added support for <tt class="docutils literal"><span class="pre">None</span></tt> for <em>times</em>.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.walk"> <tt class="descclassname">os.</tt><tt class="descname">walk</tt><big>(</big><em>top</em>, <em>topdown=True</em>, <em>onerror=None</em>, <em>followlinks=False</em><big>)</big><a class="headerlink" href="#os.walk" title="Permalink to this definition">¶</a></dt> <dd><p id="index-20">Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory <em>top</em> (including <em>top</em> itself), it yields a 3-tuple <tt class="docutils literal"><span class="pre">(dirpath,</span> <span class="pre">dirnames,</span> <span class="pre">filenames)</span></tt>.</p> <p><em>dirpath</em> is a string, the path to the directory. <em>dirnames</em> is a list of the names of the subdirectories in <em>dirpath</em> (excluding <tt class="docutils literal"><span class="pre">'.'</span></tt> and <tt class="docutils literal"><span class="pre">'..'</span></tt>). <em>filenames</em> is a list of the names of the non-directory files in <em>dirpath</em>. Note that the names in the lists contain no path components. To get a full path (which begins with <em>top</em>) to a file or directory in <em>dirpath</em>, do <tt class="docutils literal"><span class="pre">os.path.join(dirpath,</span> <span class="pre">name)</span></tt>.</p> <p>If optional argument <em>topdown</em> is <tt class="docutils literal"><span class="pre">True</span></tt> or not specified, the triple for a directory is generated before the triples for any of its subdirectories (directories are generated top-down). If <em>topdown</em> is <tt class="docutils literal"><span class="pre">False</span></tt>, the triple for a directory is generated after the triples for all of its subdirectories (directories are generated bottom-up).</p> <p>When <em>topdown</em> is <tt class="docutils literal"><span class="pre">True</span></tt>, the caller can modify the <em>dirnames</em> list in-place (perhaps using <a class="reference internal" href="../reference/simple_stmts.html#del"><tt class="xref std std-keyword docutils literal"><span class="pre">del</span></tt></a> or slice assignment), and <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> will only recurse into the subdirectories whose names remain in <em>dirnames</em>; this can be used to prune the search, impose a specific order of visiting, or even to inform <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> about directories the caller creates or renames before it resumes <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> again. Modifying <em>dirnames</em> when <em>topdown</em> is <tt class="docutils literal"><span class="pre">False</span></tt> is ineffective, because in bottom-up mode the directories in <em>dirnames</em> are generated before <em>dirpath</em> itself is generated.</p> <p>By default, errors from the <a class="reference internal" href="#os.listdir" title="os.listdir"><tt class="xref py py-func docutils literal"><span class="pre">listdir()</span></tt></a> call are ignored. If optional argument <em>onerror</em> is specified, it should be a function; it will be called with one argument, an <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> instance. It can report the error to continue with the walk, or raise the exception to abort the walk. Note that the filename is available as the <tt class="docutils literal"><span class="pre">filename</span></tt> attribute of the exception object.</p> <p>By default, <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> will not walk down into symbolic links that resolve to directories. Set <em>followlinks</em> to <tt class="docutils literal"><span class="pre">True</span></tt> to visit directories pointed to by symlinks, on systems that support them.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.6: </span>The <em>followlinks</em> parameter.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Be aware that setting <em>followlinks</em> to <tt class="docutils literal"><span class="pre">True</span></tt> can lead to infinite recursion if a link points to a parent directory of itself. <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> does not keep track of the directories it visited already.</p> </div> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">If you pass a relative pathname, don’t change the current working directory between resumptions of <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a>. <a class="reference internal" href="#os.walk" title="os.walk"><tt class="xref py py-func docutils literal"><span class="pre">walk()</span></tt></a> never changes the current directory, and assumes that its caller doesn’t either.</p> </div> <p>This example displays the number of bytes taken by non-directory files in each directory under the starting directory, except that it doesn’t look under any CVS subdirectory:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span> <span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">join</span><span class="p">,</span> <span class="n">getsize</span> <span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="s">'python/Lib/email'</span><span class="p">):</span> <span class="k">print</span> <span class="n">root</span><span class="p">,</span> <span class="s">"consumes"</span><span class="p">,</span> <span class="k">print</span> <span class="nb">sum</span><span class="p">(</span><span class="n">getsize</span><span class="p">(</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">),</span> <span class="k">print</span> <span class="s">"bytes in"</span><span class="p">,</span> <span class="nb">len</span><span class="p">(</span><span class="n">files</span><span class="p">),</span> <span class="s">"non-directory files"</span> <span class="k">if</span> <span class="s">'CVS'</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span> <span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="s">'CVS'</span><span class="p">)</span> <span class="c"># don't visit CVS directories</span> </pre></div> </div> <p>In the next example, walking the tree bottom-up is essential: <a class="reference internal" href="#os.rmdir" title="os.rmdir"><tt class="xref py py-func docutils literal"><span class="pre">rmdir()</span></tt></a> doesn’t allow deleting a directory before the directory is empty:</p> <div class="highlight-python"><div class="highlight"><pre><span class="c"># Delete everything reachable from the directory named in "top",</span> <span class="c"># assuming there are no symbolic links.</span> <span class="c"># CAUTION: This is dangerous! For example, if top == '/', it</span> <span class="c"># could delete all your disk files.</span> <span class="kn">import</span> <span class="nn">os</span> <span class="k">for</span> <span class="n">root</span><span class="p">,</span> <span class="n">dirs</span><span class="p">,</span> <span class="n">files</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">walk</span><span class="p">(</span><span class="n">top</span><span class="p">,</span> <span class="n">topdown</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">files</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> <span class="k">for</span> <span class="n">name</span> <span class="ow">in</span> <span class="n">dirs</span><span class="p">:</span> <span class="n">os</span><span class="o">.</span><span class="n">rmdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">name</span><span class="p">))</span> </pre></div> </div> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> </div> <div class="section" id="process-management"> <span id="os-process"></span><h2>15.1.5. Process Management<a class="headerlink" href="#process-management" title="Permalink to this headline">¶</a></h2> <p>These functions may be used to create and manage processes.</p> <p>The various <tt class="xref py py-func docutils literal"><span class="pre">exec*()</span></tt> functions take a list of arguments for the new program loaded into the process. In each case, the first of these arguments is passed to the new program as its own name rather than as an argument a user may have typed on a command line. For the C programmer, this is the <tt class="docutils literal"><span class="pre">argv[0]</span></tt> passed to a program’s <tt class="xref c c-func docutils literal"><span class="pre">main()</span></tt>. For example, <tt class="docutils literal"><span class="pre">os.execv('/bin/echo',</span> <span class="pre">['foo',</span> <span class="pre">'bar'])</span></tt> will only print <tt class="docutils literal"><span class="pre">bar</span></tt> on standard output; <tt class="docutils literal"><span class="pre">foo</span></tt> will seem to be ignored.</p> <dl class="function"> <dt id="os.abort"> <tt class="descclassname">os.</tt><tt class="descname">abort</tt><big>(</big><big>)</big><a class="headerlink" href="#os.abort" title="Permalink to this definition">¶</a></dt> <dd><p>Generate a <tt class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></tt> signal to the current process. On Unix, the default behavior is to produce a core dump; on Windows, the process immediately returns an exit code of <tt class="docutils literal"><span class="pre">3</span></tt>. Be aware that calling this function will not call the Python signal handler registered for <tt class="xref py py-const docutils literal"><span class="pre">SIGABRT</span></tt> with <a class="reference internal" href="signal.html#signal.signal" title="signal.signal"><tt class="xref py py-func docutils literal"><span class="pre">signal.signal()</span></tt></a>.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.execl"> <tt class="descclassname">os.</tt><tt class="descname">execl</tt><big>(</big><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.execl" title="Permalink to this definition">¶</a></dt> <dt id="os.execle"> <tt class="descclassname">os.</tt><tt class="descname">execle</tt><big>(</big><em>path</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execle" title="Permalink to this definition">¶</a></dt> <dt id="os.execlp"> <tt class="descclassname">os.</tt><tt class="descname">execlp</tt><big>(</big><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.execlp" title="Permalink to this definition">¶</a></dt> <dt id="os.execlpe"> <tt class="descclassname">os.</tt><tt class="descname">execlpe</tt><big>(</big><em>file</em>, <em>arg0</em>, <em>arg1</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execlpe" title="Permalink to this definition">¶</a></dt> <dt id="os.execv"> <tt class="descclassname">os.</tt><tt class="descname">execv</tt><big>(</big><em>path</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.execv" title="Permalink to this definition">¶</a></dt> <dt id="os.execve"> <tt class="descclassname">os.</tt><tt class="descname">execve</tt><big>(</big><em>path</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execve" title="Permalink to this definition">¶</a></dt> <dt id="os.execvp"> <tt class="descclassname">os.</tt><tt class="descname">execvp</tt><big>(</big><em>file</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.execvp" title="Permalink to this definition">¶</a></dt> <dt id="os.execvpe"> <tt class="descclassname">os.</tt><tt class="descname">execvpe</tt><big>(</big><em>file</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.execvpe" title="Permalink to this definition">¶</a></dt> <dd><p>These functions all execute a new program, replacing the current process; they do not return. On Unix, the new executable is loaded into the current process, and will have the same process id as the caller. Errors will be reported as <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> exceptions.</p> <p>The current process is replaced immediately. Open file objects and descriptors are not flushed, so if there may be data buffered on these open files, you should flush them using <tt class="xref py py-func docutils literal"><span class="pre">sys.stdout.flush()</span></tt> or <a class="reference internal" href="#os.fsync" title="os.fsync"><tt class="xref py py-func docutils literal"><span class="pre">os.fsync()</span></tt></a> before calling an <tt class="xref py py-func docutils literal"><span class="pre">exec*()</span></tt> function.</p> <p>The “l” and “v” variants of the <tt class="xref py py-func docutils literal"><span class="pre">exec*()</span></tt> functions differ in how command-line arguments are passed. The “l” variants are perhaps the easiest to work with if the number of parameters is fixed when the code is written; the individual parameters simply become additional parameters to the <tt class="xref py py-func docutils literal"><span class="pre">execl*()</span></tt> functions. The “v” variants are good when the number of parameters is variable, with the arguments being passed in a list or tuple as the <em>args</em> parameter. In either case, the arguments to the child process should start with the name of the command being run, but this is not enforced.</p> <p>The variants which include a “p” near the end (<a class="reference internal" href="#os.execlp" title="os.execlp"><tt class="xref py py-func docutils literal"><span class="pre">execlp()</span></tt></a>, <a class="reference internal" href="#os.execlpe" title="os.execlpe"><tt class="xref py py-func docutils literal"><span class="pre">execlpe()</span></tt></a>, <a class="reference internal" href="#os.execvp" title="os.execvp"><tt class="xref py py-func docutils literal"><span class="pre">execvp()</span></tt></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><tt class="xref py py-func docutils literal"><span class="pre">execvpe()</span></tt></a>) will use the <span class="target" id="index-21"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> environment variable to locate the program <em>file</em>. When the environment is being replaced (using one of the <tt class="xref py py-func docutils literal"><span class="pre">exec*e()</span></tt> variants, discussed in the next paragraph), the new environment is used as the source of the <span class="target" id="index-22"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable. The other variants, <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">execl()</span></tt></a>, <a class="reference internal" href="#os.execle" title="os.execle"><tt class="xref py py-func docutils literal"><span class="pre">execle()</span></tt></a>, <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>, and <a class="reference internal" href="#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a>, will not use the <span class="target" id="index-23"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable to locate the executable; <em>path</em> must contain an appropriate absolute or relative path.</p> <p>For <a class="reference internal" href="#os.execle" title="os.execle"><tt class="xref py py-func docutils literal"><span class="pre">execle()</span></tt></a>, <a class="reference internal" href="#os.execlpe" title="os.execlpe"><tt class="xref py py-func docutils literal"><span class="pre">execlpe()</span></tt></a>, <a class="reference internal" href="#os.execve" title="os.execve"><tt class="xref py py-func docutils literal"><span class="pre">execve()</span></tt></a>, and <a class="reference internal" href="#os.execvpe" title="os.execvpe"><tt class="xref py py-func docutils literal"><span class="pre">execvpe()</span></tt></a> (note that these all end in “e”), the <em>env</em> parameter must be a mapping which is used to define the environment variables for the new process (these are used instead of the current process’ environment); the functions <a class="reference internal" href="#os.execl" title="os.execl"><tt class="xref py py-func docutils literal"><span class="pre">execl()</span></tt></a>, <a class="reference internal" href="#os.execlp" title="os.execlp"><tt class="xref py py-func docutils literal"><span class="pre">execlp()</span></tt></a>, <a class="reference internal" href="#os.execv" title="os.execv"><tt class="xref py py-func docutils literal"><span class="pre">execv()</span></tt></a>, and <a class="reference internal" href="#os.execvp" title="os.execvp"><tt class="xref py py-func docutils literal"><span class="pre">execvp()</span></tt></a> all cause the new process to inherit the environment of the current process.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os._exit"> <tt class="descclassname">os.</tt><tt class="descname">_exit</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#os._exit" title="Permalink to this definition">¶</a></dt> <dd><p>Exit the process with status <em>n</em>, without calling cleanup handlers, flushing stdio buffers, etc.</p> <p>Availability: Unix, Windows.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">The standard way to exit is <tt class="docutils literal"><span class="pre">sys.exit(n)</span></tt>. <a class="reference internal" href="#os._exit" title="os._exit"><tt class="xref py py-func docutils literal"><span class="pre">_exit()</span></tt></a> should normally only be used in the child process after a <a class="reference internal" href="#os.fork" title="os.fork"><tt class="xref py py-func docutils literal"><span class="pre">fork()</span></tt></a>.</p> </div> </dd></dl> <p>The following exit codes are defined and can be used with <a class="reference internal" href="#os._exit" title="os._exit"><tt class="xref py py-func docutils literal"><span class="pre">_exit()</span></tt></a>, although they are not required. These are typically used for system programs written in Python, such as a mail server’s external command delivery program.</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last">Some of these may not be available on all Unix platforms, since there is some variation. These constants are defined where they are defined by the underlying platform.</p> </div> <dl class="data"> <dt id="os.EX_OK"> <tt class="descclassname">os.</tt><tt class="descname">EX_OK</tt><a class="headerlink" href="#os.EX_OK" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means no error occurred.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_USAGE"> <tt class="descclassname">os.</tt><tt class="descname">EX_USAGE</tt><a class="headerlink" href="#os.EX_USAGE" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means the command was used incorrectly, such as when the wrong number of arguments are given.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_DATAERR"> <tt class="descclassname">os.</tt><tt class="descname">EX_DATAERR</tt><a class="headerlink" href="#os.EX_DATAERR" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means the input data was incorrect.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_NOINPUT"> <tt class="descclassname">os.</tt><tt class="descname">EX_NOINPUT</tt><a class="headerlink" href="#os.EX_NOINPUT" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means an input file did not exist or was not readable.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_NOUSER"> <tt class="descclassname">os.</tt><tt class="descname">EX_NOUSER</tt><a class="headerlink" href="#os.EX_NOUSER" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means a specified user did not exist.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_NOHOST"> <tt class="descclassname">os.</tt><tt class="descname">EX_NOHOST</tt><a class="headerlink" href="#os.EX_NOHOST" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means a specified host did not exist.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_UNAVAILABLE"> <tt class="descclassname">os.</tt><tt class="descname">EX_UNAVAILABLE</tt><a class="headerlink" href="#os.EX_UNAVAILABLE" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means that a required service is unavailable.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_SOFTWARE"> <tt class="descclassname">os.</tt><tt class="descname">EX_SOFTWARE</tt><a class="headerlink" href="#os.EX_SOFTWARE" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means an internal software error was detected.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_OSERR"> <tt class="descclassname">os.</tt><tt class="descname">EX_OSERR</tt><a class="headerlink" href="#os.EX_OSERR" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means an operating system error was detected, such as the inability to fork or create a pipe.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_OSFILE"> <tt class="descclassname">os.</tt><tt class="descname">EX_OSFILE</tt><a class="headerlink" href="#os.EX_OSFILE" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means some system file did not exist, could not be opened, or had some other kind of error.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_CANTCREAT"> <tt class="descclassname">os.</tt><tt class="descname">EX_CANTCREAT</tt><a class="headerlink" href="#os.EX_CANTCREAT" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means a user specified output file could not be created.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_IOERR"> <tt class="descclassname">os.</tt><tt class="descname">EX_IOERR</tt><a class="headerlink" href="#os.EX_IOERR" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means that an error occurred while doing I/O on some file.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_TEMPFAIL"> <tt class="descclassname">os.</tt><tt class="descname">EX_TEMPFAIL</tt><a class="headerlink" href="#os.EX_TEMPFAIL" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means a temporary failure occurred. This indicates something that may not really be an error, such as a network connection that couldn’t be made during a retryable operation.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_PROTOCOL"> <tt class="descclassname">os.</tt><tt class="descname">EX_PROTOCOL</tt><a class="headerlink" href="#os.EX_PROTOCOL" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means that a protocol exchange was illegal, invalid, or not understood.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_NOPERM"> <tt class="descclassname">os.</tt><tt class="descname">EX_NOPERM</tt><a class="headerlink" href="#os.EX_NOPERM" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means that there were insufficient permissions to perform the operation (but not intended for file system problems).</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_CONFIG"> <tt class="descclassname">os.</tt><tt class="descname">EX_CONFIG</tt><a class="headerlink" href="#os.EX_CONFIG" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means that some kind of configuration error occurred.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.EX_NOTFOUND"> <tt class="descclassname">os.</tt><tt class="descname">EX_NOTFOUND</tt><a class="headerlink" href="#os.EX_NOTFOUND" title="Permalink to this definition">¶</a></dt> <dd><p>Exit code that means something like “an entry was not found”.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.fork"> <tt class="descclassname">os.</tt><tt class="descname">fork</tt><big>(</big><big>)</big><a class="headerlink" href="#os.fork" title="Permalink to this definition">¶</a></dt> <dd><p>Fork a child process. Return <tt class="docutils literal"><span class="pre">0</span></tt> in the child and the child’s process id in the parent. If an error occurs <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p> <p>Note that some platforms including FreeBSD <= 6.3, Cygwin and OS/2 EMX have known issues when using fork() from a thread.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.forkpty"> <tt class="descclassname">os.</tt><tt class="descname">forkpty</tt><big>(</big><big>)</big><a class="headerlink" href="#os.forkpty" title="Permalink to this definition">¶</a></dt> <dd><p>Fork a child process, using a new pseudo-terminal as the child’s controlling terminal. Return a pair of <tt class="docutils literal"><span class="pre">(pid,</span> <span class="pre">fd)</span></tt>, where <em>pid</em> is <tt class="docutils literal"><span class="pre">0</span></tt> in the child, the new child’s process id in the parent, and <em>fd</em> is the file descriptor of the master end of the pseudo-terminal. For a more portable approach, use the <a class="reference internal" href="pty.html#module-pty" title="pty: Pseudo-Terminal Handling for Linux. (Linux)"><tt class="xref py py-mod docutils literal"><span class="pre">pty</span></tt></a> module. If an error occurs <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised.</p> <p>Availability: some flavors of Unix.</p> </dd></dl> <dl class="function"> <dt id="os.kill"> <tt class="descclassname">os.</tt><tt class="descname">kill</tt><big>(</big><em>pid</em>, <em>sig</em><big>)</big><a class="headerlink" href="#os.kill" title="Permalink to this definition">¶</a></dt> <dd><p id="index-24">Send signal <em>sig</em> to the process <em>pid</em>. Constants for the specific signals available on the host platform are defined in the <a class="reference internal" href="signal.html#module-signal" title="signal: Set handlers for asynchronous events."><tt class="xref py py-mod docutils literal"><span class="pre">signal</span></tt></a> module.</p> <p>Windows: The <a class="reference internal" href="signal.html#signal.CTRL_C_EVENT" title="signal.CTRL_C_EVENT"><tt class="xref py py-data docutils literal"><span class="pre">signal.CTRL_C_EVENT</span></tt></a> and <a class="reference internal" href="signal.html#signal.CTRL_BREAK_EVENT" title="signal.CTRL_BREAK_EVENT"><tt class="xref py py-data docutils literal"><span class="pre">signal.CTRL_BREAK_EVENT</span></tt></a> signals are special signals which can only be sent to console processes which share a common console window, e.g., some subprocesses. Any other value for <em>sig</em> will cause the process to be unconditionally killed by the TerminateProcess API, and the exit code will be set to <em>sig</em>. The Windows version of <a class="reference internal" href="#os.kill" title="os.kill"><tt class="xref py py-func docutils literal"><span class="pre">kill()</span></tt></a> additionally takes process handles to be killed.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.7: </span>Windows support</p> </dd></dl> <dl class="function"> <dt id="os.killpg"> <tt class="descclassname">os.</tt><tt class="descname">killpg</tt><big>(</big><em>pgid</em>, <em>sig</em><big>)</big><a class="headerlink" href="#os.killpg" title="Permalink to this definition">¶</a></dt> <dd><p id="index-25">Send the signal <em>sig</em> to the process group <em>pgid</em>.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.nice"> <tt class="descclassname">os.</tt><tt class="descname">nice</tt><big>(</big><em>increment</em><big>)</big><a class="headerlink" href="#os.nice" title="Permalink to this definition">¶</a></dt> <dd><p>Add <em>increment</em> to the process’s “niceness”. Return the new niceness.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.plock"> <tt class="descclassname">os.</tt><tt class="descname">plock</tt><big>(</big><em>op</em><big>)</big><a class="headerlink" href="#os.plock" title="Permalink to this definition">¶</a></dt> <dd><p>Lock program segments into memory. The value of <em>op</em> (defined in <tt class="docutils literal"><span class="pre"><sys/lock.h></span></tt>) determines which segments are locked.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt> <tt class="descclassname">os.</tt><tt class="descname">popen</tt><big>(</big><em>...</em><big>)</big></dt> <dt> <tt class="descclassname">os.</tt><tt class="descname">popen2</tt><big>(</big><em>...</em><big>)</big></dt> <dt> <tt class="descclassname">os.</tt><tt class="descname">popen3</tt><big>(</big><em>...</em><big>)</big></dt> <dt> <tt class="descclassname">os.</tt><tt class="descname">popen4</tt><big>(</big><em>...</em><big>)</big></dt> <dd><p>Run child processes, returning opened pipes for communications. These functions are described in section <a class="reference internal" href="#os-newstreams"><em>File Object Creation</em></a>.</p> </dd></dl> <dl class="function"> <dt id="os.spawnl"> <tt class="descclassname">os.</tt><tt class="descname">spawnl</tt><big>(</big><em>mode</em>, <em>path</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.spawnl" title="Permalink to this definition">¶</a></dt> <dt id="os.spawnle"> <tt class="descclassname">os.</tt><tt class="descname">spawnle</tt><big>(</big><em>mode</em>, <em>path</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnle" title="Permalink to this definition">¶</a></dt> <dt id="os.spawnlp"> <tt class="descclassname">os.</tt><tt class="descname">spawnlp</tt><big>(</big><em>mode</em>, <em>file</em>, <em>...</em><big>)</big><a class="headerlink" href="#os.spawnlp" title="Permalink to this definition">¶</a></dt> <dt id="os.spawnlpe"> <tt class="descclassname">os.</tt><tt class="descname">spawnlpe</tt><big>(</big><em>mode</em>, <em>file</em>, <em>...</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnlpe" title="Permalink to this definition">¶</a></dt> <dt id="os.spawnv"> <tt class="descclassname">os.</tt><tt class="descname">spawnv</tt><big>(</big><em>mode</em>, <em>path</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.spawnv" title="Permalink to this definition">¶</a></dt> <dt id="os.spawnve"> <tt class="descclassname">os.</tt><tt class="descname">spawnve</tt><big>(</big><em>mode</em>, <em>path</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnve" title="Permalink to this definition">¶</a></dt> <dt id="os.spawnvp"> <tt class="descclassname">os.</tt><tt class="descname">spawnvp</tt><big>(</big><em>mode</em>, <em>file</em>, <em>args</em><big>)</big><a class="headerlink" href="#os.spawnvp" title="Permalink to this definition">¶</a></dt> <dt id="os.spawnvpe"> <tt class="descclassname">os.</tt><tt class="descname">spawnvpe</tt><big>(</big><em>mode</em>, <em>file</em>, <em>args</em>, <em>env</em><big>)</big><a class="headerlink" href="#os.spawnvpe" title="Permalink to this definition">¶</a></dt> <dd><p>Execute the program <em>path</em> in a new process.</p> <p>(Note that the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using these functions. Check especially the <a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section.)</p> <p>If <em>mode</em> is <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a>, this function returns the process id of the new process; if <em>mode</em> is <a class="reference internal" href="#os.P_WAIT" title="os.P_WAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_WAIT</span></tt></a>, returns the process’s exit code if it exits normally, or <tt class="docutils literal"><span class="pre">-signal</span></tt>, where <em>signal</em> is the signal that killed the process. On Windows, the process id will actually be the process handle, so can be used with the <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> function.</p> <p>The “l” and “v” variants of the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> functions differ in how command-line arguments are passed. The “l” variants are perhaps the easiest to work with if the number of parameters is fixed when the code is written; the individual parameters simply become additional parameters to the <tt class="xref py py-func docutils literal"><span class="pre">spawnl*()</span></tt> functions. The “v” variants are good when the number of parameters is variable, with the arguments being passed in a list or tuple as the <em>args</em> parameter. In either case, the arguments to the child process must start with the name of the command being run.</p> <p>The variants which include a second “p” near the end (<a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a>) will use the <span class="target" id="index-26"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> environment variable to locate the program <em>file</em>. When the environment is being replaced (using one of the <tt class="xref py py-func docutils literal"><span class="pre">spawn*e()</span></tt> variants, discussed in the next paragraph), the new environment is used as the source of the <span class="target" id="index-27"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable. The other variants, <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawnl()</span></tt></a>, <a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><tt class="xref py py-func docutils literal"><span class="pre">spawnv()</span></tt></a>, and <a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a>, will not use the <span class="target" id="index-28"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt> variable to locate the executable; <em>path</em> must contain an appropriate absolute or relative path.</p> <p>For <a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a>, and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a> (note that these all end in “e”), the <em>env</em> parameter must be a mapping which is used to define the environment variables for the new process (they are used instead of the current process’ environment); the functions <a class="reference internal" href="#os.spawnl" title="os.spawnl"><tt class="xref py py-func docutils literal"><span class="pre">spawnl()</span></tt></a>, <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a class="reference internal" href="#os.spawnv" title="os.spawnv"><tt class="xref py py-func docutils literal"><span class="pre">spawnv()</span></tt></a>, and <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a> all cause the new process to inherit the environment of the current process. Note that keys and values in the <em>env</em> dictionary must be strings; invalid keys or values will cause the function to fail, with a return value of <tt class="docutils literal"><span class="pre">127</span></tt>.</p> <p>As an example, the following calls to <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a> and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a> are equivalent:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">os</span> <span class="n">os</span><span class="o">.</span><span class="n">spawnlp</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s">'cp'</span><span class="p">,</span> <span class="s">'cp'</span><span class="p">,</span> <span class="s">'index.html'</span><span class="p">,</span> <span class="s">'/dev/null'</span><span class="p">)</span> <span class="n">L</span> <span class="o">=</span> <span class="p">[</span><span class="s">'cp'</span><span class="p">,</span> <span class="s">'index.html'</span><span class="p">,</span> <span class="s">'/dev/null'</span><span class="p">]</span> <span class="n">os</span><span class="o">.</span><span class="n">spawnvpe</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">P_WAIT</span><span class="p">,</span> <span class="s">'cp'</span><span class="p">,</span> <span class="n">L</span><span class="p">,</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">)</span> </pre></div> </div> <p>Availability: Unix, Windows. <a class="reference internal" href="#os.spawnlp" title="os.spawnlp"><tt class="xref py py-func docutils literal"><span class="pre">spawnlp()</span></tt></a>, <a class="reference internal" href="#os.spawnlpe" title="os.spawnlpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnlpe()</span></tt></a>, <a class="reference internal" href="#os.spawnvp" title="os.spawnvp"><tt class="xref py py-func docutils literal"><span class="pre">spawnvp()</span></tt></a> and <a class="reference internal" href="#os.spawnvpe" title="os.spawnvpe"><tt class="xref py py-func docutils literal"><span class="pre">spawnvpe()</span></tt></a> are not available on Windows. <a class="reference internal" href="#os.spawnle" title="os.spawnle"><tt class="xref py py-func docutils literal"><span class="pre">spawnle()</span></tt></a> and <a class="reference internal" href="#os.spawnve" title="os.spawnve"><tt class="xref py py-func docutils literal"><span class="pre">spawnve()</span></tt></a> are not thread-safe on Windows; we advise you to use the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module instead.</p> <p class="versionadded"> <span class="versionmodified">New in version 1.6.</span></p> </dd></dl> <dl class="data"> <dt id="os.P_NOWAIT"> <tt class="descclassname">os.</tt><tt class="descname">P_NOWAIT</tt><a class="headerlink" href="#os.P_NOWAIT" title="Permalink to this definition">¶</a></dt> <dt id="os.P_NOWAITO"> <tt class="descclassname">os.</tt><tt class="descname">P_NOWAITO</tt><a class="headerlink" href="#os.P_NOWAITO" title="Permalink to this definition">¶</a></dt> <dd><p>Possible values for the <em>mode</em> parameter to the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> family of functions. If either of these values is given, the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> functions will return as soon as the new process has been created, with the process id as the return value.</p> <p>Availability: Unix, Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 1.6.</span></p> </dd></dl> <dl class="data"> <dt id="os.P_WAIT"> <tt class="descclassname">os.</tt><tt class="descname">P_WAIT</tt><a class="headerlink" href="#os.P_WAIT" title="Permalink to this definition">¶</a></dt> <dd><p>Possible value for the <em>mode</em> parameter to the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> family of functions. If this is given as <em>mode</em>, the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> functions will not return until the new process has run to completion and will return the exit code of the process the run is successful, or <tt class="docutils literal"><span class="pre">-signal</span></tt> if a signal kills the process.</p> <p>Availability: Unix, Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 1.6.</span></p> </dd></dl> <dl class="data"> <dt id="os.P_DETACH"> <tt class="descclassname">os.</tt><tt class="descname">P_DETACH</tt><a class="headerlink" href="#os.P_DETACH" title="Permalink to this definition">¶</a></dt> <dt id="os.P_OVERLAY"> <tt class="descclassname">os.</tt><tt class="descname">P_OVERLAY</tt><a class="headerlink" href="#os.P_OVERLAY" title="Permalink to this definition">¶</a></dt> <dd><p>Possible values for the <em>mode</em> parameter to the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> family of functions. These are less portable than those listed above. <a class="reference internal" href="#os.P_DETACH" title="os.P_DETACH"><tt class="xref py py-const docutils literal"><span class="pre">P_DETACH</span></tt></a> is similar to <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a>, but the new process is detached from the console of the calling process. If <a class="reference internal" href="#os.P_OVERLAY" title="os.P_OVERLAY"><tt class="xref py py-const docutils literal"><span class="pre">P_OVERLAY</span></tt></a> is used, the current process will be replaced; the <tt class="xref py py-func docutils literal"><span class="pre">spawn*()</span></tt> function will not return.</p> <p>Availability: Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 1.6.</span></p> </dd></dl> <dl class="function"> <dt id="os.startfile"> <tt class="descclassname">os.</tt><tt class="descname">startfile</tt><big>(</big><em>path</em><span class="optional">[</span>, <em>operation</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#os.startfile" title="Permalink to this definition">¶</a></dt> <dd><p>Start a file with its associated application.</p> <p>When <em>operation</em> is not specified or <tt class="docutils literal"><span class="pre">'open'</span></tt>, this acts like double-clicking the file in Windows Explorer, or giving the file name as an argument to the <strong class="program">start</strong> command from the interactive command shell: the file is opened with whatever application (if any) its extension is associated.</p> <p>When another <em>operation</em> is given, it must be a “command verb” that specifies what should be done with the file. Common verbs documented by Microsoft are <tt class="docutils literal"><span class="pre">'print'</span></tt> and <tt class="docutils literal"><span class="pre">'edit'</span></tt> (to be used on files) as well as <tt class="docutils literal"><span class="pre">'explore'</span></tt> and <tt class="docutils literal"><span class="pre">'find'</span></tt> (to be used on directories).</p> <p><a class="reference internal" href="#os.startfile" title="os.startfile"><tt class="xref py py-func docutils literal"><span class="pre">startfile()</span></tt></a> returns as soon as the associated application is launched. There is no option to wait for the application to close, and no way to retrieve the application’s exit status. The <em>path</em> parameter is relative to the current directory. If you want to use an absolute path, make sure the first character is not a slash (<tt class="docutils literal"><span class="pre">'/'</span></tt>); the underlying Win32 <tt class="xref c c-func docutils literal"><span class="pre">ShellExecute()</span></tt> function doesn’t work if it is. Use the <a class="reference internal" href="os.path.html#os.path.normpath" title="os.path.normpath"><tt class="xref py py-func docutils literal"><span class="pre">os.path.normpath()</span></tt></a> function to ensure that the path is properly encoded for Win32.</p> <p>Availability: Windows.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.0.</span></p> <p class="versionadded"> <span class="versionmodified">New in version 2.5: </span>The <em>operation</em> parameter.</p> </dd></dl> <dl class="function"> <dt id="os.system"> <tt class="descclassname">os.</tt><tt class="descname">system</tt><big>(</big><em>command</em><big>)</big><a class="headerlink" href="#os.system" title="Permalink to this definition">¶</a></dt> <dd><p>Execute the command (a string) in a subshell. This is implemented by calling the Standard C function <tt class="xref c c-func docutils literal"><span class="pre">system()</span></tt>, and has the same limitations. Changes to <a class="reference internal" href="sys.html#sys.stdin" title="sys.stdin"><tt class="xref py py-data docutils literal"><span class="pre">sys.stdin</span></tt></a>, etc. are not reflected in the environment of the executed command.</p> <p>On Unix, the return value is the exit status of the process encoded in the format specified for <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>. Note that POSIX does not specify the meaning of the return value of the C <tt class="xref c c-func docutils literal"><span class="pre">system()</span></tt> function, so the return value of the Python function is system-dependent.</p> <p>On Windows, the return value is that returned by the system shell after running <em>command</em>, given by the Windows environment variable <span class="target" id="index-29"></span><tt class="xref std std-envvar docutils literal"><span class="pre">COMSPEC</span></tt>: on <strong class="program">command.com</strong> systems (Windows 95, 98 and ME) this is always <tt class="docutils literal"><span class="pre">0</span></tt>; on <strong class="program">cmd.exe</strong> systems (Windows NT, 2000 and XP) this is the exit status of the command run; on systems using a non-native shell, consult your shell documentation.</p> <p>The <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the <a class="reference internal" href="subprocess.html#subprocess-replacements"><em>Replacing Older Functions with the subprocess Module</em></a> section in the <a class="reference internal" href="subprocess.html#module-subprocess" title="subprocess: Subprocess management."><tt class="xref py py-mod docutils literal"><span class="pre">subprocess</span></tt></a> documentation for some helpful recipes.</p> <p>Availability: Unix, Windows.</p> </dd></dl> <dl class="function"> <dt id="os.times"> <tt class="descclassname">os.</tt><tt class="descname">times</tt><big>(</big><big>)</big><a class="headerlink" href="#os.times" title="Permalink to this definition">¶</a></dt> <dd><p>Return a 5-tuple of floating point numbers indicating accumulated (processor or other) times, in seconds. The items are: user time, system time, children’s user time, children’s system time, and elapsed real time since a fixed point in the past, in that order. See the Unix manual page <em class="manpage">times(2)</em> or the corresponding Windows Platform API documentation. On Windows, only the first two items are filled, the others are zero.</p> <p>Availability: Unix, Windows</p> </dd></dl> <dl class="function"> <dt id="os.wait"> <tt class="descclassname">os.</tt><tt class="descname">wait</tt><big>(</big><big>)</big><a class="headerlink" href="#os.wait" title="Permalink to this definition">¶</a></dt> <dd><p>Wait for completion of a child process, and return a tuple containing its pid and exit status indication: a 16-bit number, whose low byte is the signal number that killed the process, and whose high byte is the exit status (if the signal number is zero); the high bit of the low byte is set if a core file was produced.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.waitpid"> <tt class="descclassname">os.</tt><tt class="descname">waitpid</tt><big>(</big><em>pid</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.waitpid" title="Permalink to this definition">¶</a></dt> <dd><p>The details of this function differ on Unix and Windows.</p> <p>On Unix: Wait for completion of a child process given by process id <em>pid</em>, and return a tuple containing its process id and exit status indication (encoded as for <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>). The semantics of the call are affected by the value of the integer <em>options</em>, which should be <tt class="docutils literal"><span class="pre">0</span></tt> for normal operation.</p> <p>If <em>pid</em> is greater than <tt class="docutils literal"><span class="pre">0</span></tt>, <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> requests status information for that specific process. If <em>pid</em> is <tt class="docutils literal"><span class="pre">0</span></tt>, the request is for the status of any child in the process group of the current process. If <em>pid</em> is <tt class="docutils literal"><span class="pre">-1</span></tt>, the request pertains to any child of the current process. If <em>pid</em> is less than <tt class="docutils literal"><span class="pre">-1</span></tt>, status is requested for any process in the process group <tt class="docutils literal"><span class="pre">-pid</span></tt> (the absolute value of <em>pid</em>).</p> <p>An <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with the value of errno when the syscall returns -1.</p> <p>On Windows: Wait for completion of a process given by process handle <em>pid</em>, and return a tuple containing <em>pid</em>, and its exit status shifted left by 8 bits (shifting makes cross-platform use of the function easier). A <em>pid</em> less than or equal to <tt class="docutils literal"><span class="pre">0</span></tt> has no special meaning on Windows, and raises an exception. The value of integer <em>options</em> has no effect. <em>pid</em> can refer to any process whose id is known, not necessarily a child process. The <tt class="xref py py-func docutils literal"><span class="pre">spawn()</span></tt> functions called with <a class="reference internal" href="#os.P_NOWAIT" title="os.P_NOWAIT"><tt class="xref py py-const docutils literal"><span class="pre">P_NOWAIT</span></tt></a> return suitable process handles.</p> </dd></dl> <dl class="function"> <dt id="os.wait3"> <tt class="descclassname">os.</tt><tt class="descname">wait3</tt><big>(</big><em>options</em><big>)</big><a class="headerlink" href="#os.wait3" title="Permalink to this definition">¶</a></dt> <dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>, except no process id argument is given and a 3-element tuple containing the child’s process id, exit status indication, and resource usage information is returned. Refer to <a class="reference internal" href="resource.html#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><tt class="xref py py-mod docutils literal"><span class="pre">resource</span></tt></a>.<tt class="xref py py-func docutils literal"><span class="pre">getrusage()</span></tt> for details on resource usage information. The option argument is the same as that provided to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> and <a class="reference internal" href="#os.wait4" title="os.wait4"><tt class="xref py py-func docutils literal"><span class="pre">wait4()</span></tt></a>.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.5.</span></p> </dd></dl> <dl class="function"> <dt id="os.wait4"> <tt class="descclassname">os.</tt><tt class="descname">wait4</tt><big>(</big><em>pid</em>, <em>options</em><big>)</big><a class="headerlink" href="#os.wait4" title="Permalink to this definition">¶</a></dt> <dd><p>Similar to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>, except a 3-element tuple, containing the child’s process id, exit status indication, and resource usage information is returned. Refer to <a class="reference internal" href="resource.html#module-resource" title="resource: An interface to provide resource usage information on the current process. (Unix)"><tt class="xref py py-mod docutils literal"><span class="pre">resource</span></tt></a>.<tt class="xref py py-func docutils literal"><span class="pre">getrusage()</span></tt> for details on resource usage information. The arguments to <a class="reference internal" href="#os.wait4" title="os.wait4"><tt class="xref py py-func docutils literal"><span class="pre">wait4()</span></tt></a> are the same as those provided to <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a>.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.5.</span></p> </dd></dl> <dl class="data"> <dt id="os.WNOHANG"> <tt class="descclassname">os.</tt><tt class="descname">WNOHANG</tt><a class="headerlink" href="#os.WNOHANG" title="Permalink to this definition">¶</a></dt> <dd><p>The option for <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> to return immediately if no child process status is available immediately. The function returns <tt class="docutils literal"><span class="pre">(0,</span> <span class="pre">0)</span></tt> in this case.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="data"> <dt id="os.WCONTINUED"> <tt class="descclassname">os.</tt><tt class="descname">WCONTINUED</tt><a class="headerlink" href="#os.WCONTINUED" title="Permalink to this definition">¶</a></dt> <dd><p>This option causes child processes to be reported if they have been continued from a job control stop since their status was last reported.</p> <p>Availability: Some Unix systems.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="data"> <dt id="os.WUNTRACED"> <tt class="descclassname">os.</tt><tt class="descname">WUNTRACED</tt><a class="headerlink" href="#os.WUNTRACED" title="Permalink to this definition">¶</a></dt> <dd><p>This option causes child processes to be reported if they have been stopped but their current state has not been reported since they were stopped.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <p>The following functions take a process status code as returned by <a class="reference internal" href="#os.system" title="os.system"><tt class="xref py py-func docutils literal"><span class="pre">system()</span></tt></a>, <a class="reference internal" href="#os.wait" title="os.wait"><tt class="xref py py-func docutils literal"><span class="pre">wait()</span></tt></a>, or <a class="reference internal" href="#os.waitpid" title="os.waitpid"><tt class="xref py py-func docutils literal"><span class="pre">waitpid()</span></tt></a> as a parameter. They may be used to determine the disposition of a process.</p> <dl class="function"> <dt id="os.WCOREDUMP"> <tt class="descclassname">os.</tt><tt class="descname">WCOREDUMP</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WCOREDUMP" title="Permalink to this definition">¶</a></dt> <dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if a core dump was generated for the process, otherwise return <tt class="docutils literal"><span class="pre">False</span></tt>.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.WIFCONTINUED"> <tt class="descclassname">os.</tt><tt class="descname">WIFCONTINUED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFCONTINUED" title="Permalink to this definition">¶</a></dt> <dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the process has been continued from a job control stop, otherwise return <tt class="docutils literal"><span class="pre">False</span></tt>.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.WIFSTOPPED"> <tt class="descclassname">os.</tt><tt class="descname">WIFSTOPPED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFSTOPPED" title="Permalink to this definition">¶</a></dt> <dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the process has been stopped, otherwise return <tt class="docutils literal"><span class="pre">False</span></tt>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.WIFSIGNALED"> <tt class="descclassname">os.</tt><tt class="descname">WIFSIGNALED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFSIGNALED" title="Permalink to this definition">¶</a></dt> <dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the process exited due to a signal, otherwise return <tt class="docutils literal"><span class="pre">False</span></tt>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.WIFEXITED"> <tt class="descclassname">os.</tt><tt class="descname">WIFEXITED</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WIFEXITED" title="Permalink to this definition">¶</a></dt> <dd><p>Return <tt class="docutils literal"><span class="pre">True</span></tt> if the process exited using the <em class="manpage">exit(2)</em> system call, otherwise return <tt class="docutils literal"><span class="pre">False</span></tt>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.WEXITSTATUS"> <tt class="descclassname">os.</tt><tt class="descname">WEXITSTATUS</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WEXITSTATUS" title="Permalink to this definition">¶</a></dt> <dd><p>If <tt class="docutils literal"><span class="pre">WIFEXITED(status)</span></tt> is true, return the integer parameter to the <em class="manpage">exit(2)</em> system call. Otherwise, the return value is meaningless.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.WSTOPSIG"> <tt class="descclassname">os.</tt><tt class="descname">WSTOPSIG</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WSTOPSIG" title="Permalink to this definition">¶</a></dt> <dd><p>Return the signal which caused the process to stop.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.WTERMSIG"> <tt class="descclassname">os.</tt><tt class="descname">WTERMSIG</tt><big>(</big><em>status</em><big>)</big><a class="headerlink" href="#os.WTERMSIG" title="Permalink to this definition">¶</a></dt> <dd><p>Return the signal which caused the process to exit.</p> <p>Availability: Unix.</p> </dd></dl> </div> <div class="section" id="miscellaneous-system-information"> <span id="os-path"></span><h2>15.1.6. Miscellaneous System Information<a class="headerlink" href="#miscellaneous-system-information" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="os.confstr"> <tt class="descclassname">os.</tt><tt class="descname">confstr</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.confstr" title="Permalink to this definition">¶</a></dt> <dd><p>Return string-valued system configuration values. <em>name</em> specifies the configuration value to retrieve; it may be a string which is the name of a defined system value; these names are specified in a number of standards (POSIX, Unix 95, Unix 98, and others). Some platforms define additional names as well. The names known to the host operating system are given as the keys of the <tt class="docutils literal"><span class="pre">confstr_names</span></tt> dictionary. For configuration variables not included in that mapping, passing an integer for <em>name</em> is also accepted.</p> <p>If the configuration value specified by <em>name</em> isn’t defined, <tt class="docutils literal"><span class="pre">None</span></tt> is returned.</p> <p>If <em>name</em> is a string and is not known, <a class="reference internal" href="exceptions.html#exceptions.ValueError" title="exceptions.ValueError"><tt class="xref py py-exc docutils literal"><span class="pre">ValueError</span></tt></a> is raised. If a specific value for <em>name</em> is not supported by the host system, even if it is included in <tt class="docutils literal"><span class="pre">confstr_names</span></tt>, an <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> is raised with <a class="reference internal" href="errno.html#errno.EINVAL" title="errno.EINVAL"><tt class="xref py py-const docutils literal"><span class="pre">errno.EINVAL</span></tt></a> for the error number.</p> <p>Availability: Unix</p> </dd></dl> <dl class="data"> <dt id="os.confstr_names"> <tt class="descclassname">os.</tt><tt class="descname">confstr_names</tt><a class="headerlink" href="#os.confstr_names" title="Permalink to this definition">¶</a></dt> <dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.confstr" title="os.confstr"><tt class="xref py py-func docutils literal"><span class="pre">confstr()</span></tt></a> to the integer values defined for those names by the host operating system. This can be used to determine the set of names known to the system.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="function"> <dt id="os.getloadavg"> <tt class="descclassname">os.</tt><tt class="descname">getloadavg</tt><big>(</big><big>)</big><a class="headerlink" href="#os.getloadavg" title="Permalink to this definition">¶</a></dt> <dd><p>Return the number of processes in the system run queue averaged over the last 1, 5, and 15 minutes or raises <a class="reference internal" href="exceptions.html#exceptions.OSError" title="exceptions.OSError"><tt class="xref py py-exc docutils literal"><span class="pre">OSError</span></tt></a> if the load average was unobtainable.</p> <p>Availability: Unix.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.3.</span></p> </dd></dl> <dl class="function"> <dt id="os.sysconf"> <tt class="descclassname">os.</tt><tt class="descname">sysconf</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#os.sysconf" title="Permalink to this definition">¶</a></dt> <dd><p>Return integer-valued system configuration values. If the configuration value specified by <em>name</em> isn’t defined, <tt class="docutils literal"><span class="pre">-1</span></tt> is returned. The comments regarding the <em>name</em> parameter for <a class="reference internal" href="#os.confstr" title="os.confstr"><tt class="xref py py-func docutils literal"><span class="pre">confstr()</span></tt></a> apply here as well; the dictionary that provides information on the known names is given by <tt class="docutils literal"><span class="pre">sysconf_names</span></tt>.</p> <p>Availability: Unix.</p> </dd></dl> <dl class="data"> <dt id="os.sysconf_names"> <tt class="descclassname">os.</tt><tt class="descname">sysconf_names</tt><a class="headerlink" href="#os.sysconf_names" title="Permalink to this definition">¶</a></dt> <dd><p>Dictionary mapping names accepted by <a class="reference internal" href="#os.sysconf" title="os.sysconf"><tt class="xref py py-func docutils literal"><span class="pre">sysconf()</span></tt></a> to the integer values defined for those names by the host operating system. This can be used to determine the set of names known to the system.</p> <p>Availability: Unix.</p> </dd></dl> <p>The following data values are used to support path manipulation operations. These are defined for all platforms.</p> <p>Higher-level operations on pathnames are defined in the <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a> module.</p> <dl class="data"> <dt id="os.curdir"> <tt class="descclassname">os.</tt><tt class="descname">curdir</tt><a class="headerlink" href="#os.curdir" title="Permalink to this definition">¶</a></dt> <dd><p>The constant string used by the operating system to refer to the current directory. This is <tt class="docutils literal"><span class="pre">'.'</span></tt> for Windows and POSIX. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p> </dd></dl> <dl class="data"> <dt id="os.pardir"> <tt class="descclassname">os.</tt><tt class="descname">pardir</tt><a class="headerlink" href="#os.pardir" title="Permalink to this definition">¶</a></dt> <dd><p>The constant string used by the operating system to refer to the parent directory. This is <tt class="docutils literal"><span class="pre">'..'</span></tt> for Windows and POSIX. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p> </dd></dl> <dl class="data"> <dt id="os.sep"> <tt class="descclassname">os.</tt><tt class="descname">sep</tt><a class="headerlink" href="#os.sep" title="Permalink to this definition">¶</a></dt> <dd><p>The character used by the operating system to separate pathname components. This is <tt class="docutils literal"><span class="pre">'/'</span></tt> for POSIX and <tt class="docutils literal"><span class="pre">'\\'</span></tt> for Windows. Note that knowing this is not sufficient to be able to parse or concatenate pathnames — use <a class="reference internal" href="os.path.html#os.path.split" title="os.path.split"><tt class="xref py py-func docutils literal"><span class="pre">os.path.split()</span></tt></a> and <a class="reference internal" href="os.path.html#os.path.join" title="os.path.join"><tt class="xref py py-func docutils literal"><span class="pre">os.path.join()</span></tt></a> — but it is occasionally useful. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p> </dd></dl> <dl class="data"> <dt id="os.altsep"> <tt class="descclassname">os.</tt><tt class="descname">altsep</tt><a class="headerlink" href="#os.altsep" title="Permalink to this definition">¶</a></dt> <dd><p>An alternative character used by the operating system to separate pathname components, or <tt class="docutils literal"><span class="pre">None</span></tt> if only one separator character exists. This is set to <tt class="docutils literal"><span class="pre">'/'</span></tt> on Windows systems where <tt class="docutils literal"><span class="pre">sep</span></tt> is a backslash. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p> </dd></dl> <dl class="data"> <dt id="os.extsep"> <tt class="descclassname">os.</tt><tt class="descname">extsep</tt><a class="headerlink" href="#os.extsep" title="Permalink to this definition">¶</a></dt> <dd><p>The character which separates the base filename from the extension; for example, the <tt class="docutils literal"><span class="pre">'.'</span></tt> in <tt class="file docutils literal"><span class="pre">os.py</span></tt>. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.2.</span></p> </dd></dl> <dl class="data"> <dt id="os.pathsep"> <tt class="descclassname">os.</tt><tt class="descname">pathsep</tt><a class="headerlink" href="#os.pathsep" title="Permalink to this definition">¶</a></dt> <dd><p>The character conventionally used by the operating system to separate search path components (as in <span class="target" id="index-30"></span><tt class="xref std std-envvar docutils literal"><span class="pre">PATH</span></tt>), such as <tt class="docutils literal"><span class="pre">':'</span></tt> for POSIX or <tt class="docutils literal"><span class="pre">';'</span></tt> for Windows. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p> </dd></dl> <dl class="data"> <dt id="os.defpath"> <tt class="descclassname">os.</tt><tt class="descname">defpath</tt><a class="headerlink" href="#os.defpath" title="Permalink to this definition">¶</a></dt> <dd><p>The default search path used by <tt class="xref py py-func docutils literal"><span class="pre">exec*p*()</span></tt> and <tt class="xref py py-func docutils literal"><span class="pre">spawn*p*()</span></tt> if the environment doesn’t have a <tt class="docutils literal"><span class="pre">'PATH'</span></tt> key. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p> </dd></dl> <dl class="data"> <dt id="os.linesep"> <tt class="descclassname">os.</tt><tt class="descname">linesep</tt><a class="headerlink" href="#os.linesep" title="Permalink to this definition">¶</a></dt> <dd><p>The string used to separate (or, rather, terminate) lines on the current platform. This may be a single character, such as <tt class="docutils literal"><span class="pre">'\n'</span></tt> for POSIX, or multiple characters, for example, <tt class="docutils literal"><span class="pre">'\r\n'</span></tt> for Windows. Do not use <em>os.linesep</em> as a line terminator when writing files opened in text mode (the default); use a single <tt class="docutils literal"><span class="pre">'\n'</span></tt> instead, on all platforms.</p> </dd></dl> <dl class="data"> <dt id="os.devnull"> <tt class="descclassname">os.</tt><tt class="descname">devnull</tt><a class="headerlink" href="#os.devnull" title="Permalink to this definition">¶</a></dt> <dd><p>The file path of the null device. For example: <tt class="docutils literal"><span class="pre">'/dev/null'</span></tt> for POSIX, <tt class="docutils literal"><span class="pre">'nul'</span></tt> for Windows. Also available via <a class="reference internal" href="os.path.html#module-os.path" title="os.path: Operations on pathnames."><tt class="xref py py-mod docutils literal"><span class="pre">os.path</span></tt></a>.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.4.</span></p> </dd></dl> </div> <div class="section" id="miscellaneous-functions"> <span id="os-miscfunc"></span><h2>15.1.7. Miscellaneous Functions<a class="headerlink" href="#miscellaneous-functions" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="os.urandom"> <tt class="descclassname">os.</tt><tt class="descname">urandom</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#os.urandom" title="Permalink to this definition">¶</a></dt> <dd><p>Return a string of <em>n</em> random bytes suitable for cryptographic use.</p> <p>This function returns random bytes from an OS-specific randomness source. The returned data should be unpredictable enough for cryptographic applications, though its exact quality depends on the OS implementation. On a UNIX-like system this will query /dev/urandom, and on Windows it will use CryptGenRandom. If a randomness source is not found, <a class="reference internal" href="exceptions.html#exceptions.NotImplementedError" title="exceptions.NotImplementedError"><tt class="xref py py-exc docutils literal"><span class="pre">NotImplementedError</span></tt></a> will be raised.</p> <p>For an easy-to-use interface to the random number generator provided by your platform, please see <a class="reference internal" href="random.html#random.SystemRandom" title="random.SystemRandom"><tt class="xref py py-class docutils literal"><span class="pre">random.SystemRandom</span></tt></a>.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.4.</span></p> </dd></dl> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">15.1. <tt class="docutils literal"><span class="pre">os</span></tt> — Miscellaneous operating system interfaces</a><ul> <li><a class="reference internal" href="#process-parameters">15.1.1. Process Parameters</a></li> <li><a class="reference internal" href="#file-object-creation">15.1.2. File Object Creation</a></li> <li><a class="reference internal" href="#file-descriptor-operations">15.1.3. File Descriptor Operations</a><ul> <li><a class="reference internal" href="#open-flag-constants">15.1.3.1. <tt class="docutils literal"><span class="pre">open()</span></tt> flag constants</a></li> </ul> </li> <li><a class="reference internal" href="#files-and-directories">15.1.4. Files and Directories</a></li> <li><a class="reference internal" href="#process-management">15.1.5. Process Management</a></li> <li><a class="reference internal" href="#miscellaneous-system-information">15.1.6. Miscellaneous System Information</a></li> <li><a class="reference internal" href="#miscellaneous-functions">15.1.7. Miscellaneous Functions</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="allos.html" title="previous chapter">15. Generic Operating System Services</a></p> <h4>Next topic</h4> <p class="topless"><a href="io.html" title="next chapter">15.2. <tt class="docutils literal"><span class="pre">io</span></tt> — Core tools for working with streams</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li><a href="../_sources/library/os.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="io.html" title="15.2. io — Core tools for working with streams" >next</a> |</li> <li class="right" > <a href="allos.html" title="15. Generic Operating System Services" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="allos.html" >15. Generic Operating System Services</a> »</li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="http://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Jul 03, 2019. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>
Close