我正在编写 Windows 中的程序。我启动了我的 linux mint 硬盘驱动器,出于某种原因,它在 mint 中给出了一个错误,但在 Windows 7 中却没有?以下是该程序的 3 个文件:
主要.py:
#-------------------------------------------------------------------------------
# Name: main.py
# Purpose: An RPG (Roll playing game) where you wake up in a room and have
# to figure out text based puzzles to escape.
# The whole game will be done in a terminal (Shell) and will be
# completely text and ascii code. This will be the main file.
#
# Author: William Bryant
#
# Created: 15/12/2013
# Copyright: (c) William Bryant 2013
#-------------------------------------------------------------------------------
import time
import ascii
import quests
#The function that starts/restarts the game
def init():
"""
Calls all the functions to start the game/ restart the game
"""
#Display a cool banner
ascii.ywu_banner(2)
START_INPUT = input("Press ENTER/RETURN on your keyboard to start the game")
time.sleep(0.7)
ascii.clear()
#Game text.
game_text()
def options():
pass
#The text which is the main story line after the banner which gives the player
#A sense of what the setting is about
def game_text():
"""
Prints out a bit of text 2 lines down and clears the screen every 4 or so
seconds.
"""
time.sleep(5)
print("\n\nYour eyes gentally and gradually, open")
time.sleep(4)
ascii.clear()
time.sleep(2)
print("\n\nYou slowly gather your senses and sit up...")
time.sleep(4.5)
ascii.clear()
time.sleep(2)
print("\n\nYou look around the room, and try to make sense of the")
print("environment you are in and to your surprise, you realise your in some")
print("sort of a prison cell!")
time.sleep(12.5)
ascii.clear()
time.sleep(2)
print("\n\nYou place your hand on the wall...")
time.sleep(3)
ascii.clear()
time.sleep(2)
print("\n\n... It feels like some sort of metal.")
time.sleep(4)
ascii.clear()
time.sleep(2)
print('\n\n"How did I get here?", \nYou think to yourself')
time.sleep(4)
ascii.clear()
time.sleep(2)
quests.way_out_quest()
time.sleep(2)
print("\nYou accepted the quest" + ascii.WOODEN_DOOR)
time.sleep(10)
ascii.clear()
ascii.clear()
time.sleep(2)
print("\nYou see a wooden door next to your bed with 5 buttons and a handel... " + ascii.WOODEN_DOOR)
time.sleep(10)
ascii.clear()
time.sleep(2)
print("\n\nYou the figure out that it's some sort of combination lock.")
time.sleep(4)
ascii.clear()
time.sleep(2)
print("\n\nMmm, let me try this: ")
time.sleep(4)
ascii.clear()
time.sleep(2)
#if the file is the main file then start the program
if __name__ == '__main__':
init()
任务.py:
#-------------------------------------------------------------------------------
# Name: quests
# Purpose: To contain quests functions for the game "Yoy wake up..."
#
# Author: William Bryant
#
# Created: 17/12/2013
# Copyright: (c) William Bryant 2013
#-------------------------------------------------------------------------------
import time
import ascii
import main
#Error message if user executes the wrong file.
if __name__ == '__main__':
print("[ERROR]: Do not run this file. Run main.py - this file should not be executed!")
time.sleep(4)
exit()
#Function for the first quest: do you want to find a way out?
def way_out_quest():
"""
If the question is not answered, then the player can't move on. If they say
yes, then they continue through the script. If they say no, then the init
function is called from main.py
"""
way_out_answered = False
while way_out_answered == False:
WAY_OUT_INPUT = input("Quest: Do you want to find a way out? ")
if WAY_OUT_INPUT in ["yes", "Yes", "YES"]:
way_out_answered = True
elif WAY_OUT_INPUT in ["no", "No", "NO"]:
way_out_answered = True
time.sleep(2)
ascii.clear()
print("GAME\nOVER!")
time.sleep (5)
ascii.clear()
main.init()
else:
print("Type yes or no. ")
time.sleep(4)
ascii.py:
#-------------------------------------------------------------------------------
# Name: ascii
# Purpose: To create all the ascii art and graphic tools for the game:
# "you wake up..."
#
# Author: William Bryant
#
# Created: 15/12/2013
# Copyright: (c) William 2013
#-------------------------------------------------------------------------------
import time
import os
WOODEN_DOOR = """ ______________________________
/_____/_____/_____/_____/_____/
._. ._.
| | | |
|_| ______ ______ |_|
|-| /__1__/ /__2__/ |-| ___________
| | | | || ||| ||||
|_| |_| || ||| ||||
._. ._. ||_||| ||||
| | | | _||_|||_||||_
|_| ______ |_|
|-| /__3__/ |-|
| | /\ | |
|_| \/ |_|
._. ._. _____
| | | | ____________________________|_____|
|_| ______ ______ |_| | |______________________________| |
|-| /__4__/ /__5__/ |-| | | | |
| | | | |_| |_|
|_| |_|
_____________________________________________________________________
/_____/ /_____/__/_____/ /_____/ /_____/ /_____/ /_____/ /_____/
/_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/ /_____/"""
#Error message if user executes the wrong file.
if __name__ == '__main__':
print("[ERROR]: Do not run this file. Run main.py - this file should not be executed!")
time.sleep(4)
exit()
#Clear function
def clear():
"""
Clears the console screen using the built in commands on a operating
system (here linux and windows)
"""
os.system(['clear','cls', "^L"][os.name == 'nt'])
#"Wake up..." title/banner at the start
def ywu_banner(num_of_times):
"""
Prints You wake up...(the game name) in ascii code big letters into a
console and clears the screen using the clear function above and reprints
the message to make the dots at the end appear to be moving.
"""
print("__ __ _")
time.sleep(0.25)
print("\ \ / / | |")
time.sleep(0.25)
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
time.sleep(0.25)
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
time.sleep(0.25)
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | _ _ ")
time.sleep(0.25)
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .__(_|_|_)")
time.sleep(0.25)
print(" | | ")
time.sleep(0.25)
print(" |_| ")
time.sleep(0.25)
clear()
for foo in range(num_of_times):
print("__ __ _")
print("\ \ / / | |")
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | _ ")
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .__(_|_)")
print(" | | ")
print(" |_| ")
time.sleep(0.7)
clear()
print("__ __ _")
print("\ \ / / | |")
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | ")
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .__(_)")
print(" | | ")
print(" |_| ")
time.sleep(0.7)
clear()
print("__ __ _")
print("\ \ / / | |")
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | ")
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .___/")
print(" | | ")
print(" |_| ")
time.sleep(0.7)
clear()
print("__ __ _")
print("\ \ / / | |")
print(" \ \_/ /__ _ _ __ ____ _| | _____ _ _ _ __")
print(" \ / _ \| | | | \ \ /\ / / _` | |/ / _ \ | | | | '_ \ ")
print(" | | (_) | |_| | \ V V / (_| | < __/ | |_| | |_) | _ _ ")
print(" |_|\___/ \__,_| \_/\_/ \__,_|_|\_\___| \__,_| .__(_|_|_)")
print(" | | ")
print(" |_| ")
time.sleep(0.7)
clear()
我在 main.py 中使用函数 ascii.ywu_banner(2) 后出现此错误:
Press ENTER/RETURN on your keyboard to start the game
Traceback (most recent call last):
File "main.py", line 102, in <module>
init()
File "main.py", line 26, in init
START_INPUT = input("Press ENTER/RETURN on your keyboard to start the game")
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
最佳答案
您没有指定您使用的是哪个 Python 版本,但我假设您在 Windows 上使用的是 3.x,在 Linux 上使用的是 2.x。 input() 在 Python 2.x 和 Python 3.x 上的工作方式不同。在 2.x 上,它尝试将用户的输入作为 Python 代码进行评估(这非常不安全),如果尝试在 2.x 上运行 3.x 代码,这将解释您的错误。
注意:3.x 的 2.x 等效 input() 被命名为 raw_input() 但无论如何您可能还有一些其他的不兼容性。
关于python - 我的 python 程序在 Windows 7 中运行良好并打印到控制台,但在 Linux Mint 中出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20750797/
我需要在客户计算机上运行Ruby应用程序。通常需要几天才能完成(复制大备份文件)。问题是如果启用sleep,它会中断应用程序。否则,计算机将持续运行数周,直到我下次访问为止。有什么方法可以防止执行期间休眠并让Windows在执行后休眠吗?欢迎任何疯狂的想法;-) 最佳答案 Here建议使用SetThreadExecutionStateWinAPI函数,使应用程序能够通知系统它正在使用中,从而防止系统在应用程序运行时进入休眠状态或关闭显示。像这样的东西:require'Win32API'ES_AWAYMODE_REQUIRED=0x0
关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少
我正在使用Ruby2.1.1和Rails4.1.0.rc1。当执行railsc时,它被锁定了。使用Ctrl-C停止,我得到以下错误日志:~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`gets':Interruptfrom~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`verify_server_version'from~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新rubygems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems
我喜欢使用Textile或Markdown为我的项目编写自述文件,但是当我生成RDoc时,自述文件被解释为RDoc并且看起来非常糟糕。有没有办法让RDoc通过RedCloth或BlueCloth而不是它自己的格式化程序运行文件?它可以配置为自动检测文件后缀的格式吗?(例如README.textile通过RedCloth运行,但README.mdown通过BlueCloth运行) 最佳答案 使用YARD直接代替RDoc将允许您包含Textile或Markdown文件,只要它们的文件后缀是合理的。我经常使用类似于以下Rake任务的东西:
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送