Python File System Operation Snippets Collection

In this post, I’ll share some simple snippet to do various file system operation. Pretty much as a bookmark for my own usage, in case I needed it someday.
How to get current working directory:

import os
os.getcwd()

How to change working directory:

import os
os.chdir(‘/tmp/’)

How to list directory contents:

import os
os.listdir(‘/tmp/’)

How to check if directory / file exists:

import os
os.path.exists(‘/tmp/’)#work for both [...]

Automate Facebook Status Update Without Facebook API

Sweet little snippet with only 10 lines of code! Using python mechanize library to update your facebook status. Check out the code:

PHPSH: Test PHP Snippet, The Python Way!

If you know python, maybe you know the interactive python shell, too. If you don’t know both, well, let me explain it. Python has it’s built in interactive shell. When you install python and you execute the command, python, you will be introduced to a shell like interface where you could type python statements and [...]