Ask Your Question
1

'object is not callable' error in sagetex (that doesn't occur in a worksheet)

asked 2016-11-28 20:00:55 +0200

mathochist gravatar image

I'm generating random numbers to be presented in scientific notation for a quiz I'm typing. In testing this code works fine in a worksheet, but gives an error in a sagesilent block of my .tex document. Here's the code:

sci = {}
for index in range(1, 14):     # Picks random coeffs for sci not.
    places = ZZ.random_element(0, 4)
    sci["co{0}".format(index)] = round(10*random(), places)
powe = {}
for index in range(1, 14):     # Picks random powers for use.
    powe["r{0}".format(index)] = ZZ.random_element(5, 10)
sci['co1']
sci['co2']
powe['r1']
powe['r2']

In the worksheet, those last four lines generate output like

3.0
5.566
7
8

But when I use that same code in the .tex document (without the last four lines), Sage returns this error before I can even call my numbers:

'module' object is not callable

My best guess is that rounding needs some package that the worksheet imports automatically but sagetex does not, but I'm afraid I don't know enough about what's really going on. Thank you for any help!

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-11-29 15:26:45 +0200

Sébastien gravatar image

Here is a way to generate the same error message:

>>> import random
>>> random()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable

The function random from the module of the same name is callable:

>>> from random import random
>>> random()
0.6012904467670809

Therefore, I would suggest to add the line

from random import random

to your code to make sure that random is really a function and not a module. Does this fix your problem?

edit flag offensive delete link more

Comments

Yes, thank you! I think I may have imported random in the worksheet on a different occasion, but I didn't think about that since I thought cells were only executed when you run them. If I import a package in a worksheet, I wonder if it should linger through subsequent sessions? But, yes, that worked; thanks again.

mathochist gravatar imagemathochist ( 2016-12-02 21:31:02 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-11-28 20:00:55 +0200

Seen: 1,540 times

Last updated: Nov 29 '16