Having worked through the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016, I naively thought that I knew Python

Head First Python, 2nd Edition by Paul Barry
Having worked through the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016 (Publisher(s): O'Reilly Media, Inc.), I naively thought that I knew Python,

Mike McGrath Python in Easy Steps 2013
But when I started reading Mike McGrath Python in Easy Steps I realized that I don’t even know all the keywords of the Python language. import keyword for word in keyword.kwlist: print(word)

When one reaches the chapter — "Processing requests", there will be problems with Abyss Web Server, the settings made according to the official guide will not help: Adding Python Support.

All examples from the book work when leaving the page ".html" to ".py" page, parameters are passed and everything is displayed.

However, then suddenly everything stops working, even those examples that just worked, when trying to pass something from ".html" to ".py", Abyss Web Server gives the 500 error.

The record in the log: "AttributeError: partially initialized module 'cgi' has no attribute 'FieldStorage' (most likely due to a circular import)."

GUIs with Tkinter (and Fun with Turtles)

Python Turtle Graphics
Turtle graphics is a popular way for introducing programming to kids. It was part of the original Logo programming language developed by Wally Feurzig and Seymour Papert in 1966.

The example that comes with the turtle docs:

from turtle import * color('purple', 'cyan') begin_fill() while True: forward(200) left(170) if abs(pos()) < 1: break end_fill() done()

The example was found in the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016, Publisher(s): O'Reilly Media, Inc.

Getting UserAgent and Browser name in Flask, Python

Head First Python, 2nd Edition by Paul Barry
Inspired by the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016, Publisher(s): O'Reilly Media, Inc.
where some examples don't work
Pages 296-300 of that book

Task 4: Create Code to Work with Our Webapp’s Database and Tables


Determine the Flask version.
First way: two lines in IDLE import flask print(flask.__version__) Second way: one command in Command line: pip show flask The installed Flask version is uptodate - 3.0.3
Determine the Python version.
First way: two lines in IDLE from platform import python_version python_version() Second way: one command in Command line again: python -V The installed Python version is uptodate too - 3.12.3
Coding in Python, Flask from flask import Flask from flask import render_template, request The method request.user_agent.browser returns nothing.
The next method requires one more importing from ua_parser import user_agent_parser
These three lines returns the browser name in browser variable: web_detail = str(request.user_agent) user_browser = user_agent_parser.ParseUserAgent(web_detail) browser = user_browser['family'] or briefer in single code line user_agent_parser.Parse(request.user_agent.string)['user_agent']['family'] I digress a little from the main trend of this note and give a method that receives all the User Agent: request.headers.get("user-agent")

Summing up, at the beginning, I believed the problem was that
"request.user_agent.browser" did not return anything and found other methods to get the browser name. But still nothing was written to the database. I couldn't write to the field "browser_string" in the table "log" of the database "vsearchlogDB" anything, the value after insert operation was Null

How to Fix ImportError: cannot import name 'escape' from

Head First Python, 2nd Edition by Paul Barry
ImportError: cannot import name 'escape' from 'flask'
or
ImportError: cannot import name 'escape' from 'jinja2'
There is no possibility to import name 'escape' from 'flask' (or jinja2).
Today the simplest way is to use from markupsafe import escape instead of from flask import escape.

Jinja is a dependency of Flask and Flask V1.X.X uses the escape module from Jinja, however support for the escape module was dropped in newer versions of Jinja.

Markup and escape should be imported from MarkupSafe.
from flask import escape was found on the page in the article It’s Time to Escape (Your Data) in the book "Head First Python, 2nd Edition" by Paul Barry, released November 2016, Publisher(s): O'Reilly Media, Inc.