0

Python 2.7.5 and OSX 10.8 here

I'm trying to plot some datas I get from a file. I'm trying to code a function where the user is able to plot from the point he wants, and have come to this part of code :

firstPoint = raw_input("1st point to be displayed is n° : ")

tbdata3 = hdulist[3].data
print(hdulist[3].header['TTYPE24'])
print tbdata3.field('DDL_FT_OPL')
print(hdulist[3].header['TTYPE23'])
print tbdata3.field('DDL_SC_OPL')

dataFT=tbdata3.field('DDL_FT_OPL')
plt.subplot(211)
plot(dataFT[firstPoint:400,:])
dataSC=tbdata3.field('DDL_SC_OPL')
plt.subplot(212)
plot(dataSC[firstPoint:400,:])
show()

I get this error :

Traceback (most recent call last):
File "/Users/geoffroysarrazin/Desktop/stage_observatoire/testEkki.py", line 52, in essai
plot(dataFT[firstPoint:400,:])
IndexError: invalid slice

And it seems weird to me, cause I got this with

firstPoint=10

and just before, I had a constant value instead of this input from the user, which was equal to 200 (or whatever <400) and it worked...

4

1 回答 1

1

Simple - you're not converting your input!

firstPoint = int(raw_input("1st point to be displayed is n° : "))

You can add some exception handling to re-prompt the user if he doesn't provide a number, if you so wish.

于 2013-07-09T15:18:09.947 回答