SGMLXML.net A place for SGML and XML application developers.

September 9, 2021

OS Module

Filed under: — cangione @ 8:48 am

OS Module

Comes with the anaconda install.

import os

name of operating system

We can get the operating system we're working on

1. **nt** is windows
2. **posix** is all unix based systems (Mac, Linux, ect)

Thrid would be java but not very common

print(os.name)
posix

Working directory

NOTE if working on windows need to store strings as \ for escape.

os.getcwd()
print(os.getcwd())

Contents of Directory

os.listdir('.')
['Debugging.ipynb',
 'Object Orient Programming Theory.ipynb',
 'Untitled.ipynb',
 'Flow Control.ipynb',
 '.ipynb_checkpoints',
 'My First Notebook.ipynb',
 'User Defined Functions.ipynb']
os.listdir('git')
['documentation']

make and rename directory

#os.mkdir()
#os.rename

create and edit

Note OS directory not needed. Can be done in base python.
#file = open('somefile','w')
#file.write('hello\n')
#file.writ4e('world!')
#file.close()

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress