On Thursday 08 January 2009, ztnews wrote: > Forgive me if this is too obvious. I'm still evaluating/learning the > basics of SAGE > > Just how compatible is SAGE with Python? By which I mean, should I be > able to just "drop-in" an existing/working python script and have it > run, or should I expect some modifications will be required? And if > so, what's the major things I need to keep an eye out for? > > I've looked in the documents, particularly "Coding in Python for Sage" > > http://www.sagemath.org/doc/prog/node15.html > > I'll illustrate by example. I found a Python script that does a > physics calculation (band structure of silicon) > > http://www.wag.caltech.edu/home/rpm/projects/tight-binding/harrison.py > > or see here for a discussion of the script: > > http://www.wag.caltech.edu/home/rpm/projects/tight-binding/ > > I've successfully run harrison.py (without modification) using both > linux and windows-based python installations. But under SAGE (I've > installed the latest vmware version) required a little diddling to get > it (mostly) running. > > Two points. 1) This script calls for modules "Numeric" and > "LinearAlgebra" > > from Numeric import * # Make sure that NumPy is in your > from LinearAlgebra import eigenvalues > > both of which failed in SAGE. A couple minor modifications and I got > past those points. I suspect these are deprecated, but still the > Python installations handled the script without mods. > > 2) The other thing that failed was the system call to gnuplot at the > end of the script. I can imagine that would be hard make work in a > SAGE-notebook environment, and I haven't managed that. > > Now, my point here is not that I need that script to run, > particularly. My question is about compatibility. Have I missed > something about how to execute a Python script with the minimum of > modifications?
The Python you run when you run Sage is a standard Python so it should just work (TM). However, with one notable exception: The input is pre-parsed such that e.g. 1 becomes ZZ(1). This is necessary so that 1/2 is actually one half. You can turn this behaviour off by: sage: preparser(False) sage: 2/3 0 sage: 2/3 2/3 Martin -- name: Martin Albrecht _pgp: http://pgp.mit.edu:11371/pks/lookup?op=get&search=0x8EF0DC99 _otr: 47F43D1A 5D68C36F 468BAEBA 640E8856 D7951CCF _www: http://www.informatik.uni-bremen.de/~malb _jab: martinralbre...@jabber.ccc.de --~--~---------~--~----~------------~-------~--~----~ 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 URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---