我试图运行我的python程序,但当我运行它时,什么都没有发生

我试图运行我的python程序,但当我运行它时,什么都没有发生,python,Python,我在运行我用python编写的交互式小故事时遇到了问题。我一直遇到某种非ASCII错误,或者某种不允许我运行程序的错误 如果你想试试,这里有一个程序:[program][1] 这是我的密码: #Programmer: 11/8/12 # Story of Doors # Interactive story where the user can choose between options in between the - - marks. def main(): print "I w

我在运行我用python编写的交互式小故事时遇到了问题。我一直遇到某种非ASCII错误,或者某种不允许我运行程序的错误

如果你想试试,这里有一个程序:[program][1] 这是我的密码:

#Programmer: 11/8/12
# Story of Doors
# Interactive story where the user can choose between options in between the - - marks.

def main():

    print "I welcome you to the mind of the chosen. A place only understood by those who never forfeit. The chance to walk through the halls is given only but once the time has come for you to decide, will you stand aside, or never regret to have tried?"

#Quest is the word used to decide whether the player wants to play or quit.
    Quest = raw_input("  I welcome you to the mind of the chosen. A place only understood by those who never forfeit. The chance to walk through the halls is given only but once the time has come for you to decide, will you stand aside, or never regret to have tried?")

    if(Quest == "stand aside"):
        print "Have fun asleep, for those who will awake are the ones who take the leap." 
    if (Quest == "never regret to have tried"):
        print "I see you think yourself as worthy, I hope you know, this quest is full of low beings"
    print "Down the hall you walked with a line of doors not covered or locked. The choices are at hand with many experiences to be had."
    print "Step into a door and never look back, for your decisions will open a crack. Your choices are at hand, choose from the list written in sand."

#here the reader\player decides what quest he wants to go on, or what door they want to open. 
    Opendoor = raw_input("Door 1: The door of no troubles where you see everything in doubles ") + ("Door 2: ")  
    if(Opendoor == "Door 1"):

        print "The incense infilled maple shaped door was entered to the begin the scene." 
    print "Going straight through to a land engulfed by the waves controlled, where the shore is seen when the machines flee."
    print "Out through a mix of purple and green lies The Beheaded Dragon who whispers and schemes. 'Come to my lab, and enjoy the lick of a colorful tab.'"
    print "After a flash of happy and sad, you see through perspectives and forget the word 'bad'."
    print "With witches and crafts, comes the great Sage whose be riddled with mad."
    print " I know of a place where the sky is purple and nobodies hurtful heaven at night is spoken of. The minds are torn up with a thought of what’s next."


    ComeAlong = raw_input(" Will you -join the quest- or -eschew the test-? ")
    if(ComeAlong == "eschew test"):
       print "'I accept your decline and reply with a good-bye.'"
    if(ComeAlong == "join quest"):
        print "'I'm glad you see yourself as worthy, just remember kid, in here. No mind is sturdy.'"
        print " Here begins a trip to the land of nomads where you witness a dance and give it a try, for you have no doubts as you see with one eye. Forgotten stories of the times of war, for the children are busy learning to soar."
        print "you join this man with not but one rule 'never turn back, for there are consequences for trying to hack.'"
        print "'This is a place of glitches and traps, but the end lies open with stitches to map'"
    Woman = raw_input(" You journey onward through the forest and trees but come across some women on their knees their eyes are locked and only you hold the keys. You're given the choice to open the lock and -allow them to see- or leave them locked and -mimick the birds and the bees-.")   
    if(Woman == "mimick the birds and the bees"):
        print "You approach the women and accept their tease. They looks up at you with a smile, and simultaneously screech 'We see your story has ended and can now be marked as 'deceased' and within a blink of an eye you are paralyzed with nothing to drink."
        wait(2)
    print "Nice try, but this saddly proves, you're not ready to fly. and with that I wave to you a sincere and heart felt good-bye!"
    if(Woman == "allow them to see"):
            print " You approach the women and give them the keys, they grabs them and begin to flee but while the flock reaches there caves one of the women stands beside you and opens the lock."
            print " 'I know where your headed and can lend you my boat, it's right around the corner sitting by the dock.'"
            print " As you follow the woman you look up onto the sky and read aloud 'Take a deep breath and watch your step' confused by the words you ask the woman 'Hey, whats that mean?' with no response you look down to her but see nothing but a stream"
            print " 'Hello!?' you scream, but no one is to be seen. All alone you begin to gleam followed by your lungs releasing the steam"
            print " With that the scene darkens and you rise from your sleep, just to realize life, is but a dream."



# Second Door of choices.

    if(Opendoor == "Door 2"):
        print "This is a story of a young wounded boy, who was lost in his mind with one little toy. He sat on the floor waiting for more, but after an hour his feelings went sour."
        print "He rose up on his feet and started to wonder. Through the bright door there were tons of new people to meet."
        print " He made it his duty to connect with these people, even if they were him in a past life or sequel."
        print " After some time came a decision. To speak with -the man in the white-, or -the woman with no sight-"
        if(Decision == "the man in the white"):
            print " 'Hello mister. May i ask you some questions?'"
            print " 'Why yes you may, but i dont have time to give you a lesson.'"
            print " 'They will be quick i promise, What brings you here to the land of nostradamus?'"
            print " ' Well isnt it obvious? Nothing more than the thirst for knowledge!'"
            print " 'Ahh I see, but what do you do if you cant find the answer to the riddle you speak?'"
            print " 'Then I learn a new language and ask it to Nietzsche' "
            print " 'What if its a question with no answer?'"
            print "' Then I forget about philosophy and become a great dancer! But in all seriousness, you musn't forget for every box of questions there is box of answers'"
        if(Decision == "the woman with no sight"):
            print " 'Hello miss, do you have some free time?'"
            print " ' Ofcourse I do, and i'll give you it for a dime' "
            print " 'If I pay it is not free ' "
            print " 'it's a reward, not a fee.'"
            print " ' okay but if i dont enjoy what you have to say will I still have to pay?'"
            print " ' I'm sorry but you pay for the herbs, not the tea.'"
            print " 'I understand the concept, but i'll have to disagree.'"

            main() 

