Ask Your Question
1

get path of sage script

asked 9 years ago

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!

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 9 years ago

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.

Preview: (hide)
link
0

answered 9 years ago

tmonteil gravatar image

updated 9 years ago

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'
Preview: (hide)
link

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: 9 years ago

Seen: 995 times

Last updated: Apr 11 '16