On Thu, Jun 9, 2016 at 3:42 PM, Andrew <andrew.mat...@gmail.com> wrote: > Thanks Johan.As much as anything I wanted to know that I wasn't doing > something stupid. > > On Thursday, 9 June 2016 14:02:16 UTC+2, Johan S. R. Nielsen wrote: >> >> As a package author, you shouldn't force the user to load the functions >> into >> the global namespace. However, it might be possible by getting hold of the >> globals() object or something. > > > Well, actually, if some one explicitly loads the package using something > like "import mytest" then I think that it is reasonable to load the main > functions from the package it the global namespace. Thinking about it, sage > already does something similar (but more explicit) with methods like > inject_shorthands. Drilling down a little I realised that I can do what I > want by putting the following into my __init__.py file: > > from sage.misc.misc import inject_variable > from mytest.test import atest > inject_variable('atest',atest) > > Question: do people think that it is reasonable for a package to do this?
No. Definitely not. Never. > Arguments against include that packages "shouldn't force the user to load > the functions into > the global namespace" and that this may lead to clashes in the namespace. An > argument in favour of doing this is that this a more user-friendly and a > user is unlikely to import a package if they don't want to use it. Sage doesn't do this either. If you load a normal Python interpreter, 'import sage' does not do this. It just happens that the specialized sage interpreter does that at startup time, but that's not normal behavior for a Python package. If there's a way to detect if you're in the sage interpreter it *might* be okay to do this only in that case depending on how other sage users feel (I don't know). But otherwise it's something that should be specified manually in init.sage. -- 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.