Reputation: 131
I have some code like this:
def checkupdate():
build_version = 1.8
server = 'server ip'
ftp2 = ftplib.FTP(server)
ftp2.login()
writeversion = open("latest_version.txt", "w")
ftp2.retrlines('RETR latest_version.txt', writeversion.write())
writeversion.write(latestversion)
writeversion.close()
latestversion2 = open("latest_version.txt", "r")
latestversion3 = latestversion2.readline()
if latestversion3 > build_version:
tkMessageBox.showwarning("Updater", "There is a new version. Please check our site.")
elif latestversion3 == build_version:
tkMessageBox.showinfo("Updater", "Current version:%d, is the latest." % build_version)
else:
tkMessageBox.showinfo("Updater", "Current version:%d is the latest." % build_version)
latestversion2.close()
os.unlink("latest_version.txt")
However, everytime i run this, it cant write the version fetched from the ftp server to latest_version.txt, and the file is empty. It also tells me that there is always a new version. Any way to get this piece to work?
Upvotes: 1
Views: 38
Reputation: 123608
You are comparing different types here. build_version
is considered as a float
and latestversion3
as a string
. As such, what you're observing is perfectly expected:
>>> "1.6" > 1.7
True
>>> "0.42" > 1.7
True
One fix would be to declare as a string:
build_version = "1.8"
However, you might run into problems if you try to compare version numbers such as 1.7.1
and 1.7.10
. You should be using disutils.version
in order to compare version numbers.
Upvotes: 1