(python)(2.7.7)代码中出现奇怪的语法错误

时间:2014-09-10 01:16:58

标签: python python-2.7 boolean syntax-error

from PIL import Image    
import input_class    
import input_function    
import input_crop_values    
import input_translate

class ImageChanger():

def __init__ ():
    image_filename = input_class.input_file_name()
    self.my_image = Image.open(image_filename)

    chosen_Function = input_function.input_vaild_function()

    if chosen_Function == "Crop" or chosen_Function == "crop":
        crop_values = input_crop_values.input_crop_data()
        my_image.crop(crop_values)

    elif chosen_Function == "Translate" or chosen_function == "translate":
        translate_values = input_translate.input_translate_data()
        my_image.crop(translate_values)
    else:
        print("unexpected error while running code")


def printState():
    print( "Your image file name is %s" % self.my_filename );
    return (self.my_filename);

def translate(self,x_cord,y_cord):
    return (self.my_image.offset(x_cord,y_cord));

def crop(self, box):
    return (self.my_image.crop(box))
抱歉奇怪的格式化,

错误:

Traceback (most recent call last):
  File "C:\Users\Alexander\Desktop\Final_Udacity_project\dragon_picture_test.py", line 1, in <module>
    import picture_changer
  File "C:\Users\Alexander\Desktop\Final_Udacity_project\picture_changer.py", line 3, in <module>
    import input_function
  File "C:\Users\Alexander\Desktop\Final_Udacity_project\input_function.py", line 14
    else
       ^
SyntaxError: invalid syntax

我有一些其他功能,未列出使用输入命令类似用户界面,然后将其返回给更大的类。

返回值的位置和返回的位置是:

line 8*: image_filename = input_class.input_file_name() # you would give a name of a picture here,

line 10*:  chosen_function = input_function.input_vaild_function()  # you Would give it either crop or translate can be sentence case or lowercase

line 11*:  crop_values = input_crop_values.input_crop_data()  # you would give it data in brackets like [1,2,3,4] and it would crop it.

line 15*: translate_values = input_translate.input_translate_data() # you would give it information in ( ), like (1,2,3,4) and it would translate it. 

代码对布尔的行为非常奇怪,错误消息对我没那么大帮助。

1 个答案:

答案 0 :(得分:0)

else,与块之前的其他语句一样,需要冒号。

else:
相关问题