Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Example Python Scripts to Python3 or Specify Python2 Requirement in Docs #588

Closed
TomMoeras opened this issue Nov 16, 2023 · 2 comments

Comments

@TomMoeras
Copy link

While browsing through the example scripts in the docs, I noticed that the Python scripts seem to utilize Python 2 print statements. This could potentially lead to errors when running these scripts in a Python 3 environment. So not really a big issue and something that can be easily resolved.

One of the scripts uses the following structure:

# /examples/Program-examples/01_Python/primes.py
#! /usr/bin/env python
import datetime
import time
import sys

def print_time(str):
    now = time.time()
    st = datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S')
    print str, st
    return int(now)

def ask_int(prompt, retries=3):
    while True:
        num = int(input(prompt))
        if num > 1:
            return num
        else:
            print "Please enter an integer which is bigger than one."
            retries -= 1
        if retries <= 0:
            print('Too many attempts, try again later.')
            sys.exit()

The print statements in this script are written in the Python 2 style, without parentheses, which would lead to syntax errors in Python 3.

Possible fixes are:

  1. Update the Scripts: The scripts could be updated to Python 3. This would involve minor changes, such as modifying print statements to use parentheses.
  2. Specify Python Version in Documentation: Alternatively, if maintaining the scripts in Python 2 is preferable, it would be beneficial to clearly specify in the documentation that these scripts are intended to be run with Python 2.
@boegel
Copy link
Member

boegel commented Jan 20, 2024

@laraPPr Is this fixed with #592?

@laraPPr
Copy link
Contributor

laraPPr commented Jan 20, 2024

Yes, those were all updated.

@boegel boegel closed this as completed Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants