Skip to main content

Cool Python Tricks

Print Append

Using print to append string to file


file = open('path/to/file','a+')
print >> file, 'string to append'
print >> file, 'another string'

If you check your file you should have string to append another string

Dictionary Functions

Map functions in python dictionary


def doThis():
    print 'this'

def doThat():
    print 'that'

def doThose(string):
    print string

func_dict = { 'this':doThis, 'that':doThat, 'those':doThose }

func_dict['this'] #prints this
func_dict['that'] #prints that
func_dict['those']('Python is cool') #prints Python is cool

More to come...

Comments

Popular posts from this blog

Inkscape Game Character #4

This one goes to the fellows a PopCap Games . This is a plant pod from the game Plants vs Zombies.   If you would like to study the drawing feel free to download the Inkscape SVG file. Right click then hit save link as: plantpod.svg All rights reserve to the original artists.

New Angry Birds(Maybe)

So I'm a huge fan of angry birds and while playing the game I thought hey I want to make some birds to break things. So here are some of the birds I created (with the exception of the first one). Let me know what you guys think. If you would like to study the drawing feel free to download the Inkscape SVG file. Right click then hit save link as: newbirds.svg All rights reserve to the original artists.

Mobile App UI Mockup

Here is a mock up on the UI I want to "try" for my application. Enjoy. Download link on request.