Open cdfmlr opened 5 months ago
@kaasima10 I have tested pyflowchart 0.3.1 with python 3.11 and astunparse 1.6.3 as you described, on some basic cases I tried, it works fine. Would you mind to post your inputted python source code and command executed that helps reproduce this problem?
this is my python code :-
import pyflowchart as pfc import inspect
def example_function(x): if x > 0: return 'Positive' elif x < 0: return 'Negative' else: return 'Zero'
code = inspect.getsource(example_function) fc = pfc.parse(code) flowchart = fc.flowchart() print(flowchart)
@cdfmlr I encountered an AttributeError when attempting to convert a simple Python function to a flowchart using the pyflowchart library. The function is straightforward, but the error occurs during the conversion process.
Thanks. Have figured it out.
You should use:
from pyflowchart import Flowchart
...
fc = Flowchart.from_code(code)
...
instead of:
import pyflowchart as pfc
...
fc = pfc.parse(code)
...
As described in our document section Python to Flowchart, Flowchart.from_code
is the right method you are expected to converts python source code from a str
to the flowchart:
Meanwhile, parse
is an internal function that parses the abstract syntax trees of python codes, instead of a str
of python source code:
Users shall never call this function from the out of the package.
As pyflowchart 0.3.1 used with python 3.11 and astunparse 1.6.3 throws an exception:
How do I resolve this issue?
Originally posted by @kaasima10 in https://github.com/cdfmlr/pyflowchart/issues/28#issuecomment-2101265384