Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x if/elif-Python3的问题_Python 3.x - Fatal编程技术网

Python 3.x if/elif-Python3的问题

Python 3.x if/elif-Python3的问题,python-3.x,Python 3.x,好,从这里来: 这是我的第二个问题很抱歉,没有问题。。。 我成功地阅读了4个字母的平台,现在我想要的是如果平台=mt81或mt67继续,如果不退出。 为此,我使用了: if platform == "mt81" or "mt67": continue elif platform != "mt81" or != "mt67": wait = input("Incompatible CPU! BYE!") break 如果我执行python文件,没有错误,

好,从这里来: 这是我的第二个问题很抱歉,没有问题。。。 我成功地阅读了4个字母的平台,现在我想要的是如果平台=mt81或mt67继续,如果不退出。 为此,我使用了:

if platform == "mt81" or "mt67":
       continue
elif platform != "mt81" or != "mt67":
       wait = input("Incompatible CPU! BYE!")
       break
如果我执行python文件,没有错误,但是当我单击读取平台的选项时,什么也不会发生,它会返回到菜单,但是如果我删除If/elif工具正在工作但没有平台检测

我试过:

if "mt81" in platform or "mt67" in platform:
       continue
elif "mt81" not in platform or "mt67" not in platform:
       wait = input("Incompatible CPU! BYE!")
       break
但同样的结果

你知道我能做什么吗? 再次感谢

编辑 完整代码:

import os
import subprocess

# By R0rt1z2
# All the credits goes to diplomatic for create his excellent MTK-SU!

#set null variables
supported = ['mt81', 'mt67']

def menu():
        """
        Fucntion to clean
        """
        os.system('clear')
        print("\t Big thanks to diplomatic")
        print("\t1 - Root the Device")
        print("\t2 - Spawn Root Shell")
        print("\t3 - Exit")

while True:
        #show menu
        menu()

        #user sets option
        option = input("Select an option >> ")

        if option=="1":
             print("Detecting device information....")
             print("--------------------------------------")
             subprocess.call("adb shell getprop ro.boot.veritymode > verity.txt",shell=True)
             with open('verity.txt') as myfile:
               verity = myfile.read()
             subprocess.call("adb shell getprop debug.mtklog.netlog.Running > mtk.txt",shell=True)
             with open('mtk.txt') as myfile:
               mtk = myfile.read()
             subprocess.call("adb shell getprop ro.product.model > device.txt",shell=True)
             with open('device.txt') as myfile:
               device = myfile.read()
             subprocess.call("adb shell getprop ro.hardware > platform.txt",shell=True)
             with open('platform.txt', 'r') as myfile:
               platform = myfile.read(4)
             subprocess.call("adb shell getprop ro.product.cpu.abi > arch.txt",shell=True)
             with open('arch.txt') as myfile:
               arch = myfile.read()
             subprocess.call("adb shell getprop ro.build.version.release > android.txt",shell=True)
             with open('android.txt') as myfile:
               android = myfile.read()
             print("Device: " + device)
             print("ARCH: " + arch)
             print("Platform: " + platform)
             print("Android: " + android)
             print("--------------------------------------")
             if platform == "mt81" or "mt67":
               continue
             elif platform != "mt81" or != "mt67":
               wait = input("Incompatible CPU! BYE!")
               break
             if "enforcing" in verity:
                 print("Sorry! Your device seems to have DM-Verity, this method will not work. Exiting...")
                 break
             elif " " in verity:
                 continue
             # ty t0x1cSH
             if "arm64-v8a" in arch:
                print("--------------------------------------")
                print("Detected arm64 arch.. Pushing arm64 mtk-su & files")
                subprocess.call("adb push arm64/mtk-su arm64/root.sh arm64/su arm64/supolicy arm64/libsupol.so /data/local/tmp",shell=True)
                print("--------------------------------------")
                print("Pushed files succsefully!")
                print("Rooting the device...")
                subprocess.call("adb install files/SuperSU.apk",shell=True)
                subprocess.call("adb shell chmod 755 /data/local/tmp/mtk-su",shell=True)
                subprocess.call("adb shell chmod 755 /data/local/tmp/root.sh",shell=True)
                subprocess.call('adb shell /data/local/tmp/mtk-su -c "/data/local/tmp/root.sh"',shell=True)
                wait = input("PRESS ENTER TO CONTINUE.")
                os.system('clear')
             # ty t0x1cSH
             elif "armeabi-v7a" in arch:
                print("Detected armv7 arch.. Pushing armv7 mtk-su & files")
                subprocess.call("adb push arm/mtk-su arm/root.sh arm/su arm/supolicy arm/libsupol.so /data/local/tmp",shell=True)
                print("--------------------------------------")
                print("Pushed files succsefully!")
                print("Rooting the device...")
                subprocess.call("adb install files/SuperSU.apk",shell=True)
                subprocess.call("adb shell chmod 755 /data/local/tmp/mtk-su",shell=True)
                subprocess.call("adb shell chmod 755 /data/local/tmp/root.sh",shell=True)
                subprocess.call('adb shell /data/local/tmp/mtk-su -c "/data/local/tmp/root.sh"',shell=True)



        elif option=="2":
               print("ROOT SHELL SPAWNER")
               subprocess.call("adb shell getprop ro.product.cpu.abi > arch.txt",shell=True)
               with open('arch.txt') as myfile:
                  arch = myfile.read()
               print("Spawning Root Shell... \n For exit type 'exit' two times or Control+C for terminate the script")
               # ty again t0x1cSH :)
               if "arm64-v8a" in arch:
                   subprocess.call("adb push arm64/mtk-su /data/local/tmp",shell=True)
                   subprocess.call("adb shell chmod 755 /data/local/tmp/mtk-su",shell=True)
                   subprocess.call("adb shell /data/local/tmp/mtk-su",shell=True)
                   wait = input("PRESS ENTER TO CONTINUE.")
                   os.system('clear')
               elif "armeabi-v7a" in arch:
               # ty again again XD
                   subprocess.call("adb push arm/mtk-su /data/local/tmp",shell=True)
                   subprocess.call("adb shell chmod 755 /data/local/tmp/mtk-su",shell=True)
                   subprocess.call("adb shell /data/local/tmp/mtk-su",shell=True)
                   wait = input("PRESS ENTER TO CONTINUE.")
                   os.system('clear')

        elif option=="3":
               break

        else:
               print("")
               input("Incorrect option...\nPress any key to continue..")

我猜您希望传递代码而不是继续,所以请尝试更改继续传递。continue在开始处启动下一个循环,并传递给下一个代码

if platform in ('mt81', 'mt67'):
// if platform in set(supported):
    pass
else:
    wait = input("Incompatible CPU! BYE!")
    break
注释的if语句用于根据需要使用受支持的已定义列表。

此平台值在文件中的外观如何

我认为平台是一个变量,你必须比较它的值。所以,将平台作为一个字符串,您可以检查平台是否以两个字符串开头:“mt81”和“mt67”。 您可以做的是:

if platform.startswith('mt81') or  platform.startswith('mt67'):
    continue;
else:
    print("Incompatible platform.\n")

您要做的是比较平台是否与“mt81”相同,因为其中可能有空格或特殊字符,所以可能并不总是完全匹配。所以最好使用字符串函数startswith

谢谢,但结果一样。我也在一个while循环中,IDK,如果这影响到了。我需要补充一点:否则它会给我语法错误。编辑:切换到平台中的if'mt81','mt67'会给我:``回溯最后一次调用:if'mt81','mt67'中的文件mtk-su_linux.py,第53行:TypeError:'in'需要字符串作为左操作数,而不是元组``请使用pass not continue重试。若要使用elif,必须使用else语句。但是无论哪种方式,最好改变你的第一个if来获得break语句。谢谢你的回复:Platform是.txt文件中的前4个字母。我已经尝试了你的建议,但仍然是一样的,返回菜单没有输出。