[sage-devel] Re: [sage-forum] Re: problem with sage-python

2007-10-17 Thread William Stein

On 10/17/07, Pierre [EMAIL PROTECTED] wrote:

 a 'sage-import' command would also make a lot of sense.


Something like that definitely makes sense.

What about

   load foo.sage

to load as usual, and

   sage_import foo.sage

to do the same as load but put everything in the foo namespace?
I wonder if the command will be too hard to remember.
Another possibility would be:

   load foo.sage as foo

would make it so everything in foo.sage is imported into the foo
namespace.  Then

   attach foo.sage as foo

could also be implemented.  Also one could do

load foo.sage as bar

to put everything in the bar namespace.

Thoughts?

 On 17 oct, 11:28, Pierre [EMAIL PROTECTED] wrote:
  perhaps i'm being silly: i'm assuming that it is possible to preparse
  right after 'import' has located the file, and still before it
  actually does import it ! this would require modifying python, a bit
  of a pain!
 
  On 17 oct, 11:23, Pierre [EMAIL PROTECTED] wrote:
 
   my suggestion is that the standard extension should not be .sage, but
   rather .sage.py so import foo.sage would import foo.sage.py. It will
   also help python IDEs (thanks for the emacs tweak btw). And i believe
   it is true to sage's nature.
 
   Then, import should preparse if the extension is .sage.py, not if it
   is just .py.
 
   what do you think ?
 
   On 17 oct, 11:14, William Stein [EMAIL PROTECTED] wrote:
 
On 10/17/07, Pierre [EMAIL PROTECTED] wrote:
 
 I was wondering how to have my scripts preparsed: now i know. And i
 need to tell emacs that a .sage file needs to be treated like a .py
 file...
 
Put this in your .emacs file:
 
(setq auto-mode-alist (cons '(\\.sage\\' . python-mode) 
auto-mode-alist))
 
 a problem with .sage files though is that the import command doesn't
 work with them (foo.sage is not found by either 'import foo' or
 'import foo.sage'). I *know* there is the 'load' or the 'attach'
 command instead, but really i prefer import, because of what it does
 with namespaces: having 'foo.f()' is less likely to clash with f()...
 same with variables.
 
I understand.   It would indeed be god to have some sort of preparse
then import command.  Any suggestions for how it would work (i.e.,
from the user's point of view)?  Making
 import foo
work if foo.sage is there isn't really an option, since Python directly
does the import, and won't know to look for foo.sage.
 
William


 



-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~--~~~~--~~--~--~---



[sage-devel] Re: [sage-forum] Re: problem with sage-python

2007-10-17 Thread William Stein

On 10/17/07, Pierre [EMAIL PROTECTED] wrote:
 or the load command could exactly replace import, so that

 load foo

 would load foo.sage in the namespace foo after preparsing, while the
 current behavior of load would be achieved by

 from foo load *

 And load foo as bar would work as well. (I don't know if foo should
 be replaced by foo.sage thoughout, can't decide)

 The problem is that people are used to the current syntax of load...
 perhaps what you are suggesting is better. Personally i would find
 either way very easy to remember. What would students prefer ? i don't
 use sage to teach (yet!), but i suppose it's important. I'm guessing
 that creating a new namespace (by default) would prevent them from
 making silly mistakes.

Let's wait and see what/if this discussion generates any further
discussion in this thread by people other than you and me.
If so, then it would make sense to do a rewrite of the commands.

FYI, the current load command works like the load command in
Magma, which is what I was very used to using when I started
Sage, and which I missed.  It -- coupled with the attach command --
provide different functionality than import.

By the way, if foo is a file and you do
load foo.sage
you can then do
import foo
and get foo in a namespace.  This is because typing foo.sage
creates a file foo.py with the preparsing done.

William

William

--~--~-~--~~~---~--~~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~--~~~~--~~--~--~---