On Mon, Jan 14, 2019 at 12:36 PM E. Madison Bray <erik.m.b...@gmail.com> wrote:
>
> On Mon, Jan 14, 2019 at 12:00 PM Dima Pasechnik <dimp...@gmail.com> wrote:
> >
> > Turns out it's due to the script reading a parameter, in the usual
> > Pythonic way, at the end of the file:
> >
> > if __name__ == "__main__":
> >    import sys
> >    m = int(sys.argv[1])
> >    compute_alpha(m)
> >
> > Namely, load() tries to evaluate int(sys.argv[1]), whereas for some
> > reason sys.argv[1] is '-i'.
> >
> > So this is probably not a bug, but deserves mentioning in the documentation.
>
> What I'm wondering is why load() sets `__name__ = '__main__'`
> (otherwise it wouldn't be running this code at all).
>
> There might be a good reason, but it also seems like a bad idea
> precisely for reasons like this: .sage files that also work as
> executables, and thus use the standard `__name__ == '__main__'`
> blocking.  I don't think load() should cause this code to run.  It
> might instead be better if it assigned some random-ish module name
> based on the .sage filename.

perhaps, even better, having `__name__`  equal to None by default is a
better choice,
and load() can get an optional parameter to set `__name__` ?

(same with attach())

Dima

>
> > On Mon, Jan 14, 2019 at 10:42 AM Dima Pasechnik <dimp...@gmail.com> wrote:
> > >
> > > My student created a sage script crossing.sage that runs by itself,
> > > i.e. starting it in bash, with it having the 1st line
> > >
> > > #!/usr/bin/env sage
> > >
> > > but an attempt to load("crossing.sage") in Sage gives an error:
> > >
> > > ValueError                                Traceback (most recent call 
> > > last)
> > > <ipython-input-1-f92dbb154243> in <module>()
> > > ----> 1 load("crossing.sage")
> > > /home/dimpase/sage/local/lib/python2.7/site-packages/sage/misc/persist.pyx
> > > in sage.misc.persist.load (build/cythonized/sag
> > > e/misc/persist.c:2470)()
> > >     134
> > >     135     if sage.repl.load.is_loadable_filename(filename):
> > > --> 136         sage.repl.load.load(filename, globals())
> > >     137         return
> > >     138
> > > /home/dimpase/sage/local/lib/python2.7/site-packages/sage/repl/load.pyc
> > > in load(filename, globals, attach)
> > >     261                 add_attached_file(fpath)
> > >     262             with open(fpath) as f:
> > > --> 263                 exec(preparse_file(f.read()) + "\n", globals)
> > >     264     elif ext == '.spyx' or ext == '.pyx':
> > >     265         if attach:
> > > <string> in <module>()
> > > ValueError: invalid literal for int() with base 10: '-i'
> > > sage:
> > >
> > > ---------------------
> > >
> > > Is this a Sage bug? Any idea what might be going on there?
> > >
> > > Thanks
> > > Dima
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "sage-devel" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to sage-devel+unsubscr...@googlegroups.com.
> > To post to this group, send email to sage-devel@googlegroups.com.
> > Visit this group at https://groups.google.com/group/sage-devel.
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sage-devel" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sage-devel+unsubscr...@googlegroups.com.
> To post to this group, send email to sage-devel@googlegroups.com.
> Visit this group at https://groups.google.com/group/sage-devel.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at https://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to