# Best practices to avoid long lines when using eval()

**URL:** <https://community.seqera.io/t/best-practices-to-avoid-long-lines-when-using-eval/1535>\
**Category:** Ask for help\
**Tags:** vscode\
**Created:** [December 10, 2024, 5:50pm UTC](https://community.seqera.io/t/best-practices-to-avoid-long-lines-when-using-eval/1535 "2024-12-10T17:50:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JAlvarez](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/jalvarez/32/605_2.png) [@JAlvarez](https://community.seqera.io/u/JAlvarez)\
**Post date:** [December 10, 2024, 5:50pm UTC](https://community.seqera.io/t/best-practices-to-avoid-long-lines-when-using-eval/1535/1 "2024-12-10T17:50:01Z")

</div>

The new `eval()` is quite useful and handy, but I’m wondering what would be the recommended/best approach when using it with longer commands such as those used to collect versions of Python libraries? e.g. `"python -c 'import long.library.namespace; print(long.library.namespace. __version__ )'"`

---

<div class="post-metadata">

**Author:** ![bentsherman](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bentsherman/32/52_2.png) [@bentsherman](https://community.seqera.io/u/bentsherman)\
**Post date:** [December 10, 2024, 6:56pm UTC](https://community.seqera.io/t/best-practices-to-avoid-long-lines-when-using-eval/1535/2 "2024-12-10T18:56:42Z")

</div>

You could move the string into a helper function:

```groovy
def pythonVersionCmd() {
  "python -c 'import long.library.namespace; print(long.library.namespace. __version__ )'"
}

process PROC {
  output:
  eval( pythonVersionCmd() )

  // ...
}

```

Or you can use an `env()` output which is slightly more verbose but pretty close:

```groovy
process PROC {
  output:
  env('PYTHON_VERSION')

  script:
  """
  export PYTHON_VERSION=$(python -c 'import long.library.namespace; print(long.library.namespace. __version__ )')
  """
}

```

---

<div class="post-metadata">

**Author:** ![JAlvarez](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/jalvarez/32/605_2.png) [@JAlvarez](https://community.seqera.io/u/JAlvarez)\
**Post date:** [December 11, 2024, 1:24pm UTC](https://community.seqera.io/t/best-practices-to-avoid-long-lines-when-using-eval/1535/3 "2024-12-11T13:24:19Z")

</div>

Thank you @bentsherman. The latter seems more reasonable, particularly if you have many modules in need of this version (so you don’t end up multiplying the `pythonVersionCmd()` function, or having to go the more complex route of the utils subworkflow).

---

<div class="post-metadata">

**Author:** ![bentsherman](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/bentsherman/32/52_2.png) [@bentsherman](https://community.seqera.io/u/bentsherman)\
**Post date:** [December 11, 2024, 2:03pm UTC](https://community.seqera.io/t/best-practices-to-avoid-long-lines-when-using-eval/1535/4 "2024-12-11T14:03:06Z")

</div>

You can have a module that just defines helper functions like `pythonVersionCmd()` that are included by other modules. You don’t have to have a subworkflow. That is just an nf-core convention that I personally find to be too restrictive, especially for cases like this one.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex013/user_avatar/community.seqera.io/system/32/2402_2.png) [@system](https://community.seqera.io/u/system)\
**Post date:** [December 18, 2024, 2:04pm UTC](https://community.seqera.io/t/best-practices-to-avoid-long-lines-when-using-eval/1535/5 "2024-12-18T14:04:03Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
