linux中将bat文件打成包,将.BAT文件转换为Linux支持 - python

问题1:我假设这将转换为Shell脚本,但是我唯一的问题是我是否需要更改代码中的任何内容?这只是简单地运行python脚本文件。

cd ..

cd Bin\Randomizer

cls

python Randomizer.py

问题2:当我拥有python脚本时,我需要在那台计算机上安装python才能使python脚本正常工作,就像我在编写代码时知道的那样。但是,如果我通过电子邮件将其发送给他人并且有人启动它,他们需要python吗?如果可以,有什么办法可以避免这种情况?就像当您进入网站并玩游戏时,并不能确保您安装python。

例如这是一个脚本

import time

import random

"""Randomizer Script"""

print("Randomizer Loaded!")

print()

time.sleep(3)

done = 0

while done == 0:

name = input("What is your name? ")

print("Welcome " + name + " To Randomizer!")

time.sleep(1)

print("This program will randomize things for a chosen choice!")

print()

print("Before we start this program can only allow 6 names at a time")

time.sleep(3)

num = input("How Many Things Are You Randomizing? 2 - 6 ")

def randomizer2():

name1 = input("What Is the First Persons Name ")

name2 = input("What Is the Second Persons Name ")

chosennum = random.randint(1, 2)

if chosennum == 1:

if name1.isalpha():

chosenname = name1

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 2:

if name2.isalpha():

chosenname = name2

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

def randomizer3():

name1 = input("What Is the First Persons Name ")

name2 = input("What Is the Second Persons Name ")

name3 = input("What Is the Third Persons Name ")

chosennum = random.randint(1, 3)

if chosennum == 1:

if name1.isalpha():

chosenname = name1

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 2:

if name2.isalpha():

chosenname = name2

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 3:

if name3.isalpha():

chosenname = name3

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

def randomizer4():

name1 = input("What Is the First Persons Name ")

name2 = input("What Is the Second Persons Name ")

name3 = input("What Is the Third Persons Name ")

name4 = input("What Is the Fourth Persons Name ")

chosennum = random.randint(1, 4)

if chosennum == 1:

if name1.isalpha():

chosenname = name1

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif num == 2:

if name2.isalpha():

chosenname = name2

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif num == 3:

if name3.isalpha():

chosenname = name3

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 4:

if name4.isalpha():

chosenname = name4

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

def randomizer5():

name1 = input("What Is the First Persons Name ")

name2 = input("What Is the Second Persons Name ")

name3 = input("What Is the Third Persons Name ")

name4 = input("What Is the Fourth Persons Name ")

name5 = input("What Is the Fifth Persons Name ")

chosennum = random.randint(1, 5)

if chosennum == 1:

if name1.isalpha():

chosenname = name1

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 2:

if name2.isalpha():

chosenname = name2

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 3:

if name3.isalpha():

chosenname = name3

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 4:

if name4.isalpha():

chosenname = name4

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 5:

if name5.isalpha():

chosenname = name5

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

def randomizer6():

name1 = input("What Is the First Persons Name ")

name2 = input("What Is the Second Persons Name ")

name3 = input("What Is the Third Persons Name ")

name4 = input("What Is the Fourth Persons Name ")

name5 = input("What Is the Fifth Persons Name ")

name6 = input("What Is the Sixth Persons Name ")

chosennum = random.randint(1, 6)

if chosennum == 1:

if name1.isalpha():

chosenname = name1

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif num == 2:

if name2.isalpha():

chosenname = name2

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif num == 3:

if name3.isalpha():

chosenname = name3

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif chosennum == 4:

if name4.isalpha():

chosenname = name4

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif num == 5:

if name5.isalpha():

chosenname = name5

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

elif num == 6:

if name6.isalpha():

chosenname = name6

print("The Name "+chosenname+" Has Been Chosen!")

else:

print("Do Not Input Numbers Input Letters!")

if num.isdigit() and num == "2":

randomizer2()

elif num.isdigit() and num == "3":

randomizer3()

elif num.isdigit() and num == "4":

randomizer4()

elif num.isdigit() and num == "5":

randomizer5()

elif num.isdigit() and num == "6":

randomizer6()

else:

print("Please Insert Numbers!")

stay = input("Do You Want To Randomize Again? Y/N ")

if stay == "Y":

done = 0

elif stay == "N":

done = 1

website = "Nothing :("

print("Thank You For Using Are Programs for more visit " + website)

time.sleep(7)

参考方案

坦率地说,我不明白您的第一个问题。您显示的代码绝对不会转换任何内容。而且python不是shell脚本。你想让我做什么 ?如果要执行python脚本,请在终端中使用python script.py。

关于第二个问题:

如果您将某人的python代码邮寄给某人,则他们需要安装python解释器才能运行它。解释器必须是正确的python版本,您不能在3.x上运行2.x,反之亦然。他们还需要拥有您正在使用的库。

话虽这么说,但是有打包python代码的方法。在这里查看:How to make a Python script standalone executable to run without ANY dependency?

如果要通过单击执行python脚本,则以下3个步骤应该可以解决问题:

将此行添加到脚本顶部:#!/usr/bin/env python。它应该是代码的第一行。

将文件标记为可执行文件,在终端chmod +x script.py中运行以下命令

编辑您的文件浏览器首选项。应该有一个设置在“运行”和“打开”可执行脚本文件之间切换。

之后,只需双击脚本即可。

编辑:

您代码的第一行应该是

#!/usr/bin/env python

要么

#!/usr/bin/env python3

取决于您代码的python版本。

Python uuid4,如何限制唯一字符的长度 - python

在Python中,我正在使用uuid4()方法创建唯一的字符集。但是我找不到将其限制为10或8个字符的方法。有什么办法吗?uuid4()ffc69c1b-9d87-4c19-8dac-c09ca857e3fc谢谢。 参考方案 尝试:x = uuid4() str(x)[:8] 输出:"ffc69c1b" Is there a way to…Python-crontab模块 - python

我正在尝试在Linux OS(CentOS 7)上使用Python-crontab模块我的配置文件如下:{ "ossConfigurationData": { "work1": [ { "cronInterval": "0 0 0 1 1 ?", "attribute&…Python:检查是否存在维基百科文章 - python

我试图弄清楚如何检查Wikipedia文章是否存在。例如,https://en.wikipedia.org/wiki/Food 存在,但是https://en.wikipedia.org/wiki/Fod 不会,页面只是说:“维基百科没有此名称的文章。”谢谢! 参考方案 >>> import urllib >>> prin…Python Pandas导出数据 - python

我正在使用python pandas处理一些数据。我已使用以下代码将数据导出到excel文件。writer = pd.ExcelWriter('Data.xlsx'); wrong_data.to_excel(writer,"Names which are wrong", index = False); writer.…Python:在不更改段落顺序的情况下在文件的每个段落中反向单词? - python

我想通过反转text_in.txt文件中的单词来生成text_out.txt文件,如下所示:text_in.txt具有两段,如下所示:Hello world, I am Here. I am eighteen years old. text_out.txt应该是这样的:Here. am I world, Hello old. years eighteen a…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值