How ChatGPT can Comment Computer Code

Mark McWiggins
2 min readNov 27, 2024

I just sent ChatGPT this code:

#!/usr/bin/env python3
from flask import Flask, render_template, request, Blueprint

app = Flask(__name__)
bp = Blueprint(‘my_routes’, __name__)
app.register_blueprint(bp)

import logging
from flask import Flask

# Set up logging
logging.basicConfig(
filename=’app.log’, # Log file name
level=logging.DEBUG, # Logging level
format=’%(asctime)s [%(levelname)s] %(message)s’, # Log format
datefmt=’%Y-%m-%d %H:%M:%S’ # Date format
)

@app.route(‘/cgi-bin/example’, methods=[‘POST’])
def example():
data = request.form
needs = request.form[‘needs’]
quals = request.form[‘quals’]
# Or request.json, request.data, etc., depending on your needs
return f”Received data {needs} {quals}”, 200

@app.route(‘/error’)
def error_route():
try:
1 / 0 # Simulate an error
except ZeroDivisionError as e:
app.logger.error(‘An error occurred: %s’, e)
return ‘This route has an error.’

# Route for the home page
@app.route(‘/’)
def home():
return render_template(‘index.html’)

# Route for a simple greeting
@app.route(‘/greet’, methods=[‘GET’, ‘POST’])
def greet():
if request.method == ‘POST’:
name = request.form.get(‘name’, ‘World’)
return f”Hello, {name}!”
return ‘’’
<form method=”POST”>
<label for=”name”>Enter your name:</label
‘’’
@app.route(‘/resumefront’, methods=(‘GET’, ‘POST’))

def resumefront():
# Example data for the table
rows = [
{“needs0”: “”, “qualifications0”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”},
{“needs”: “”, “qualifications”: “”}

]
return render_template(‘resumefront.html’, rows=rows)

if __name__ == “__main__”:
app.run(debug=True)

And ChatGPT responded with this:

#!/usr/bin/env python3
# Import required modules and functions
from flask import Flask, render_template, request, Blueprint

# Create the Flask application instance
app = Flask(__name__)

# Create a Blueprint for routing modularity (though not utilized much here)
bp = Blueprint(‘my_routes’, __name__)

# Register the blueprint with the app
app.register_blueprint(bp)

# Import logging for debugging and error reporting
import logging

# Set up logging configuration
logging.basicConfig(
filename=’app.log’, # Log file name where logs are saved
level=logging.DEBUG, # Log level (DEBUG for detailed logs)
format=’%(asctime)s [%(levelname)s] %(message)s’, # Log format
datefmt=’%Y-%m-%d %H:%M:%S’ # Date format in the logs
)

# Define a route to handle POST requests at ‘/cgi-bin/example’
@app.route

That’s it; Mark McWiggins

The ChatGPT Logo
ChatGPT is Indispensable!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response