开发者

How to call a funciton from an another python file

开发者 https://www.devze.com 2023-03-20 18:00 出处:网络
I have a xml parser in python by named : NmapParser.py def nmap_parser_sax(nmap_xml_file): parser = make_parser()

I have a xml parser in python by named : NmapParser.py

def nmap_parser_sax(nmap_xml_file):
    parser = make_parser()
    nmap_parser = NmapParserSAX()
    parser.setContentHandler(nmap_parser)
    nmap_parser.set_parser(parser)
    nmap_parser.set_xml_file(nmap_xml_file)
    return nmap_parser

Now i have to call this function from an another file i.e. views.py. I did that

import NmapParser
nm开发者_JAVA技巧ap_parser_sax("/home/lovestone/Desktop/usoc/umit/nmap_example.xml")
print nmap_xml_file

I tried this it shows an following error:

Traceback (most recent call last):
File "parse.py", line 2, in <module>
nmap_parser_sax("/home/lovestone/Desktop/usoc/umit/nmap_example.xml")
NameError: name 'nmap_parser_sax' is not defined

What i have to do is to parse the value from a xml file and then i have to save that value in my java script variable. I am on Django platform.

I also tried this :

import NmapParser
NmapParser.nmap_parser_sax("/home/lovestone/Desktop/usoc/umit/nmap_example.xml")
print nmap_xml_file

and still it is showing same error


you either need to use

from NmapParser import nmap_parser_sax
result = nmap_parser_sax("/home/lovestone/Desktop/usoc/umit/nmap_example.xml")
print result.nmap_xml_file

or

import NmapParser
result = NmapParser.nmap_parser_sax("/home/lovestone/Desktop/usoc/umit/nmap_example.xml")
print result.nmap_xml_file
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号