在导入类的时候,我的代码有什么问题?

2024-05-20 13:43:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在我的设置模块中调用我的方法hello,但是它应该可以很好地与from shodan.shodan import myclass一起工作,但是它似乎不适合文件结构,并且导入文件和调用。这是我正在做的练习的一个原型,但它似乎不适用于类和打印hello方法

.
    ├── core
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── settings.py
    │   └── settings.pyc
    ├── google
    │   ├── google.py
    │   ├── google.pyc
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   └── modules
    │       ├── images.py
    │       ├── __init__.py
    │       ├── __init__.pyc
    │       ├── utils.py
    │       └── utils.pyc
    ├── loop.sh
    ├── main.py
    ├── names
    ├── shodan
    │   ├── __init__.py
    │   ├── __init__.pyc
    │   ├── shodan.py
    │   └── shodan.pyc
    └── unix.sh

你知道吗设置.py你知道吗

from optparse import OptionParser
from sys import platform as _platform
from google.google import * 
from shodan.shodan import *

def settings(argv=None):
    if _platform == "linux" or _platform == "linux2":
    #Linux
        CrossPlatformCommandLineParser()
    elif _platform == "darwin":
    # MAC OS X
        CrossPlatformCommandLineParser()
    elif _platform == "win32":
    # Windows
        CrossPlatformCommandLineParser()
    elif _platform == "win64":
    # Windows 64-bit
        CrossPlatformCommandLineParser()

def CrossPlatformCommandLineParser(argv=None):
    if _platform == "linux" or _platform == "linux2":
    #Linux
        #print 'Linux ' + 'new cyber weapon'
        #google()
        shodan = Shodan()
        shodan.hello()
    elif _platform == "darwin":
    # MAC OS X
        print 2 
    elif _platform == "win32":
    # Windows
        print 3
    elif _platform == "win64":
    # Windows 64-bit
        print 4

你知道吗肖丹.py你知道吗

#!/usr/bin/python
class Shodan:
    """docstring for ClassName"""
    def __init__(self, key):
        self.key = "aaa"

    def hello():
        print '[+] shodan...' + self.key

你知道吗主.py你知道吗

#!/usr/bin/python
import sys
import core.settings

if __name__ == '__main__':
    try:
        core.settings.settings()
    except KeyboardInterrupt:
        print "interrupted by user.."
    except:
        sys.exit()

Tags: frompyimporthellosettingsinitwindowsdef
1条回答
网友
1楼 · 发布于 2024-05-20 13:43:34

你可以在家里试试这样的东西设置.py你知道吗

导入整个shodan文件。然后尝试创建Shodan类的对象,并使用该对象调用hello方法。你知道吗

这将导致您的设置.py像这样归档。你知道吗

from optparse import OptionParser
from sys import platform as _platform
from google.google import * 
import shodan.shodan

def settings(argv=None):
    if _platform == "linux" or _platform == "linux2":
    #Linux
        CrossPlatformCommandLineParser()
    elif _platform == "darwin":
    # MAC OS X
        CrossPlatformCommandLineParser()
    elif _platform == "win32":
    # Windows
        CrossPlatformCommandLineParser()
    elif _platform == "win64":
    # Windows 64-bit
        CrossPlatformCommandLineParser()

def CrossPlatformCommandLineParser(argv=None):
    if _platform == "linux" or _platform == "linux2":
    #Linux
        #print 'Linux ' + 'new cyber weapon'
        #google()
        shodanObject = shodan.Shodan("aaa")
        shodanObject.hello()
    elif _platform == "darwin":
    # MAC OS X
        print 2 
    elif _platform == "win32":
    # Windows
        print 3
    elif _platform == "win64":
    # Windows 64-bit
        print 4

修改您的shodan如下:

class Shodan:
    """docstring for ClassName"""
    key = ""
    def __init__(self, key):
        self.key = "aaa"

    def hello():
        print '[+] shodan...' + self.key

观察中的变化设置.py用于对象创建。 shodanObject=肖丹。肖丹(“aaa”)这一行。你知道吗

相关问题 更多 >