这个问题在这里已有答案:
使用Python 3打印语法错误[重复] 9个答案我有一个python脚本但我不知道如何使用它。 脚本看起来像这样
def usage(): print "usage : ./ssl-patch <apk file>" def unzip_apk(infile, output): zfile = zipfile.ZipFile(infile, 'r') zfile.extractall(output) zfile.close() def zip_to_apk(indir, output): outapk = zipfile.ZipFile(output, 'w') for (path, dirs, files) in os.walk(indir): zipath = path[len("./" + output):] for filename in files: outapk.write(os.path.join(path, filename), os.path.join(zipath, filename), zipfile.ZIP_DEFLATED) outapk.close() def escape_dollar(string): return(re.sub('\$','\\$',string))我把所有的文件放在一个文件夹然后用cd定位到它然后写了nameOfScript.py fileName.apk我也尝试了很多其他的方法来编写它但是无法弄明白。
但我得到了错误
print "usage : ./ssl-path <apk file>" ^ SyntaxError: invalid syntax谢谢 :)
This question already has an answer here:
Syntax error on print with Python 3 [duplicate] 3 answersI have a python script but I am not sure how I can use it. The script looks like this
def usage(): print "usage : ./ssl-patch <apk file>" def unzip_apk(infile, output): zfile = zipfile.ZipFile(infile, 'r') zfile.extractall(output) zfile.close() def zip_to_apk(indir, output): outapk = zipfile.ZipFile(output, 'w') for (path, dirs, files) in os.walk(indir): zipath = path[len("./" + output):] for filename in files: outapk.write(os.path.join(path, filename), os.path.join(zipath, filename), zipfile.ZIP_DEFLATED) outapk.close() def escape_dollar(string): return(re.sub('\$','\\$',string))I put all the files in one folder then located to it with cd and then wrote nameOfScript.py fileName.apk I have also tried many other ways to write it but cant figure it out.
but I get the error
print "usage : ./ssl-path <apk file>" ^ SyntaxError: invalid syntaxThanks :)
最满意答案
欢迎来到SO。
该脚本缺少一个主要部分,它只包含函数定义(从def开始)。
可以使用python [name_of_script] [command-line-parameters]调用包含主要部分的脚本(使用if __name__ == '__main__':或只是在函数定义之外使用语句)。
希望有所帮助:)
Welcome to SO.
The script lacks a main section, it only consists of function definitions (starting with def).
A script that includes a main part (either using if __name__ == '__main__': or just having statements outside of function definitions) can be invoked with python [name_of_script] [command-line-parameters].
Hope that helps :)
更多推荐
发布评论