Is it possible to utilize a CLI (module/app/library) for use in my own Python script?

huangapple go评论71阅读模式
英文:

Is it possible to utilize a CLI (module/app/library) for use in my own Python script?

问题

我是相对新手的编程者,但我喜欢Python,并正试图理解某些东西,因为我遇到了一个特定的问题需要解决!

为了提供背景示例 -

我目前正在尝试将一个pyfiglet标题(居中)样式化为彩色渐变。似乎除了以下方式外没有其他方法:

https://github.com/wasi-master/gradient_figlet

然而,这是一个CLI模块/工具,我不知道如何将其实现到我的脚本中。没有文档,我习惯于提供以下示例:

import gradient-figlet

gradient_figlet("TEST HELLO")

要获得打印的渐变文本(figlet)结果,就像在命令行中使用gradient-figlet时所实现的那样,您可以使用:

python -m gradient_figlet YOUR_TEXT

总的来说,这是否可能?

任何帮助将不胜感激。

*另外 - 如果有人有任何关于如何在控制台中居中物体的提示,我会非常感激 Is it possible to utilize a CLI (module/app/library) for use in my own Python script? *

英文:

I am fairly new to coding but love Python and am trying to understand something as I've run into a specific issue I need solved!

To give an example for context -

I am currently trying to stylize a pyfiglet title (centered) as a colored gradient. There seems to be no way to do this ASIDE FROM:

https://github.com/wasi-master/gradient_figlet

However, this is a CLI module/tool and I have no idea how to implement it into my script. There is no documentation and I am used to being provided with examples such as:

import gradient-figlet

gradient_figlet("TEST HELLO")

To give a printed gradient text (figlet) result as gradient-figlet accomplishes when used in command line using:

python -m gradient_figlet YOUR_TEXT

Is this possible in general?

Any help would be appreciated.

On a side note - I'd really like to be able to center things in console if anyone has any tips Is it possible to utilize a CLI (module/app/library) for use in my own Python script?

答案1

得分: 0

它似乎没有非CLI实现。但是,您可以使用子进程运行CLI并捕获输出并使用它。

import subprocess

the_result = subprocess.run(['python', '-m', 'gradient_figlet', 'YOUR_TEXT'], stdout=subprocess.PIPE)

如果这不是您要找的请告诉我
英文:

It doesn't look like gradient_figlet has a non CLI implementation. However you could use subprocess to run the CLI and capture the output and use it.

import subprocess

the_result = subprocess.run(['python', '-m', 'gradient_figlet', 'YOUR_TEXT'], stdout=subprocess.PIPE)

Let me know if this isn't what you are looking for!

答案2

得分: 0

我与该存储库的创建者进行了交谈,他很友好地更新了存储库,以支持在脚本中使用!

https://github.com/wasi-master/gradient_figlet

希望这能帮助到某人!

英文:

I spoke with the creator of the repo and he kindly updated the repo to support usage within a script!

https://github.com/wasi-master/gradient_figlet

Hope this helps someone!

huangapple
  • 本文由 发表于 2023年1月9日 06:20:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051664.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定