python – 从.py到.exe
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python – 从.py到.exe,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4587字,纯文字阅读大概需要7分钟。
内容图文
![python – 从.py到.exe](/upload/InfoBanner/zyjiaocheng/742/6bfeab687f0b4025ab79e8854530f738.jpg)
好的,相关的信息可以在这个帖子中找到(这就是他们在这里被称为什么?).
Python Calculator Divide by Zero/Sqrting a Neg. Int. crashing program
对不起,如果我应该把它保留到那个线程,我不熟悉这里的礼节,也不确定是否会被看到.
无论如何,我对那里给出的代码做了一些修改.这是我目前的最终产品.
import math
def convertString(str):
try:
returnValue = int(str)
except ValueError:
returnValue = float(str)
return returnValue
def addition(a, B):
return convertString(a) + convertString(B)
def subtraction(a, B):
return convertString(a) - convertString(B)
def multiplication(a, B):
return convertString(a) * convertString(B)
def division(a, B):
return convertString(a) / convertString(B)
def sqrt(a):
return math.sqrt(convertString(a))
def expo(a, B):
x = convertString(a)
y = convertString(B)
return math.pow(x, y)
def fact(a):
return math.factorial(convertString(a))
keepProgramRunning = True
print "Welcome to [Removed]'s 2011 4-H Project! This is a simple calculator coded in Python, which is a high-level programming language. Java, C, C++, and Perl are other high-level programming languages that you may have heard of. Press Enter to get started!"
print ""
raw_input('')
while keepProgramRunning:
print "Please select what you would like to do:"
print ""
print "1) Addition"
print "2) Subtraction"
print "3) Multiplication"
print "4) Division"
print "5) Square Root"
print "6) Exponentiation"
print "7) Factorial"
print "8) Quit Program"
print ""
print "Input the number of the action that you wish to do here, then press Enter:",
choice = raw_input()
if choice == "1":
print ""
numberA = raw_input("Enter the first addend: ")
numberB = raw_input("Enter the second addend: ")
print ""
print "The sum of those numbers is", addition(numberA, numberB)
print ""
print "Press the Enter key to continue."
raw_input('')
elif choice == "2":
print ""
numberA = raw_input("Enter the first term: ")
numberB = raw_input("Enter the second term: ")
print ""
print "The difference of those numbers is", subtraction(numberA, numberB)
print ""
print "Press the Enter key to continue."
raw_input('')
elif choice == "3":
print ""
numberA = raw_input("Enter the first factor: ")
numberB = raw_input("Enter the second factor: ")
print ""
print "The product of those numbers is", multiplication(numberA, numberB)
print ""
print "Press the Enter key to continue."
raw_input('')
elif choice == "4":
print ""
numberA = raw_input("Enter the dividend: ")
numberB = raw_input("Enter the divisor: ")
while float(numberB) == 0:
print ""
print "You cannot divide by zero. Please choose another divisor."
print ""
numberB = raw_input("Enter your divisor: ")
print ""
print "The quotient of those numbers is", division(numberA, numberB)
print ""
print "Press the Enter key to continue."
raw_input('')
elif choice == "5":
while True:
print ""
numberA = raw_input("Enter the number you wish to find the square root of: ")
if float(numberA) >= 0:
break
print ""
print "You cannot take the square root of a negative number."
print ""
print "The square root of that number is", sqrt(numberA)
print ""
print "Press the Enter key to continue."
raw_input('')
elif choice == "6":
print ""
numberA = raw_input("Enter the base: ")
numberB = raw_input("Enter the exponent: ")
print ""
print "The solution to that expression is", expo(numberA, numberB)
print ""
print "Press the Enter key to continue."
raw_input('')
elif choice == "7":
while True:
print ""
numberA = raw_input("Enter the number you wish to find the factorial of: ")
if float(numberA) >= 0:
break
print ""
print "You can only find the factorial of non-negative integers."
print ""
print "The factorial of that number is", fact(numberA)
print ""
print "Press the Enter key to continue."
raw_input('')
elif choice == "8":
print ""
print "Goodbye! Thank you for your time spent both judging my project and those of everyone else! Have a nice day! :)"
print ""
print "Press the Enter key to close."
raw_input('')
keepProgramRunning = False
else:
print ""
print "The key you have selected is not assigned to an action. Please choose from the listed options."
print ""
print "Press the Enter key to continue."
raw_input('')
我已经解决了关闭问题,并且我已经完成了它以确保一切正常并且正确显示(间隔线应该是它们的位置,没有字在线之间分开等).现在我(相信我)准备好让它成为独立的.从我所看到的可能,甚至应该添加任何导入的东西(在这种情况下,数学库(我相信它是所谓的.)是导入的,因此它将被包含在独立版本中,正确?).所以,正如我的标题所说,我如何从Python文件转到可执行文件?我已经尝试过自己找到答案了,但是给出的工具要么已经过时,要么不起作用(至少我是如何使用它们的.).
有什么建议?
解决方法:
正如你提到的其他questons和过时的工具(我假设你的意思是py2exe,从2008年的最后一次更新),看看PyInstaller及其documentation.
另一个工具是cx_freeze.
内容总结
以上是互联网集市为您收集整理的python – 从.py到.exe全部内容,希望文章能够帮你解决python – 从.py到.exe所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。