Skip to content

Instantly share code, notes, and snippets.

@boralyl
Created March 1, 2012 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boralyl/1946524 to your computer and use it in GitHub Desktop.
Save boralyl/1946524 to your computer and use it in GitHub Desktop.
Observations
# 1) 2 blank spaces between a function definition and end. i.e.
import foo
def diinosaur():
pass
def something_else():
pass
# 2) Ah! Global variables! If it's going to be reused, maybe a class is better and file_dir can be set in the constructor. i.e.
class AllStandardsCss(object):
def __init__(self, file_dir):
self.file_dir = file_dir
def do_something(self):
print "Look I'm using the file_dir var: %s" % (self.file_dir, )
file_dir = '/path/to/something'
all_standards = AllStandardsCss(file_dir)
all_standards.do_something()
# 3) open returns an iterator, so no need to read all the lines into memory
for line in open(file_dir, 'r'):
print line
# 4) There are builtin functions for copying, moving, removing files.
import os
import shutil
# http://docs.python.org/library/os.html#os.remove
os.remove('path/to/file')
# http://docs.python.org/library/shutil.html#shutil.copy
shutil.copy(src, destination)
# 5) get_all_elements(). I think the easiest way to define these is
# a dictionary of lists like so:
elements = {
'border-radius': ['-moz-border-radius', '-webkit-border-radius'],
'border-top-right-radius': ['-moz--top-right-radius', '-webkit-top-right-radius']
}
for rule in elements:
print "The rule is %s" % (rule, )
print "The following need to be added:"
for new_rule in elements[rule]:
print new_rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment