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();
 
        }
    }
}
相关推荐
Q_Q51100828520 分钟前
python+uniapp基于微信小程序的学院设备报修系统
spring boot·python·微信小程序·django·flask·uni-app
蓝色空白的博客34 分钟前
自动化测试脚本-->集成测试部署思路整理(1)
python·集成测试
Blossom.1181 小时前
把AI“绣”进丝绸:生成式刺绣神经网络让古装自带摄像头
人工智能·pytorch·python·深度学习·神经网络·机器学习·fpga开发
星星也在雾里1 小时前
【管理多版本Python环境】Anaconda安装及使用
python·anaconda
用户3721574261351 小时前
使用 Python 将 CSV 文件转换为 PDF 的实践指南
python
大佬,救命!!!1 小时前
算法实现迭代2_堆排序
数据结构·python·算法·学习笔记·堆排序
总有刁民想爱朕ha2 小时前
Python自动化从入门到实战(24)如何高效的备份mysql数据库,数据备份datadir目录直接复制可行吗?一篇给小白的完全指南
数据库·python·自动化·mysql数据库备份
孤客网络科技工作室2 小时前
Python - 100天从新手到大师:第五十七天获取网络资源及解析HTML页面
开发语言·python·html
帅大大的架构之路3 小时前
高级篇:Python脚本(101-150)
开发语言·python
liweiweili1263 小时前
Django中处理多数据库场景
数据库·python·django