Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9036973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:08:03+00:00 2026-06-16T09:08:03+00:00

I have a Python script that connects to a website via FTP and lists

  • 0

I have a Python script that connects to a website via FTP and lists the current version numbers of programs located on the website. I created an array to hold the version numbers till the script would pick the largest number out of the array and tell me what it was. For example my array would usually look like this:

array = ['1.04','1.6','1.14']

So I used…

max_in_array = max(array) 

to return the largest value in the array.

Unfortunately, I received ‘1.6’ as the largest number when, in fact, ‘1.14’ is the latest version number.
The only other thing I could think to do is to cut off the ‘1.’ from the list of arrays so that I receive:

array = ['04','6','14']

And then paste it back on to get the full version number. But since this website contains many versions such as ‘2.02.04’ and ‘1.14.01’ I don’t know how to efficiently do that.

Any help would be greatly appreciated!


os.chdir("./gnu/"+_package)

pope = len(_package) + 1 ## Cuts off name of program
char = len(_package) - 12 ## Cuts off extension ".tar.gz"

for tok in glob.glob("*.tar.gz"):
    token.append(tok) ## Appends name to array
    bork = max(token) ## Gets max version number (sometimes useless)
    print bork
    char = len(bork) - 7

for _gnu in glob.glob("*.tar.gz"): ## Finds only matches with .tar.gz
    _gnuapp.append(_gnu[pope:char]) ## Appends version number to array
    spoke = max(_gnuapp) ## Gets max version number
    _ver = _package + "-" + spoke + ".tar.gz" ## Compiles the package name, ver #, and extension
    _down(_user, _ver, _package) ## Opens information in download module 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:08:04+00:00Added an answer on June 16, 2026 at 9:08 am

    Edit: Sorry, misinterpreted the question at first – see this answer for a few methods regarding comparing version numbers. Taking the second answer in there (which suggests using distutils.version‘s StrictVersion), you can try this:

    In [3]: from distutils.version import StrictVersion
    
    In [4]: s = ['1.04','1.6','1.14', '2.02.04', '1.14.01']
    
    In [5]: max(s, key=StrictVersion)
    Out[5]: '2.02.04'
    

    One thing to note is that you are actually comparing strings and not numbers. One thing you can do to ensure that you are comparing the number themselves (disregarding that you want to do with the item afterwards) is to provide a key to the max function:

    In [1]: s = ['1.04','1.6','1.14']
    
    In [2]: max(s, key=float)
    Out[2]: '1.6'
    

    Since you are looking to compare float values (and not the strings), this compares the float equivalents of the strings. However it may be best to convert those to floats before proceeding:

    In [4]: s = ['1.04','1.6','1.14']
    
    In [5]: s_floats = [float(x) for x in s]
    
    In [6]: s_floats
    Out[7]: [1.04, 1.6000000000000001, 1.1399999999999999]
    

    You can then use max as you expect:

    In [9]: max(s_floats)
    Out[9]: 1.6000000000000001
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a python script that connects to a local MySQL db. I know
I have a python script that connects to an external host, fetches some data,
I have a python script using imaplib that connects to a gmail account and
I have a python script I wrote that connects me to a VPN. Before
I have a Python command line script that connects to a database, generates files
I'm trying write a python 2.7 script, that connects to a server via SSL
I have a python script that runs a program, which generates few .exe files
I have a python script that I want always to run in the background.
I have a Python script that makes use of 'Print' for printing to stdout.
I have a Python script that needs to issue a number of shell commands.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.