This is mostly a quick note to aid other programmers who end up searching for something along the lines of "why doesn't floating point division work in pdb".

Short version: the from __future__ import magic doesn't work in pdb.

Long version: when debugging a program that (a) runs under Python 2 and (b) relies on from __future__ import division to get floating point rather than integer division, it would be nice to have expressions typed at the pdb prompt behave the same way as expression evaluated in the file. However, this doesn't work:

$ python -m pdb test.py
> /home/martin/test.py(1)<module>()
-> from __future__ import division
(Pdb) n
> /home/martin/test.py(3)<module>()
-> c = 74 / 100
(Pdb) from __future__ import division
(Pdb) 2/3
0
(Pdb)

This applies to all magic from the __future__ module, but the division is by far the most used so I'm guessing that's what people are most likely to be searching for.


Subscribe to articles from the programming category via RSS or ATOM

Comments

comments powered by Disqus