Ask Your Question
1

get path of sage script

asked 2016-04-10 22:04:28 +0100

zionnahi gravatar image

Hi, I'm trying to cerate a sage script that will print it's location on the disk. the most of classical python solutions for this problem, like using the inspect module, doesn't work - they return me the location of temporary files (the files inside the directory which returned by the function tmp_dir() ) instead of the directory of the source file.

Thank you!

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-04-11 17:26:43 +0100

If you attach a file "mine.sage" containing a function f and you want to find the path of that file, you can do

from sage.misc.sageinspect import sage_getfile
sage_getfile(f)

This will return the location of the associated temporary file, the top of which should say

# -*- coding: utf-8 -*-
######################################################################
# This file was *autogenerated* from the file /path/to/mine.sage.
######################################################################

So read that file (using standard Python tools) and parse line 3 to get the path.

edit flag offensive delete link more
0

answered 2016-04-11 15:36:34 +0100

tmonteil gravatar image

updated 2016-04-11 15:45:35 +0100

I am not sure about your question,so perhaps could you make explicit which script you want to run, from where, how it calls Sage, etc, so that we can make an adapted answer.

Anyway, note that from a Sage interpreter, you can get the directory that contains the sage command as follows (in my case, it is /opt/sagemath/sage-source):

sage: import os
sage: os.getenv('SAGE_ROOT')
'/opt/sagemath/sage-source'
edit flag offensive delete link more

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

Stats

Asked: 2016-04-10 22:04:28 +0100

Seen: 905 times

Last updated: Apr 11 '16