每當(dāng)我將文件保存在Python中時,它都會保存在當(dāng)前的工作目錄中。由于某些未知原因,Python已停止保存pwd。我的圖形現(xiàn)在被保存在它下面的目錄中。因此,/Documents/.../OrbitalMechanics/OrbitalNotes現(xiàn)在不保存它們,而是將它們保存在中/Documents/.../OrbitalMechanics。我的操作系統(tǒng)是Ubuntu 13.04,我正在使用Emacs,并從終端編寫程序。當(dāng)我調(diào)用.py文件時,路徑為emacs ~/Documents/.../OrbitalMechanics/OrbitalNotes/stumpff.py。因此,我在正確的目錄中。什么會導(dǎo)致此問題?保存身材時,我沒有做任何正常的事情。發(fā)生這種情況的程序如下:#!/usr/bin/env ipython # This program plots the Stumpff functions C(z) and S(z) import numpy as npimport pylabfrom matplotlib.ticker import MaxNLocatordef C(z): if z > 0: return (1 - np.cos(z ** 0.5)) / z elif z < 0: return (np.cosh(np.sqrt(-z)) - 1) / -z return 0.5def S(z): if z > 0: return (np.sqrt(z) - np.sin(z ** 0.5)) / np.sqrt(z) ** 3 elif z < 0: return (np.sinh(np.sqrt(-z)) - np.sqrt(-z)) / np.sqrt(-z) ** 3 return 1.0 / 6.0vC = np.vectorize(C)vS = np.vectorize(S)z = np.linspace(-50.0, 500.0, 500000.0)y = vC(z)y2 = vS(z)fig = pylab.figure()ax = fig.add_subplot(111)ax.plot(z, y, 'r')ax.plot(z, y2, 'b')pylab.legend(('$C(z)$', '$S(z)$'), loc = 0)pylab.xlim((-50, 0))pylab.ylim((0, 15))pylab.xlabel('$z$')pylab.gca().xaxis.set_major_locator(MaxNLocator(prune = 'lower'))pylab.savefig('stumpffneg50to0.eps', format = 'eps')以前,當(dāng)我保存圖形時,該圖形將保存在文件所在的目錄中,.py即使我不在該目錄中也是如此。也就是說,我可以在主目錄中,在中運(yùn)行文件emacs,該文件將是我想要保存的位置。現(xiàn)在,即使過去總是將文件保存在python腳本的位置,情況也并非如此。如果我從終端運(yùn)行文件ipython ~/path/to/file,則數(shù)字將保存.py文件所在的位置。如果我打開文件emacs并用于C-c C-c運(yùn)行文件,則文件將從.py文件所在的目錄向下保存一級。如果我cd到該目錄,然后在中打開文件emacs,則該文件再次將向下保存一級。
添加回答
舉報
0/150
提交
取消