Sunday, June 30, 2013

Sym folders

Folder Structure

Sym
  \sym  : source code
  \test : testing code
  \docs : documentation

On Testing

Also like the idea of Thomas Andrews in [1] to put unit test code in the module itself:
if __name__ == '__main__':
   do tests...

References:

  1. http://guide.python-distribute.org/example.html
  2. http://stackoverflow.com/questions/61151/where-do-the-python-unit-tests-go

Add modules by specific path - e.g. for testing

import sys
sys.path.append('..')  # add path to module, in this case the parent directory
 

import some_module

Saturday, June 1, 2013

Python Tip - If you've accidentally deleted your .py files, all is not lost...

Recover .py files using uncompyle

If you've accidentally deleted your .py file, all is not lost. Use uncompyle to recover:

  git clone https://github.com/gstarnberger/uncompyle.git
  cd uncompyle/
  sudo ./setup.py install

  uncompyler.py thank_goodness_this_exists.pyc > recovered_file.py


See Also

Python Tip - Create and detach a child process

Create and detach a child process

Use the following code to create and subsequently detach a child process

  DETACHED_PROCESS = 0x00000008
  pid = subprocess.Popen([sys.executable, "longtask.py"],
                         creationflags=DETACHED_PROCESS)

  pid.poll()  # Returns: None if child still active
              #          returncode otherwise 


In Sym, a complex component will be made up of a parent process and related child processes. 

See Also