997Flask – [Errno 48] Address already in use


Stopping the flask server with ⌃-Z (CRTL-Z), instead of the correct ⌃-C (CRTL-C), results in the server still bound to port 5000:

OSError: [Errno 48] Address already in use

Problem: After Flask crash, the port can still be occupied.


Check who is using port 5000

sudo lsof -i:5000
kill $PID
kill -9 $PID


[2]  + killed     flask run

966Combining JSON files in Python

Quick python script to combine several JSON files into one. File names are dict keys in the JSON output.

import os
import json

entries = os.listdir(os.getcwd())

animationFiles = [

output = {}

for name in animationFiles:
  with open(name + '.json') as f:
    output[name] = json.loads(f.read())

outputFile = open('output.json', 'w')
outputFile.write( json.dumps(output) )


636Python 3.1 and TextMate

http://stackoverflow.com/questions/1775954/using-python-3-1-with-textmate Variable can be set in TextMate either on a global or on a per project basis. It seems some of the internals are coded using Python 2.x, therefore a global switch to the backwards-incompatible 3.x is not recommended. Project based variable can be set by opening a project, deselecting any text files, and clicking on the little i-icon in the project window. My path for Python 3.1 is: TM_PYTHON /Library/Frameworks/Python.framework/ Versions/3.1/bin/python3 Your milage might vary.