Sunday, November 4, 2012

pprint in python

javac -d option

Using "-d" option, you can create a class in a hierarchical directory. "" has "package a.b", with the "-d" option, the class is generated in "testa/build/a/b" directory.
javac -d testa/build -g testa/src/a/b/ 
java -cp testa/build a.b.HelloA

Python format string

When using template technique for formatting string, STRING#format can be useful.
print 'Coordinates: {latitude}, {longitude}'.format(latitude='37.24N', longitude='-115.81W')
Coordinates: 37.24N, -115.81W



You can get all the installed module information using "python modules".
pydoc modules

AddressBook         __future__          django              pstats
AppKit              _abcoll             dl                  pty
AppleScriptKit      _ast                doctest             pwd
AppleScriptObjC     _bisect             dumbdbm             py2app
Audio_mac           _builtinSuites      dummy_thread        py2app_tests
Automator           _codecs             dummy_threading     py_compile
BaseHTTPServer      _codecs_cn          easy_install        pyclbr
Bastion             _codecs_hk          email               pydoc
CFNetwork           _codecs_iso2022     encodings           pydoc_data
CFOpenDirectory     _codecs_jp          errno               pyexpat
CGIHTTPServer       _codecs_kr          exceptions          quopri
CalendarStore       _codecs_tw          fcntl               random
Canvas              _collections        filecmp             re
pydoc doesn't recognize any special markups. If you want to get more from the docstring, you need other documentation generator such as epydoc, Doxygen, or Sphinx.


Using markdown format with TextMate

You want to execute "pandoc" when "⌘-R" is clicked, what would you do? There are some ideas you need to understand.
  • Scope selection
  • Activation
  • Command
  • Environment Variables

Scope selection and Activation

Many of the keys are already assigned, so when you try to use the popular key such as "⌘-R", you need to select the scope. In other words, you need to teach TextMate that when you click "⌘-R" in markdown, it means something special. Screen Shot 2012 11 04 at 2 56 11 PM


In command editor, you can give any UNIX command you want. And many of the predefined environment variables are already given.

Combining the command and variable, you can come up wit the following commands.
/usr/local/bin/pandoc "$TM_FILEPATH" -o "$TM_FILEPATH".html
/usr/bin/open "$TM_FILEPATH".html
echo File: "$TM_FILEPATH"
Screen Shot 2012 11 04 at 3 02 07 PM


python logging

Python logging lets the information is shown to the screen, or written to a file. Without any file setup, the default action is to print out the info to the screen.

You have three levels of logging: debug > info > warning. The strongest level is debug, and the weakest is warning.
import logging

logging.warning('Watch out!') # will print a message to the console'I told you so') # will not print anything
You can use "basicConfig()" method to login the info to the file. For level, if you choose "DEBUG", every debug/info/warning message is logged, with "INFO", only info/waring, and so on.
import logging

logging.debug('This message should go to the log file')'So should this')
logging.warning('And this, too')


Documentation in python

def foo():
    """A multi-line

def bar():
    A multi-line