I see. It works now. Thanks! 

On Tuesday, December 3, 2013 12:38:35 AM UTC+8, Nils Bruin wrote:
>
> On Sunday, December 1, 2013 6:06:42 PM UTC-8, sea21 wrote:
>>
>> Hi, 
>>
>> I wanted to write a Sage third-party module to generate random numbers. 
>> The module contains a class which includes a method to generate a random 
>> number. The method calls on the ntl library:
>>
>> r = ntl.ZZ_random(2**512)
>>
>> However, after I installed the module in Sage via:
>>
>> sage --python GenRan.py install
>>
>> and typed
>>
>> sage: from GenRan import *
>> sage: genran = GenRan()
>> sage: genran()
>>
>> I get the error message:
>> NameError: global name 'ntl' is not defined.
>>
>> But when I attach GenRan directly via:
>>
>> sage: attach GenRanNum.py
>> sage: genran = GenRan()
>> sage: genran()
>> 1928749784019341983249823749823423948723984
>>
>> I get the random number I desire. 
>>
>> Why is this so? I am using sage version 5.7 on Linux version 2.6. Would 
>> greatly appreciate any help. Thanks!
>>
> You probably need a statement `import ntl` in GenRanNum.py. The code of an 
> attached file gets injected into the top-level name space, which already 
> has most things available. When you import a module, it gets its own name 
> space. This name space doesn't have ntl in it, so you have to put it there 
> first.
>  
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to