python调用另一个python脚本_Python:调用另一个Python脚本

是否可以调用另一个python脚本来只访问脚本中的定义而不访问其他内容?在

在我要导入的脚本中,有一些绘图我想取消,因为这个其他程序不需要。也就是说,我只想访问Stumpff函数的定义,而不需要绘制图形。在

我要导入的脚本是:#!/usr/bin/env ipython

# This program plots the Stumpff functions C(z) and S(z)

import numpy as np

import pylab

from matplotlib.ticker import MaxNLocator

def 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.5

def 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.0

vC = np.vectorize(C)

vS = np.vectorize(S)

z = np.linspace(-50.0, 500.0, 100000.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, 12))

pylab.xlabel('$z$')

pylab.gca().xaxis.set_major_locator(MaxNLocator(prune = 'lower'))

pylab.savefig('stumpffneg50to0.eps', format = 'eps')

fig2 = pylab.figure()

ax2 = fig2.add_subplot(111)

ax2.plot(z, y, 'r')

ax2.plot(z, y2, 'b')

pylab.legend(('$C(z)$', '$S(z)$'), loc = 1)

pylab.xlim((0, 30))

pylab.ylim((0, 0.5))

pylab.xlabel('$z$')

pylab.gca().xaxis.set_major_locator(MaxNLocator(prune = 'lower'))

pylab.savefig('stumpff0to30.eps', format = 'eps')

fig3 = pylab.figure()

ax3 = fig3.add_subplot(111)

ax3.plot(z, y, 'r')

ax3.plot(z, y2, 'b')

pylab.legend(('$C(z)$', '$S(z)$'), loc = 0)

pylab.xlim((0, 500))

pylab.ylim((0, 0.05))

pylab.xlabel('$z$')

pylab.gca().xaxis.set_major_locator(MaxNLocator(prune = 'lower'))

pylab.savefig('stumpff0to500.eps', format = 'eps')

pylab.show()

之后,我的新脚本能理解C(z)和{}?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值