sage: "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/home/zoresvit/devel/ciphering/algebraic/<ipython console> in <module>()
ValueError: Unknown format code 'd' for object of type 'str'
sage: preparser(False)
sage: "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(42)
'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010'
$ sage --version
Sage Version 4.8, Release Date: 2012-01-20
$ sage -python
Python 2.6.4 (r264, Jan 20 2012, 00:16:31)
[GCC 4.4.3] on linux2
The problem is that apparently format doesn't accept Integers:
sage: "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin: {0:#b}".format(int(42))
'int: 42; hex: 0x2a; oct: 0o52; bin: 0b101010'
sage: "int: {0:d}; hex: {0:#x}; oct: {0:#o}; bin:
{0:#b}".format(Integer(42))
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/Users/grout/jason/drake/linear-algebra/Exams/<ipython console> in
<module>()
ValueError: Unknown format code 'd' for object of type 'str'
Thanks,
Jason
Given that not every Integer fits into an int, this would be asking for
trouble. Rather, Sage should specify its own format for Integer, etc.
Given that not every Integer fits into an int, this would be asking for
trouble. Rather, Sage should specify its own format for Integer, etc.