xml - Why can't <some-name> be used in a python list? -


for example, can't manually enter in list:

list = [<element1>, <element2>, <element3>...] 

which throws error:

>>> list = [<dom text node "u'\n\t'">]   file "<stdin>", line 1     list = [<dom text node "u'\n\t'">]         ^ syntaxerror: invalid syntax 

whereas can put element xml parse elements list, doesn't cause syntax error. have listed xml elements in list:

[<dom text node "u'\n\t'">,   <dom element: apple @ 0x18a4648>,   <dom text node "u'\n\t\n\t'">,   <dom element: google @ 0x18a4968>,   <dom text node "u'\n\t\n\t'">,   <dom element: lenovo @ 0x18a4b48>,   <dom text node "u'\n\t\n\t'">,   <dom element: samsung @ 0x18a4be8>,   <dom text node "u '\n'">] 

which works fine, when manually try feed list above elements, fails.

can explain why so?

whatever printed between angled brackets human-readable presentation of class, example:

>>> class test: ...  pass ...  >>> = test() >>> print(a) <__main__.test object @ 0x7f76070b6198> >>> repr(a) '<__main__.test object @ 0x7f76070b6198>' 

the <...> string of text, can control printed __str__() , __repr__() functions:

>>> class banana: ...   def __str__(self): ...     return 'i yellow!' ... ...   def __repr__(self): ...     return 'i yellow!' ...  >>> b = banana() >>> print(b) yellow! >>> repr(b) yellow! 

if want create list these variables, use variable names (in case, a & b): list = [a, b]

bonus hint:
list builtin name in python (refering list type (type([]) == list); don't want use variable or function name (but because python cool, allow anyway).


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -