Thanks Leif. inspect.getfile() doesn't seem to do what I want. The situation is that I have a number of scripts, s1.sage, s2.sage, etc, and I'd like them to be able to write to a '.js' file with the same name as their filenames, e.g. s3.sage would write to s3.js, etc. I thought I might be able to do something like open(__name__ + ".js", w")...
On 9 June 2013 15:43, leif <not.rea...@online.de> wrote: > leif wrote: > >> Emil wrote: >> >>> I'd like to know if it's possible to get the filename of a script that's >>> been run using the "load" or "attach" command at the sage: prompt. >>> >>> If I insert a "print __name__" in the script I just get "__main__". >>> >>> I know __name__ isn't the right thing, since I'm not dealing with an >>> imported Python module... But it seems like it could be possible that >>> there is a builtin that gives what I want, but I can't find it... >>> >> >> In Sage, there is attached_files() which gives a list of the filenames. >> >> >> Not sure whether there's some function for just loaded files; doesn't >> seem Sage would keep track of them. >> > > ... but I probably misread your question. > > If the loaded script you want to get the filename of defines some object > foo, you can use inspect.getfile(foo). > > (Probably see also sage/misc/sageinspect.py.) > > > > -leif > > -- > () The ASCII Ribbon Campaign > /\ Help Cure HTML E-Mail > > -- > You received this message because you are subscribed to the Google Groups > "sage-support" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to > sage-support+unsubscribe@**googlegroups.com<sage-support%2bunsubscr...@googlegroups.com> > . > To post to this group, send email to sage-support@googlegroups.com. > Visit this group at > http://groups.google.com/**group/sage-support?hl=en<http://groups.google.com/group/sage-support?hl=en> > . > For more options, visit > https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out> > . > > > -- You received this message because you are subscribed to the Google Groups "sage-support" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-support+unsubscr...@googlegroups.com. To post to this group, send email to sage-support@googlegroups.com. Visit this group at http://groups.google.com/group/sage-support?hl=en. For more options, visit https://groups.google.com/groups/opt_out.