简体   繁体   English

Python脚本无法在命令提示符下打印输出

[英]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 Shebange Line. 删除Shebange线。
  1. Remove the first line from your script. 从脚本中删除第一行。
  2. Execute the script using python test1.py COMMAND_LINE_ARGUMENTS 使用python test1.py COMMAND_LINE_ARGUMENTS执行脚本python test1.py COMMAND_LINE_ARGUMENTS
  • Modify Your Shebang line. 修改您的Shebang行。
  1. Change the first line of your script from !/usr/bin/python to #!python (This is assuming that python is in your systems PATH variable.)` 将脚本的第一行从!/usr/bin/python更改为#!python (这是假定python在系统PATH变量中。)

  2. 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.

相关问题 如何向我展示 python argparse 脚本的 output,打印结果退出命令提示符 - How to show me output of python argparse script, result of print exits command prompt 使用鼠标右键&gt;&gt;在此处命令提示符后执行脚本时,Python无法正常工作 - Python doesn't work properly when I execute a script after using Right Click >> Command Prompt Here python脚本打开Windows命令提示符并打印一些字符串 - python script to open windows command prompt and print some strings 为什么命令 Python 在命令提示符中不执行任何操作? - Why doesn't the command Python not do anything in Command Prompt? 命令提示符中的 Python 不起作用,但在 python 空闲时它可以 - Python in command prompt doesn't work, but in python idle it does 命令提示符返回空白,但python控制台没有 - Command prompt returning blank, but python console doesn't (Windows 11) 命令提示符无法识别 Python (3.10.6) 已安装? - (Windows 11) Command Prompt doesn't recognize that Python (3.10.6) is installed? 命令提示符中的“python”不起作用(Windows 10) - "python" in command prompt doesn't work (windows 10) 从命令提示符运行 Python 脚本无法正常工作 - Running a Python script from the command prompt isn't working correctly Python print() 命令不会在一行上打印所有内容 - Python print() command doesn't print everything on one line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM