## Archive for the ‘python’ Category

### The decimal module in Python

Wednesday, August 12th, 2009

Python has a brilliant decimal module (http://docs.python.org/library/decimal.html) you may need if you want to avoid floating point errors.  This may be necessary if you are faced with compounding errors under special circumstances e.g. if testing a statistical routine against a purpose-built test dataset (e.g. http://www.itl.nist.gov/div898/strd/anova/SmLs09_cv.html).  The performance hit is substantial, however, so it has to be used judiciously.  Anyway, here is an example:

```import decimal D = decimal.Decimal decimal.getcontext().prec = 120 d1 = D("1.1") f1 = 1.1 print "Decimal result is: %s" % round((d1**1000 - D("2.46993291801e+41")),3) print "Floating point result is: %s" % round((f1**1000 - 2.46993291801e+41),3) >>>```

Decimal result is: -4.17366587591e+29
Floating point result is: -3.97456123863e+29

Usually, floating point is good enough – but not under all circumstances.  In which case, it pays to be familiar with the decimal module.

Tuesday, June 9th, 2009

SOFA Statistics is having new import functionality added.  The first target is csv format files (using the standard Python csv module underneath) followed by Excel spreadsheets.  The solution I have for Excel works even when MS Office has not been installed on a machine but will only work in Windows.   Later on I will target SPSS data files and Open Office Calc spreadsheet files.

### Resolving Windows installation glitches

Tuesday, May 26th, 2009

If you had problems installing the Windows version of SOFA 0.6.8, try 0.7.0 (http://www.sofastatistics.com/misc/sofa-0.7.0_python-2.5.zip).  It resolves the main issues with that installation package.  Version 0.7.0 also resolves some other issues within SOFA and represents the first of the 0.7 series – the goal of which is to enable importing of spreadsheets and other, non-SQL database type data.

The Windows comtypes package relied upon by SOFA 0.6.8 proved to be faulty.  The 0.7.0 version of SOFA Statistics, which has just been released, uses an older version of comtypes (0.5.2) which is known to work.  A version of comtypes 0.6.0 for python 2.5 is apparently forthcoming.

There is still a delay when using SOFA’s table making functionality for the first time while comtypes generates some data it needs.  NB this is a one-off delay which doesn’t affect anything else.  Ideally, SOFA will handle this process better in a forthcoming release.

### Windows package will be Python 2.5 only for now

Saturday, May 16th, 2009

Unfortunately SciPy does not have a Python 2.6 installer yet.  The MySQLdb package does but it is not from the central sourceforge location (http://www.technicalbard.com/files/MySQL-python-1.2.2.win32-py2.6.exe). Also see http://bytes.com/groups/python/854793-will-mysqldb-python-shim-supported-python-2-6-3-x.  For the time being, therefore, the Windows package for SOFA will be a Python 2.5 version only.

BTW nearly ready to release the packages once project hosting is finalised.

The licence is AGPL 3.

### SOFA for Windows Package under testing

Friday, May 15th, 2009

A windows installer for sofa statistics has been created and is currently undergoing testing on clean machines.  NSIS was used to create the installer, which necessitated learning a new script language.  The language used by NSIS is a cross between PHP and assembly and was quite a shock after the elegance of python.

### Made first demo deb package successfully

Friday, May 8th, 2009

The instructions kindly provided by Horst Jens  at http://showmedo.com/videotutorials/video?name=linuxJensMakingDeb were very helpful.  There are a few details I have to understand better but it all looks doable.  One gotcha when editing the rules file in gedit – tabs != spaces and manually added tabs are converted into spaces!  Copying and pasting tabs from elsewhere solved the problem.