Ticket #1789: examples-trac-1789.patch

File examples-trac-1789.patch, 3.0 KB (added by was, 12 years ago)

fixes the examples and docs in the examples/programming/scripts to avoid a lot of confusion, e.g., so they work on both os x and linux instead of just os x.

  • programming/standalone_scripts/python/README.txt

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1200750740 28800
    # Node ID 9c0e756361cc177c88a0f697e6538671baf935fb
    # Parent  21db08a64b56dba96df1deabf14555e140a81044
    Trac #1789 -- fix examples illustrating standalone scripts
    
    diff -r 21db08a64b56 -r 9c0e756361cc programming/standalone_scripts/python/README.txt
    a b This example explains how to write Pytho 
    11This example explains how to write Python scripts that have access to
    22the SAGE library functionality.
    33
     4IMPORTANT!:
    45It's important that the root directory of your sage install be in
    5 your PATH in order for the examples to work.
     6your PATH in order for the examples to work.  I.e., the command
     7"sage" must be in your PATH.
    68
    79This example arose out of code from Nathan Dunfield and David Kohel.
    810
    your path. Note that 
    1214
    1315  from sage.all import *
    1416
    15 appears near the top of each script.  The key thing is that sage-python
    16 sets all environment variables, etc., correctly for using the SAGE library.
    17 Otherwise it is just like the usual Python interpreter.
     17appears near the top of each script.  The key thing is that sage run
     18as a #! script sets all environment variables, etc., correctly for using
     19the SAGE library.  Otherwise it is just like the usual Python interpreter.
    1820
    1921EXAMPLES:
    2022was$ ./binom 5 2
    was$ ./factor 200593983 
    2325was$ ./factor 200593983
    24263 * 37 * 1807153
    2527
    26 
    2728NOTE -- No SAGE preparsing is available for scripts yet, even as
    28 an option.   You could put
    29 
    30 #!/usr/bin/env sage
    31 
    32 at the beginning of the file, but command line arguments won't
    33 be correctly passed via sys.argv because IPython seems to not
    34 pass them yet. 
     29an option.   A workaround is to turn the already preparsed version
     30of a .sage script into a #! script.
  • programming/standalone_scripts/python/binom

    diff -r 21db08a64b56 -r 9c0e756361cc programming/standalone_scripts/python/binom
    a b  
    1 #!/usr/bin/env sage -python
     1#!/usr/bin/env sage
    22
    33import sys
    4 from sage.all import *
    54
    65if len(sys.argv) != 3:
    76    print "Usage: %s <n> <m>"%sys.argv[0]
    87    sys.exit(1)
    98
     9from sage.all import *
    1010n = ZZ(sys.argv[1])
    1111m = ZZ(sys.argv[2])
    1212print binomial(n, m)
  • programming/standalone_scripts/python/factor

    diff -r 21db08a64b56 -r 9c0e756361cc programming/standalone_scripts/python/factor
    a b  
    1 #!/usr/bin/env sage -python
     1#!/usr/bin/env sage
    22
    33import sys
    4 from sage.all import *
    54
    65
    76if len(sys.argv) != 2:
    if len(sys.argv) != 2: 
    98    print "Outputs the prime factorization of n."
    109    sys.exit(1)
    1110
     11from sage.all import *
    1212print factor(sage_eval(sys.argv[1]))