Wednesday, January 20, 2016

Too many files for ls

Using ls you receive the error that there are too many arguments:

Example:

find /path/to/files/ -name "*.ZIP" -exec basename {} \;

Saturday, January 2, 2016

Get path to current script in Python

import os 
os.path.dirname(os.path.realpath(__file__))
 
Source 

Python string formatting in print statements

#!/usr/bin/env python

# Format using a dictionary
print '%(language)s has %(number)03d quote types.'
% {"language":"Python","number":2}

# Format using a list

print '%s has %03d quote types.' % ("Python",2)

# Best method

print '{} has {} quote types.'.format("Python",2)

Planning to post more code snippets this year to remind me of how to do various things in Python.

Source: Pyformat