Ask Your Question

Can I alias a sage command?

asked 2015-08-31 13:42:56 -0600

rexroni gravatar image

updated 2015-08-31 14:19:07 -0600

If I type alias, I get a list of aliases, but they all look very "bashy", and not like sage commands. Can I set an alias for a sage command? Like alias 'meh'='load("meh.sage")'?

I have looked on this site, the "SAGE for newbies" document I found by Ted Kosan,, and the general web, and I haven't found any documentation on aliases in sage.

When I run that, I get the following output:

sage: alias 'meh'='load("meh.sage")'
ValueError                                Traceback (most recent call last)
<ipython-input-118-7d3257e61ed9> in <module>()
----> 1 get_ipython().magic(u'alias \'meh\'=\'load("meh.sage")\'')

/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
   2302         magic_name, _, magic_arg_s = arg_s.partition(' ')
   2303         magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2304         return self.run_line_magic(magic_name, magic_arg_s)
   2306     #-------------------------------------------------------------------------

/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
   2223                 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
   2224             with self.builtin_trap:
-> 2225                 result = fn(*args,**kwargs)
   2226             return result

/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/magics/osm.pyc in alias(self, parameter_s)

/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    191     # but it's overkill for just that one bit of state.
    192     def magic_deco(arg):
--> 193         call = lambda f, *a, **k: f(*a, **k)
    195         if callable(arg):

/usr/lib/sagemath/local/lib/python2.7/site-packages/IPython/core/magics/osm.pyc in alias(self, parameter_s)
    117         # Now try to define a new one
    118         try:
--> 119             alias,cmd = par.split(None, 1)
    120         except TypeError:
    121             print(oinspect.getdoc(self.alias))

ValueError: need more than 1 value to unpack
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-08-31 14:51:28 -0600

eric_g gravatar image


The easiest way is to define a Python function:

sage: def meh():
....:     load("meh.sage")
sage: meh()  # executes load("meh.sage")

Best wishes,


edit flag offensive delete link more


Ok, I did know about that, but I figured there must be a way to use the aliases, since aliases exist. Any insight into the aliasing then, if it isn't useful for sage commands?

rexroni gravatar imagerexroni ( 2015-09-02 12:42:08 -0600 )edit

"alias" is an IPython feature. The sage command line is IPython with some customizations. See for documentation.

nbruin gravatar imagenbruin ( 2015-09-10 22:59:10 -0600 )edit

Ah, thank you. That was the second half of the answer I was looking for. When I have 15 rep someday I'll come back and upvote your comment.

rexroni gravatar imagerexroni ( 2015-09-13 10:07:34 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-08-31 13:42:56 -0600

Seen: 219 times

Last updated: Aug 31 '15