Is there a python module that convert a value and an error to a scientific notation?
Question: Suppose I have two numbers, `v = 0.01342` and `err = 0.0004`. Under scientific
notation, this would be written as `(13.4 ± 0.4)e-3`. Is there a function that
does that conversion (probably on scipy)? Naturally, the important thing is
the numbers and not the `±` sign. Searching the web, I learned that there is
(are?) function(s?) which eat a number to transform and a number of desired
digit and they spit the result. This is not what I'm searching for. I've
written once but it turned out to be quite ugly.


Answer: I didn't understand what you meant by the last few lines, but when you have a
specific output like yours, you usually have to write you own.

    
    
    def sci_not(v,err,rnd=1):
        power = - int(('%E' % v)[-3:])+1
        return '({0} +/- {1})e{2}'.format(
                round(v*10**power,rnd),round(err*10**power,rnd),power)
    

This does the trick

    
    
    >>> v = .01342
    >>> err = .0004
    >>> sci_not(v,err)
    (13.4 +/- 0.4)e3
    

**EDIT :** You can put in the ± character if you make the string unicode, but
the results only look pretty when you use a print statment.

Replace the previous return statement with

    
    
    return u'({0} \u00B1 {1})e{2}'.format(
                round(v*10**power,rnd),round(err*10**power,rnd),power)
    

This returns

    
    
    >>> sci_not(v,err)
    u'(13.4 \xb1 0.4)e3'
    >>> print sci_not(v,err)
    (13.4 ± 0.4)e3
    

