[英]Python Executables Running on Earlier Versions
Lets say Person 1 has a python executable file (mac) that was written in Python 3.x. 让我们说Person 1有一个用Python 3.x编写的python可执行文件(mac)。 Person 1 sends said file to Person 2, who also has a mac, but only has Python 2.6.1.
Person 1将所述文件发送给Person 2,Person 2也有一个mac,但只有Python 2.6.1。 When Person 2 runs that file, will it work?
当Person 2运行该文件时,它会起作用吗?
Someone said they needed to see the code, so: 有人说他们需要看代码,所以:
#!/usr/bin/env python
# -*- coding: UTF8 -*-
topo1 = 0
topo2 = 0
print("This program helps compare two players: ")
print("It only uses that player's stats from the previous two years to determine their worth in fantasy baseball")
def complay1():
global topo1
print("Enter in the first player's stats below")
homerun = input("Enter in the player's home run total from the most recent year: ")
sb = input("Enter in the player's stolen base total from the most recent year: ")
hit = input("Enter in the player's hit total from the most recent year: ")
walks = input("Enter in the player's walk total from the most recent year: ")
doubles = input("Enter in the player's doubles total from the most recent year: ")
rbi = input("Enter in the player's RBI total from the most recent year: ")
ba = input("Enter in the player's batting average from the most recent year, do not include a decimal point: ")
hitL = input("Enter in the player's hit total from the year before the most recent year: ")
homerunL = input("Enter in the player's home run total from the year before the most recent year: ")
age = input("Enter in the player's age: ")
gp = input("How many games did the player play last year?: ")
topo1 += int(homerun)*3
topo1 += int(sb)*2
topo1 += int(hit)/2.5
topo1 += int(walks)/4
topo1 += int(doubles)
topo1 += int(rbi)/3
topo1 += int(hitL)/15
topo1 += int(homerunL)
topo1/(int(gp)/4)
topo1 -= int(age)
topo1 += int(ba)/2
print(topo1, "is the total PLV+ for this player")
def complay2():
global topo2
print("Enter in the second player's stats below")
homerun = input("Enter in the player's home run total from the most recent year: ")
sb = input("Enter in the player's stolen base total from the most recent year: ")
hit = input("Enter in the player's hit total from the most recent year: ")
walks = input("Enter in the player's walk total from the most recent year: ")
doubles = input("Enter in the player's doubles total from the most recent year: ")
rbi = input("Enter in the player's RBI total from the most recent year: ")
ba = input("Enter in the player's batting average from the most recent year, do not include a decimal point: ")
hitL = input("Enter in the player's hit total from the year before the most recent year: ")
homerunL = input("Enter in the player's home run total from the year before the most recent year: ")
age = input("Enter in the player's age: ")
gp = input("How many games did the player play last year?: ")
topo2 += int(homerun)*3
topo2 += int(sb)*2
topo2 += int(hit)/2.5
topo2 += int(walks)/4
topo2 += int(doubles)
topo2 += int(ba)/2
topo2 += int(rbi)/3
topo2 += int(hitL)/15
topo2 += int(homerunL)
topo2/(int(gp)/4)
topo2 -= int(age)
topo1 += int(ba)/2
print(topo2, "is the total PLV+ for this player")
complay1()
complay2()
if topo1 > topo2:
print("Player 1 is", ((topo1/topo2)*100)-100, "percent better")
if topo2 > topo1:
print("Player 2 is", ((topo2/topo1)*100)-100, "percent better")
Probably not, the major version changes have no backward compatiblity. 可能不是,主要的版本更改没有向后兼容性。
EDIT : For your code example, it probably works. 编辑 :对于您的代码示例,它可能有效。 The only thing changed between 2 and 3 in your script is that print isn't a function in Python 2, which is unimportant because print(x) is the same as print x for the Python 2 interpreter, extra brackets don't hurt.
在脚本中,2和3之间唯一的变化是print不是Python 2中的函数,这是不重要的,因为print(x)与Python 2解释器的print x相同,额外的括号不会受到影响。
EDIT2 : The division will break too, as said in a different answer. EDIT2 :正如另一个答案中所说,该部门也会破裂。 This is because int/int will result in an int in Python 2 and in an float in Python 3. This means
5 / 2
is 2 in Python 2 and 2.5 in Python 3. from __future__ import division
fixes this. 这是因为int / int将导致Python 2中的int和Python 3中的float。这意味着
from __future__ import division
在Python 5 / 2
为2,在Python 3中from __future__ import division
2.5。 from __future__ import division
修复此问题。
It's impossible to be completely certain without seeing the code, but there have been a lot of changes between 2.x and 3.x, making it extremely unlikely to work. 没有看到代码就不可能完全确定,但2.x和3.x之间有很多变化,使其极不可能发挥作用。
EDIT: 编辑:
The division will break it. 该部门将打破它。 Put
from __future__ import division
at the top. from __future__ import division
放在顶部。 Also, check if raw_input
exists, assigning it to input
. 另外,检查
raw_input
存在,将其分配给input
。
What do you mean by executable? 可执行文件是什么意思? My idea of a python executable is that python is bundled in it so the end user doesn't ever need to install python to run it.
我对python可执行文件的想法是python被捆绑在其中,因此最终用户不需要安装python来运行它。
If you mean just the .py, looking at the code you posted, it looks compatible. 如果你的意思是.py,看看你发布的代码,它看起来兼容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.