这是我第一次使用StackOverflow,所以如果我还有什么可以帮你们的,请告诉我。

你们没有提到这是什么版本的Python,但我猜是2.7(它肯定不是3.x)

当我将其保存为文件并在2.7中运行时,我得到以下结果:

SyntaxError:文件中的非ASCII字符“\xe2”./if.py位于第30行,但未声明编码;有关详细信息,请参阅

这正是它所说的。在Python2.7中,如果您想在字符串文本中键入任何非ASCII字符,甚至像
é
这样的东西,那么必须提供编码声明。阅读错误消息中的URL以了解如何执行此操作

另一种方法是转义字符。您不必键入
“Abré”
,而是键入
“Abr\xe9”
——或者,更好的是,键入
u“Abr\u00e9”
——它就会工作


同时,无论如何,您几乎肯定希望字符串是Unicode字符串,而不是8位字符串。这意味着,你需要的不是
“Foo”
,而是
u“Foo”
无处不在。

你没有提到这是什么版本的Python,但我猜是2.7(肯定不是3.x)

当我将其保存为文件并在2.7中运行时,我得到以下结果:

SyntaxError:文件中的非ASCII字符“\xe2”./if.py位于第30行,但未声明编码;有关详细信息,请参阅

这正是它所说的。在Python2.7中,如果您想在字符串文本中键入任何非ASCII字符,甚至像
é
这样的东西,那么必须提供编码声明。阅读错误消息中的URL以了解如何执行此操作

另一种方法是转义字符。您不必键入
“Abré”
,而是键入
“Abr\xe9”
——或者,更好的是,键入
u“Abr\u00e9”
——它就会工作


同时,无论如何,您几乎肯定希望字符串是Unicode字符串,而不是8位字符串。这意味着,您需要的不是
“Foo”
,而是
u“Foo”
无处不在。

在第28行,您有字符
,它不是ASCII字符。您需要将该字符替换为
。这将使程序运行无误。将来,如果遇到类似错误,可以使用以下命令对非ASCII字符执行
grep

grep --color='auto' -P -n "[\x80-\xFF]" your_file.py

其次,您需要将对
main()
的调用放在全局范围内(即前面不应有任何缩进)。现在,它嵌套在一个条件中,当Python解释器读取文件的主体时将不会执行。

在第28行,您有字符
,它不是ASCII字符。您需要将该字符替换为
。这将使程序运行无误。将来,如果遇到类似错误,可以使用以下命令对非ASCII字符执行
grep

grep --color='auto' -P -n "[\x80-\xFF]" your_file.py


其次,您需要将对
main()
的调用放在全局范围内(即前面不应有任何缩进)。现在,它嵌套在一个条件中,当Python解释器读取文件的主体时将不会执行。

对错误消息的精确测试将非常有用。不确定这是否是一个拼写错误,但您的main()应该是意外的,否则它将不起作用……如果_uname u==“uu main”:main()@louism:当然,但这不会导致他在解析过程中出现非ASCII字符错误,这只会使其在不做任何操作的情况下成功退出。@CodeReview上关于非工作代码的钩住问题是非主题的,对错误消息的精确测试将是有用的。不确定是否是打字错误,但您的main()应该是无意的,或者它不起作用……如果uuu name uuu==“\uuuu main”\uuuuu“:main(),您可能需要一个
。@louism:当然,但这不会导致他在解析过程中出现非ASCII字符错误,它只会使它在不做任何事情的情况下成功退出。@codereviewits python 2.4.4中,关于非工作代码的钩住的问题已脱离主题。我试着在每次开场前打个u“但是仍然没有任何东西=\@user1884176:如果我没记错的话,2.4是PEP-263编码声明成为可选的,但还不是强制性的时候。我相信它通常会尝试将源代码解释为拉丁语-1,而不是像2.7那样自动退出…但这并不能保证。因此,如果您希望安全,您仍然需要编写显式转义,或者添加编码声明。@user1884176:PS,您为什么在2012年使用这么旧的Python版本?尤其是如果你是学生的话!它的python 2.4.4。我试着在每次开场前打个u“但是仍然没有任何东西=\@user1884176:如果我没记错的话,2.4是PEP-263编码声明成为可选的,但还不是强制性的时候。我相信它通常会尝试将源代码解释为拉丁语-1,而不是像2.7那样自动退出…但这并不能保证。因此,如果您希望安全,您仍然需要编写显式转义,或者添加编码声明。@user1884176:PS,您为什么在2012年使用这么旧的Python版本?尤其是如果你是学生的话!聪明的引语没有乐趣。不要在允许这些内容进入的地方编辑代码。如果这解决了你的问题,你可以通过点击帖子旁边的复选标记来接受答案:)智能引用没有乐趣。不要在允许这些代码潜入的地方编辑代码。如果这解决了您的问题,您可以单击帖子旁边的复选标记接受答案:)