无法弄清楚Infile和输出的Python语法[重复](Cant figure out Python Syntax for Infile and Output [duplicate])

编程入门 行业动态 更新时间:2024-10-26 20:27:07
无法弄清楚Infile和输出的Python语法[重复](Cant figure out Python Syntax for Infile and Output [duplicate])

这个问题在这里已有答案:

使用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 answers

I 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 syntax

Thanks :)

最满意答案

欢迎来到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 :)

更多推荐

本文发布于:2023-08-07 14:04:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:弄清楚   语法   Python   Infile   duplicate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!