[sage-support] finding out how to import a built-in (say, vector)

2010-02-27 Thread Dima Pasechnik
In a sage function I need to use Sage's built-in types, say, vector.
E,g,

def foo(bar):
  from  import vector as v
  a=v(bar)

How do I find out from where it has to be imported?
(I haven't come up with anything better than running a grep on devel/
sage/sage/*/*.py* looking for vector and import)

Thanks,
Dima

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org


Re: [sage-support] finding out how to import a built-in (say, vector)

2010-02-27 Thread Robert Bradshaw

On Feb 27, 2010, at 6:22 PM, Dima Pasechnik wrote:


In a sage function I need to use Sage's built-in types, say, vector.
E,g,

def foo(bar):
 from  import vector as v
 a=v(bar)

How do I find out from where it has to be imported?
(I haven't come up with anything better than running a grep on devel/
sage/sage/*/*.py* looking for vector and import)


Is this from a Python script? If so the safest way is to do from  
sage.all import vector as v as there is sensitivity in the order  
things are imported. In the library, you'll have to see where it's  
defined, or do something like from sage.modules.all import vector as  
v if you're using it from a non sage.modules package. Usually you  
don't want to be too specific, or that created unneeded dependancies  
(the current order things get imported in is a mess...).


The easiest way to see is to do

sage: vector.__module__
'sage.modules.free_module_element'

- Robert

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org