2013-12-10 54 views
0

因此,我現在正在進行圖像解析,並且有一段糟糕的時間。Python在分析時意外的EOF 4

這是我的代碼:

import urllib.request 
import turtle 
import drawing 

# define a location for our file 
url = 'http://i5.nyu.edu/~cmk380/pythondata/' 

# open a connection to the URL 
response = urllib.request.urlopen(url) 

# read data from URL as a string 
data = response.read().decode('utf-8') 

image = input('Enter an image filname:') 

newurl = url+image+'.txt' 

if int(image[5]) <= 0: 
    print('Sorry,',newurl,'doesn\'t exist.') 

else: 
    print('Success! I was able to find ',newurl) 

# define a location for our file 
newurl2 = newurl 

# open a connection to the URL 
response = urllib.request.urlopen(newurl2) 

# read data from URL as a string 
data = response.read().decode('utf-8') 

#obtain data 
print(data) 

#turn data into a string and convert to float 
string = data 
splitstring = string.split(',') 

splitstring[0]=float(splitstring[0]) 
splitstring[1]=float(splitstring[1]) 
splitstring[2]=float(splitstring[2]) 


for index in range (4,len(splitstring)): 
    if splitstring[index] == 'b': 
     print('\n') 

    else: 
     drawing.draw_box(float(splitstring[0]),float(splitstring[1],float(splitstring[2]), float(splitstring[index]), float(splitstring[index]), float(splitstring[index]) 

這是我的函數:

# draw a box at position x, y 
# width and height will be w & h 
# r, g and b will be the color 
def draw_box(x, y, w, h, r, g, b): 
    turtle.penup() 
    turtle.goto(x,y) 
    turtle.setheading(0) 
    turtle.pendown() 
    turtle.pencolor(float(r), float(g), float(b)) 
    turtle.fillcolor(float(r),float(g),float(b)) 
    turtle.begin_fill() 
    for x in range(4): 
     turtle.forward(w) 
     turtle.right(90) 
    turtle.end_fill() 

的問題就在節目的最後出現,我一直用它擺弄的年齡。請幫忙!

回答

0

在上次致電drawing.draw_box時,您的括號未關閉。因此,在查找函數調用的結尾時,它會觸及文件的結尾。

另外通過的第二個值未關閉,float(splitstring[1] < -

相關問題