### Convert Python Code to Flowchart using CLI (Example) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md Provides an example of running PyFlowchart from the command line to convert a Python file ('simple.py') into flowchart DSL code. The output can then be rendered into a visual diagram. ```shell $ python -m pyflowchart simple.py # output flowchart code. ``` -------------------------------- ### Install PyFlowchart using pip Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md Installs the PyFlowchart package using the pip package installer. This is the standard way to add PyFlowchart to your Python environment. ```shell $ pip install pyflowchart ``` -------------------------------- ### Generate Flowchart for a Simple Python Function Source: https://github.com/cdfmlr/pyflowchart/blob/master/docs/examples.md This example shows how PyFlowchart can represent a simple Python function `foo` containing an if-else statement and a for loop. The generated flowchart visualizes the conditional branching and the iterative structure of the code. ```python def foo(a, b): if a: print("a") else: for i in range(3): print("b") return a + b ``` -------------------------------- ### Generate Simplified Flowchart with PyFlowchart Source: https://github.com/cdfmlr/pyflowchart/blob/master/docs/examples.md This example demonstrates the simplified output of PyFlowchart when `simplify=True`. It reduces complex structures like if statements and loops into more concise operation nodes, making the flowchart easier to read for straightforward logic. ```python # example_simplify.py a = 1 if a == 1: print(a) while a < 4: a = a + 1 ``` -------------------------------- ### Generate Basic Flowchart with PyFlowchart Source: https://github.com/cdfmlr/pyflowchart/blob/master/docs/examples.md This snippet demonstrates how to create a flowchart using PyFlowchart by defining and connecting various node types such as StartNode, OperationNode, ConditionNode, InputOutputNode, SubroutineNode, and EndNode. The `connect` and `connect_yes`/`connect_no` methods are used to establish the flow, and the final flowchart is printed using `fc.flowchart()`. ```python from pyflowchart import * st = StartNode('a_pyflow_test') op = OperationNode('do something') cond = ConditionNode('Yes or No?') io = InputOutputNode(InputOutputNode.OUTPUT, 'something...') sub = SubroutineNode('A Subroutine') e = EndNode('a_pyflow_test') # define the direction the connection will leave the node from sub.set_connect_direction("right") st.connect(op) op.connect(cond) cond.connect_yes(io) cond.connect_no(sub) sub.connect(op) io.connect(e) fc = Flowchart(st) print(fc.flowchart()) ``` -------------------------------- ### Customizing Node Connections in PyFlowchart Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md Provides an example of customizing node connections in PyFlowchart, specifically for a `ConditionNode`. It shows how to set alignment and explicitly connect nodes with direction. ```python cond = ConditionNode("a cond node", align_next=False) cond.connect_yes(op, "right") ``` -------------------------------- ### Generate Flowchart for Python Class and Function Definitions Source: https://github.com/cdfmlr/pyflowchart/blob/master/docs/examples.md This snippet illustrates PyFlowchart's ability to parse and generate a flowchart for Python code that includes nested function definitions within a class method. It focuses on visualizing the control flow of the inner function `g`. ```python # example.py print("start") def foo(): foo = "foo" class Bar(): def buzz(self, f): def g(self): print("g") f(self) return g(self) Bar().buzz(foo) print("end") ``` -------------------------------- ### Generate Flowchart from Python Code (CLI) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md This command-line interface usage shows how to generate a flowchart from a Python script using the pyflowchart module. It allows specifying the Python file and optionally a field to parse. Dependencies: pyflowchart installed as a package. ```Shell python -m pyflowchart example.py -f Bar.buzz.g ``` -------------------------------- ### Align Consecutive If Statements (Python) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md The `conds-align` parameter controls the alignment of consecutive If statements in a flowchart. When set to True, these statements are aligned. This example demonstrates the basic Python syntax for consecutive If statements. ```python # example-conds-align.py if cond1: op1 if cond2: op2 if cond3: op3 op_end ``` -------------------------------- ### Construct Flowchart using PyFlowchart API in Python Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md Demonstrates how to build a flowchart programmatically using PyFlowchart's Python API. It shows connecting various node types like StartNode, OperationNode, ConditionNode, etc. ```python from pyflowchart import * st = StartNode('a_pyflow_test') op = OperationNode('do something') cond = ConditionNode('Yes or No?') io = InputOutputNode(InputOutputNode.OUTPUT, 'something...') sub = SubroutineNode('A Subroutine') e = EndNode('a_pyflow_test') st.connect(op) op.connect(cond) cond.connect_yes(io) cond.connect_no(sub) sub.connect(op, "right") # sub->op line starts from the right of sub io.connect(e) fc = Flowchart(st) print(fc.flowchart()) ``` -------------------------------- ### PyFlowchart CLI Arguments for Code Conversion Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md Details the command-line interface arguments for PyFlowchart's `from_code` functionality, including options for specifying a field, parsing inner code, simplifying bodies, and aligning conditions. ```shell python -m pyflowchart [-f FIELD] [-i] [--no-simplify] [--conds-align] code_file ``` -------------------------------- ### Basic Python Code to Flowchart Conversion Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md Demonstrates how to convert a Python script into a flowchart using the PyFlowchart library. It reads Python code from a file and prints the generated flowchart representation. This is the fundamental way to use the library programmatically. ```python from pyflowchart import Flowchart with open('simple.py') as f: code = f.read() nc = Flowchart.from_code(code) print(fc.flowchart()) ``` -------------------------------- ### PyFlowchart CLI: Convert Python File to Flowchart Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md Shows the command-line interface (CLI) command to generate a flowchart directly from a Python file. This is a convenient way to quickly visualize Python scripts without writing additional Python code. ```sh python -m pyflowchart simple.py ``` -------------------------------- ### Generate Flowchart from Python File using CLI Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md Converts a Python file into a flowchart.js DSL text representation directly from the command line. This is a quick way to visualize script logic. ```shell $ python -m pyflowchart example.py ``` -------------------------------- ### Generate HTML Flowchart from Python file Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md This command generates a flowchart.js DSL from a Python source file and saves it as an HTML file. The HTML file can be opened in a browser to view the interactive flowchart. ```sh $ python -m pyflowchart example.py -o example.html $ # open example.html ``` -------------------------------- ### Generate Flowchart from Python Code (Python) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md This snippet demonstrates how to use the pyflowchart library in Python to generate a flowchart from a Python code string. It reads code from a file and then prints the generated flowchart. Dependencies: pyflowchart library. ```Python from pyflowchart import Flowchart with open('example.py') as f: code = f.read() nc = Flowchart.from_code(code, field='Bar.buzz.g', inner=False) print(fc.flowchart()) ``` -------------------------------- ### Generate Flowchart for a Specific Function using CLI Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md Generates a flowchart for a specific function or method within a Python file using the command line. This allows for focused visualization of parts of your code. ```shell $ python -m pyflowchart example.py -f function_name # or $ python -m pyflowchart example.py -f ClassName.method_name ``` -------------------------------- ### Generate HTML Output from Flowchart Object Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md This Python code shows how to generate an interactive HTML page containing the flowchart from a PyFlowchart object. The `output_html` function takes the output filename, flowchart title, and the flowchart DSL as arguments. ```python output_html('output.html', 'a_pyflow_test', fc.flowchart()) ``` -------------------------------- ### Advanced Flowchart Generation with `Flowchart.from_code` Parameters Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md Explains the advanced parameters available for the `Flowchart.from_code` method, including `field`, `inner`, `simplify`, and `conds_align`. These parameters allow for fine-grained control over which part of the code is converted and how it is represented. ```python Flowchart.from_code(code, field="", inner=True, simplify=True, conds_align=False) ``` -------------------------------- ### Generate Flowchart Code from Python String Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md Converts Python source code, provided as a string, into a flowchart.js DSL representation using the `Flowchart.from_code` method. This is useful for dynamic code analysis. ```python >>> from pyflowchart import Flowchart >>> with open('simple.py') as f: ... code = f.read() ... >>> fc = Flowchart.from_code(code) >>> print(fc.flowchart()) # output flowchart code. ``` -------------------------------- ### Output Flowchart to HTML (Python) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md This Python function allows direct output of the generated flowchart DSL to an HTML file. It takes the output filename, a field name, and the flowchart string as input. The function is part of the pyflowchart library. ```python >>> import pyflowchart >>> help(pyflowchart.output_html) ``` -------------------------------- ### Specify a Field for Flowchart Generation (Python API) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md Illustrates how to use the `field` parameter in the `Flowchart.from_code` method to generate a flowchart for a specific function or method within a Python script. This is useful for analyzing parts of larger codebases. ```python from pyflowchart import Flowchart with open('example.py') as f: code = f.read() nc = Flowchart.from_code(code, field='Bar.buzz.g', inner=False) print(fc.flowchart()) ``` -------------------------------- ### Set Parameters for Nodes in PyFlowchart Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md Shows how to set custom parameters for nodes using the `Node.set_param(key, value)` method in PyFlowchart. This allows for more detailed flowchart specifications compatible with flowchart.js. ```python cond = ConditionNode("a cond node") cond.no_align_next() # or do this at __init__: cond = ConditionNode("a cond node", align_next=False) cond.connect_yes(op, "right") ``` -------------------------------- ### Simplify Conditional and Loop Statements (Python API) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md Shows how the `simplify` parameter in `Flowchart.from_code` affects the representation of If and Loop statements. When `simplify=True`, single-line bodies are condensed into a single node for a cleaner flowchart. ```python flowchart = Flowchart.from_code(example_simplify_py, field="", inner=True, simplify=True) ``` ```python flowchart = Flowchart.from_code(example_simplify_py, field="", inner=True, simplify=False) ``` -------------------------------- ### Generate SVG/HTML Directly (TODO - CLI) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md This is a planned feature for the pyflowchart CLI to directly output flowcharts in SVG or HTML format. It would require external dependencies like Node.js and flowchart.js. This would eliminate the need for manual conversion steps. ```Shell $ pyflowchart example.py -o flowchart.svg ``` -------------------------------- ### Set Node Parameters in PyFlowchart Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md This Python code demonstrates how to set custom parameters for nodes in PyFlowchart using the `set_param` method. This allows for more detailed node specifications compatible with flowchart.js. ```python element(param1=value1,param2=value2)=>start: Start ``` -------------------------------- ### Simplify Conditional and Loop Statements (Python) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md This Python code demonstrates the 'simplify' parameter. With `simplify=True` (default), it merges single-line conditional/loop bodies into the condition node. With `simplify=False`, it displays the full control flow, showing separate nodes for conditions and their bodies. ```Python flowchart = Flowchart.from_code(example_simplify_py, field="", inner=True) print(flowchart.flowchart()) ``` ```Python flowchart = Flowchart.from_code(example_simplify_py, field="", inner=True, simplify=False) print(flowchart.flowchart()) ``` -------------------------------- ### Simplify Conditional and Loop Statements (CLI) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md This command shows how to disable simplification for conditional and loop statements using the '--no-simplify' flag in the pyflowchart CLI. This results in a more detailed flowchart displaying all control flow steps explicitly. ```Shell python -m pyflowchart example_simplify.py ``` ```Shell python -m pyflowchart --no-simplify example_simplify.py ``` -------------------------------- ### Control Nested Parsing with `inner` Parameter Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md Explains the `inner` parameter in `Flowchart.from_code`. When `inner=True`, the parser processes the body of a field, creating a nested flowchart. When `inner=False`, the field itself is treated as a single node. ```python flowchart = Flowchart.from_code(code, field='some_field', inner=True) ``` ```python flowchart = Flowchart.from_code(code, field='some_field', inner=False) ``` -------------------------------- ### Align Consecutive Conditional Statements (CLI) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md Explains the CLI option `--conds-align` which, when specified, aligns consecutive If statements in the generated flowchart. This improves the visual structure when dealing with multiple sequential conditional checks. ```sh python -m pyflowchart --conds-align your_script.py ``` -------------------------------- ### Control Parser Behavior with 'inner' (CLI) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md This command demonstrates the use of the '-i' flag in the pyflowchart CLI to control the 'inner' parameter. '-i' is equivalent to setting `inner=True`, causing the parser to go inside specified fields. Without '-i', `inner` defaults to `False`. ```Shell python -m pyflowchart --no-simplify example_simplify.py ``` -------------------------------- ### Control Parser Behavior with 'inner' (Python) Source: https://github.com/cdfmlr/pyflowchart/blob/master/README_zh-CN.md This Python snippet illustrates the effect of the 'inner' parameter in `Flowchart.from_code`. When `inner=True`, the parser delves into the field's body; when `inner=False`, it treats the entire field as a single node. This affects how nested structures are represented in the flowchart. ```Python flowchart = Flowchart.from_code(example_simplify_py, field="", inner=True) print(flowchart.flowchart()) ``` -------------------------------- ### Disable Align-Next for Condition Nodes Source: https://github.com/cdfmlr/pyflowchart/blob/master/README.md This Python code snippet shows how to use the `no_align_next()` method on a ConditionNode to prevent automatic alignment of subsequent nodes, providing more control over flowchart layout. ```python cond = ConditionNode("a cond node") cond.no_align_next() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.