[英]Python script doesn't print output in command prompt
I need some advice with a Python script. 我需要有关Python脚本的一些建议。 I'm still new and learned it by myself. 我还很新,并且是我自己学的。 I found the script on Google. 我在Google上找到了该脚本。 After I retype it, it doesn't print the result in the console. 重新输入后,它不会在控制台中显示结果。 How can the result of the script be shown in the console? 脚本结果如何在控制台中显示? Details as below: 详细信息如下:
C:\\Python27>test1.py af8978b1797b72acfff9595a5a2a373ec3d9106d C:\\ Python27> test1.py af8978b1797b72acfff9595a5a2a373ec3d9106d
C:\\Python27> C:\\ Python27>
After I press enter, nothing happens. 在按Enter键之后,什么都没有发生。 Should the result be shown or not? 是否显示结果?
Here's the code that I retyped: 这是我重新输入的代码:
#!/usr/bin/python
#coding: ascii
import requests
import sys
import re
url = 'http://hashtoolkit.com/reverse-hash?hash='
try:
hash = sys.argv[1]
except:
print ("usage: python "+sys.argv[0]+" hash")
sys.exit()
http = request.get(url+hash)
content = http.content
cracked = re.findall("<span title=\*decrypted (md5|sha1|sha384|sha512) hash\*>(.*)</span>", content) # expression regular
print ("\n\tAlgoritmo: "+cracked[0][0])
print ("\tPassword Cracked: "+cracked[0][1])
The first line in your script is called a Shebang line
. 脚本中的第一行称为Shebang line
。 A Shebang line tells the script to run the Python interpreter from that location. Shebang行告诉脚本从该位置运行Python解释器。
The shebang line you provided is a Linux system path, but it looks from the path you are executing Python from, that you are running on Windows. 您提供的shebang行是Linux系统路径,但从您正在Windows上执行Python的路径中可以看出。
You can do one of two things here to fix that: 您可以在此处执行以下两项操作之一来解决此问题:
- Remove the first line from your script. 从脚本中删除第一行。
- Execute the script using
python test1.py COMMAND_LINE_ARGUMENTS
使用python test1.py COMMAND_LINE_ARGUMENTS
执行脚本python test1.py COMMAND_LINE_ARGUMENTS
Change the first line of your script from
!/usr/bin/python
to#!python
(This is assuming that python is in your systemsPATH
variable.)` 将脚本的第一行从!/usr/bin/python
更改为#!python
(这是假定python在系统PATH
变量中。)Execute the script using
test1.py COMMAND_LINE_ARGUMENTS
使用test1.py COMMAND_LINE_ARGUMENTS
执行脚本
Also, you are trying to import the requests
module that is not installed in the standard library. 另外,您正在尝试导入标准库中未安装的requests
模块。
If you haven't installed this yet, you can do so by going to your Python install directory and go to the scripts
folder. 如果尚未安装,则可以转到Python安装目录,然后转到scripts
文件夹。
Hold shift
and right click and go Open command window here
按住shift
并单击鼠标右键,然后Open command window here
Type pip install requests
and hit enter. 输入pip install requests
然后按Enter。
After that you should be good to go, execute the script by navigating to it and type test.py COMMAND_LINE_ARGUMENT
此后,您应该一切顺利,通过导航到脚本并键入test.py COMMAND_LINE_ARGUMENT
来执行脚本。
If a Python script doesn't have the shebang line
: 如果Python脚本没有shebang line
:
python test.py COMMAND_LINE_ARGUMENT
you need to run your script using python. 您需要使用python运行脚本。 try: 尝试:
C:\Python27>python test1.py af8978b1797b72acfff9595a5a2a373ec3d9106d
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.