Thanks @
snippsat . I had to lookup what REPL meant and found it to be "Read-Eval-Print Loop".
I installed
ptpython and
IPythonIPython . The first seemed only an editor that wasn't even checking syntax, and had no debugging features. The second an interactive shell, and I wasn't familiar with driving it, so couldn't get it to debug. Followed some examples here and there. Obviously a need to read the docs.
I also installed Wing but quickly found it wasn't simple and easy to use. This is all I'm looking for..
* An interactive python debugger that allows syntax checking and code modification, setting breakpoints, stepping through or over code, and ability to inspect variables, strings, arrays, objects,etc,etc.
..Later - have now installed
Visual Studio and the Python extension, so will see if that suits my needs.
Visual Studio Code and Visual Studio are different things. Your link is to Visual Studio Code, or VSCode. Both Visual Studio and VSCode can do Python, but VSCode is superior. I know a lot of people find the similar names confusing.
(Jul-07-2023, 03:37 AM)deanhystad Wrote: [ -> ]Visual Studio Code and Visual Studio are different things. Your link is to Visual Studio Code, or VSCode. Both Visual Studio and VSCode can do Python, but VSCode is superior. I know a lot of people find the similar names confusing.
Thanks for picking that up. Have now had a quick check and it does seem I have installed
Quote:Version: 1.80.0
Commit: 660393deaaa6d1996740ff4880f1bad43768c814
Date: 2023-07-04T13:39:48.236Z
Electron: 22.3.14
ElectronBuildId: 21893604
Chromium: 108.0.5359.215
Node.js: 16.17.1
V8: 10.8.168.25-electron.0
OS: Linux x64 5.15.0-76-generic
I can't find VSCode though ? I do have the Python extension installed as well. Found this -
https://www.freecodecamp.org/news/visual...sualstudio
Visual Studio Code is usually referred to as VSCode.
Visual Studio Code is certainly very powerful, thanks for recommending it. There certainly are deeper layers of variables, both locals and globals, and then variables within variables. One can easily get bogged down. Will it be easier to drive if I simply watch a few variables ? Probably. For example I get the message:
Error:
'NavigableString' object has no attribute 'children'
caused by
print(tag.children.name)
so I need to inspect "tag". Is it an object, a class, a variable ??
(Jul-10-2023, 10:57 PM)jehoshua Wrote: [ -> ]so I need to inspect "tag". Is it an object, a class, a variable ??
Yes,this is more that you have not used
Beautiful Soup much and make mistakes.
Also even if
tag
(bs4.element.Tag) worked,so will this not work as
children
is just and iterator(used in loop),and have no attributes
name
.
Quick example,with a xml that has more content that you previos thread.
from bs4 import BeautifulSoup
with open('breakfast.xml') as f:
file = f.read()
soup = BeautifulSoup(file, 'xml')
food = soup.find('food')
See that
food
is a
bs4.element.Tag
.
>>> type(food)
<class 'bs4.element.Tag'
>>> food.find('price')
<price>$5.95</price>
>>> food.find('price').text
'$5.95'
# This work now but make no sense to use as this
>>> food.children
<list_iterator object at 0x0000017E966A6260>
Iterate over and get both prices.
from bs4 import BeautifulSoup
with open('breakfast.xml') as f:
file = f.read()
soup = BeautifulSoup(file, 'xml')
for tag in soup.find_all('food'):
print(tag.find('price'))
print(tag.find('price').text)
Output:
<price>$5.95</price>
$5.95
<price>$7.95</price>
$7.95
File used
breakfast.xml
:
Output:
<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>
Two of our famous Belgian Waffles with plenty of real maple syrup
</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>
Light Belgian waffles covered with strawberries and whipped cream
</description>
<calories>900</calories>
</food>
</breakfast_menu>