py2tex icon indicating copy to clipboard operation
py2tex copied to clipboard

Attribute Error on for-in loop

Open emablekos opened this issue 5 years ago • 1 comments

Thanks for this code.

I get an attribute error when doing a for-in loop.

def foo():
    a = ["a", "b"]
    b = "c"
    for val in a:
        b = val

causes:

<_ast.For object at 0x1042ebb90> <class '_ast.For'> <_ast.Name object at 0x1042ebdd0> <class '_ast.Name'>
Traceback (most recent call last):
  File "py2tex.py", line 235, in <module>
    main()
  File "py2tex.py", line 229, in main
    py2tex.visit(ast.parse(source))
  File "py2tex.py", line 33, in visit
    result = super().visit(node)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "py2tex.py", line 44, in visit_Module
    self.visit(stmt)
  File "py2tex.py", line 33, in visit
    result = super().visit(node)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "py2tex.py", line 71, in visit_FunctionDef
    self.body(node.body)
  File "py2tex.py", line 48, in body
    self.visit_all(body)
  File "py2tex.py", line 40, in visit_all
    self.visit(node)
  File "py2tex.py", line 33, in visit
    result = super().visit(node)
  File "/usr/local/Cellar/python/3.7.7/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "py2tex.py", line 145, in visit_For
    nargs = len(node.iter.args)
AttributeError: 'Name' object has no attribute 'args'

I am able to generate latex from other python code and render it to pdf.

On Python 3.7.7

emablekos avatar Jul 01 '20 13:07 emablekos

Does something like this produce the same error?

def foo():
    a = [1, 2, 3]
    for val in a:
        print(val)

If yes, I suspect that py2tex doesn't support anything that is not a simple "for in range(...)"

wil93 avatar Jul 15 '20 08:07 wil93