Giter Club home page Giter Club logo

Comments (3)

cdfmlr avatar cdfmlr commented on June 9, 2024

@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?

from pyflowchart.

kaasima10 avatar kaasima10 commented on June 9, 2024

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.

from pyflowchart.

cdfmlr avatar cdfmlr commented on June 9, 2024

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:

@staticmethod
def from_code(code: str, field: str = "", inner=True, simplify=True, conds_align=False):
"""
Get a Flowchart instance from a str of Python code.
Args:
code: str, Python code to draw flowchart
field: str, path to field (function) you want to draw flowchart
inner: bool, True: parse the body of field; Field: parse the body as an object
simplify: bool, for If & Loop statements: simplify the one-line-body or not.
conds_align: bool, for consecutive If statements: conditionNode alignment support (Issue#14) or not
Returns:
A Flowchart instance parsed from given code.

Meanwhile, parse is an internal function that parses the abstract syntax trees of python codes, instead of a str of python source code:

def parse(ast_list: List[_ast.AST], **kwargs) -> ParseProcessGraph:
"""
parse an ast_list (from _ast.Module/FunctionDef/For/If/etc.body)
Args:
ast_list: a list of _ast.AST object
Keyword Args:
* simplify: for If & Loop: simplify the one line body cases
* conds_align: for If: allow the align-next option set for the condition nodes.
See https://github.com/cdfmlr/pyflowchart/issues/14
Returns:
ParseGraph
"""

Users shall never call this function from the out of the package.

from pyflowchart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.