because line.split() splits the elements in the current line and since
there's only one element in each line, indices higher than 0 don't
exist.
I think you want the values in light.txt to be written in one line:
5 2 6 8 2 1
have a look at this:
def openLight():
file = open("C:\Users\Admin\.nuke\light.txt", 'r')
data = file.readlines()
for line in data :
light = line.split()
print "light:", light
# x = float(light[0])
# y = float(light[1])
# z = float(light[2])
# r = float(light[3])
# g = float(light[4])
# b = float(light[5])
file.close()
gr
arno
On 29 apr 2012, at 17:11, oasfc wrote:
> im trying to read in and float infomation from a text file, however I dont
> seem to be having any luck getting my script to recognise anything from past
> the first line, and sometimes for no apparant reason it wont even recognise
> the first line correctly.
>
> def openLight():
>
> file = open("C:\Users\Admin\.nuke\light.txt", 'r')
>
> data = file.readlines()
> for line in data :
> light = line.split()
> x = float(light[0])
> y = float(light[1])
> z = float(light[2])
> r = float(light[3])
> g = float(light[4])
> b = float(light[5])
> file.close()
>
>
> For reference the .txt im trying to read in is just simply:
>
> 5
> 2
> 6
> 8
> 2
> 1
>
>
> The error i seem to be getting in Nuke is:
>
> Traceback (most recent call last):
> File "", line 12, in
> IndexError: list index out of range
>
> Any help would be appreciated. Thanks
> _______________________________________________
> Nuke-python mailing list
> [email protected], http://forums.thefoundry.co.uk/
> http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python
_______________________________________________
Nuke-python mailing list
[email protected], http://forums.thefoundry.co.uk/
http://support.thefoundry.co.uk/cgi-bin/mailman/listinfo/nuke-python