简体   繁体   English

python sage从命令行附加并运行另一个命令

[英]python sage attach from command line and run another command

I want to load a sage file and run a function from that file, all from bash. 我想加载一个鼠尾草文件并从该文件运行功能,所有这些都来自bash。

The attach command is giving me trouble... attach命令给我带来麻烦...

This works: 这有效:

bash-prompt$ sage -c "print 2; print 3"
2
3
bash-prompt$

This also works: 这也适用:

bash-prompt$ sage -c "attach somefile.sage"
some print just to confirm the file is loaded
bash-prompt$

But this doesn't work: 但这不起作用:

bash-prompt$ sage -c "attach somefile.sage; print 3"
python: can't open file '/path/to/somefile.sage; print Integer(3)': [Errno 2] No such file or directory

How can I get this to work, or what can I do instead? 如何使它正常工作,或者我该怎么办?

If it helps someone... 如果可以帮助某人...

I ended up using this monstrosity: 我最终使用了这种怪物:

sage somefile.sage && sage -python -c "execfile('somefile.py'); wrapper()" && rm somefile.py

Ok, the rm part is not really all that necessary :) 好的, rm部分实际上并不需要全部:)

我认为最简单的方法是在实际的Sage文件的最后一行调用该函数:例如,“ somefile.sage”的最后一行print 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM