Apr-14-2020, 01:57 PM
Hi
Trying to understand how to use "from…import…as"
I recorded in "test.py" this extract from a script I'm presently coding
and I however passed a positional parameter.
So, I'm quite confused
Arbiel
Trying to understand how to use "from…import…as"
I recorded in "test.py" this extract from a script I'm presently coding
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from html.parser import HTMLParser from unicodedata import name as ucd_nom from unicodedata import lookup as ucd_car #import xml.etree.ElementTree from xml.etree.ElementTree import ElementTree as arbre from xml.etree.ElementTree import Element as xml def le_fichier_xml(): """Table de correspondance.""" return '/home/remi/Documents/programmation/python/grec_vocab/alphabet.xml' le_fichier_xml() larbre=arbre() alphabet=larbre.parse(le_fichier_xml()) for elem in list(alphabet): print(elem.tag, elem.attrib)No problem when I run it
remi@remi-Vostro-3550:~$ python '/home/remi/Documents/programmation/python/test.py' div {'id': 'simples'} div {'id': 'combinées'} remi@remi-Vostro-3550:~$If I skip the line 15:
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys from html.parser import HTMLParser from unicodedata import name as ucd_nom from unicodedata import lookup as ucd_car #import xml.etree.ElementTree from xml.etree.ElementTree import ElementTree as arbre from xml.etree.ElementTree import Element as xml def le_fichier_xml(): """Table de correspondance.""" return '/home/remi/Documents/programmation/python/grec_vocab/alphabet.xml' le_fichier_xml() #larbre=arbre() #alphabet=larbre.parse(le_fichier_xml()) alphabet=arbre.parse(le_fichier_xml()) for elem in list(alphabet): print(elem.tag, elem.attrib)it does not run any longer
remi@remi-Vostro-3550:~$ python '/home/remi/Documents/programmation/python/test.py' Traceback (most recent call last): File "/home/remi/Documents/programmation/python/test.py", line 17, in <module> alphabet=arbre.parse(le_fichier_xml()) TypeError: parse() missing 1 required positional argument: 'source' Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module> from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module> import apport.fileutils File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module> from apport.packaging_impl import impl as packaging File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in <module> import apt File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module> import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' Original exception was: Traceback (most recent call last): File "/home/remi/Documents/programmation/python/test.py", line 17, in <module> alphabet=arbre.parse(le_fichier_xml()) TypeError: parse() missing 1 required positional argument: 'source' remi@remi-Vostro-3550:~$with an error
Error:TypeError: parse() missing 1 required positional argument: 'source'
not quite clear, as the python documentation readsQuote:parse(source, parser=None)
Loads an external XML section into this element tree. source is a file name or file object. parser is an optional parser instance. If not given, the standard XMLParser parser is used. Returns the section root element.
and I however passed a positional parameter.
So, I'm quite confused
Arbiel