python main 函数-启动-传递参数 python 打包 exe C# 进程传参

Part1:Python main 传递参数

在Python编程中,我们经常需要从命令行或其他外部环境中获取参数。Python提供了一种简单而灵活的方式来处理这些参数,即通过main函数传参

1.python main 函数-启动-传递参数

test.py

python 复制代码
import sys

def main():
    # 获取命令行参数
    arguments = sys.argv[1:]
    
    # 处理参数
    for arg in arguments:
        print(arg)

if __name__ == "__main__":
    main()
  1. 如果直接传参给 脚本
python 复制代码
python test.py arg1 arg2 arg3

输出:

python 复制代码
['arg1', 'arg2', 'arg3']

输入 aa bb cc cc

Part2: Python 打包 exe

1、使用pyinstaller

pyinstaller是一个流行的Python打包工具,它可以将Python代码打包成独立的可执行文件。

使用pyinstaller打包Python代码非常简单,只需要在命令行中输入以下命令:

python 复制代码
pyinstaller test.py

2.使用py2exe

py2exe是一个Python打包工具,它可以将Python代码打包成Windows可执行文件。使用py2exe打包Python代码也很简单,只需要在命令行中输入以下命令:

python 复制代码
python test.py py2exe

Part3: C# 进程传参:

python 复制代码
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ConsoleAppone
{
    internal class Program
    {
        static void Main(string[] args)
        {
            ProcessStartInfo process = new ProcessStartInfo();
            process.FileName = @"D:/test.exe";
            string arg1 = "arg1";
            string arg2 = "arg2";
            process.Arguments = string.Format("{0} {1}", arg1, arg2);  //多个参数用空格隔开
            process.WindowStyle = ProcessWindowStyle.Normal;
            Process.Start(process);
            Console.Read();
 
        }
    }
}
相关推荐
雪域迷影2 分钟前
Python Django 7 小时课程
开发语言·python·django
量化吞吐机13 分钟前
最高最低都一样,价格就同样集中吗
人工智能·python
FITA阿泽要努力16 分钟前
如何调用 LLM 接口
python·api·agent
江湖中的阿龙27 分钟前
大模型应用怎么做评测?从样本集、自动评分到上线回归的完整实战
人工智能·python·回归·大模型评测
雾游43 分钟前
用上 uv 后,搭建 Python 项目终于顺手了:从安装到环境恢复,一篇讲清
python
范中勤44 分钟前
LangGraph Checkpointer 封装(下):with 的双层上下文与 MemorySaver 为什么不用 with
python·大模型·llm·agent·langgraph
鸿业远图科技1 小时前
丹东市_公交线
python
打工仔折腾 AI1 小时前
在线PDF工具隐私焦虑?把BentoPDF部署到极空间NAS本地处理
人工智能·后端·python·pdf·ai agent 实战
2603_965148111 小时前
商品价格监控 API 接口:从原理到实战的完整指南
java·前端·数据库·python·生活
数字化转型分享点滴2 小时前
机加工MES落地先连设备还是先上工单?一份车间实施参考
python·安全