简体   繁体   中英

Python 2.7 - Help using an API (HL7)

I am new to programming and Python.

I have a very basic python script that connects to server and send a text message:

#!/usr/bin/python           
import socket               
s = socket.socket()        
host = '127.0.0.1' 
port = 4106               
s.connect((host, port))
message = 'test1' 
s.send(message)
print s.recv(1024)
s.close 

Everything is fine, except that this message is an HL7 message and needs to wrapped in MLLP I found this API that I think can do this for me ( http://python-hl7.readthedocs.org/en/latest/api.html#mllp-network-client )

So I modified my program to the following, but I keep getting the error message: NameError: name 'MLLPClient' is not defined

#!/usr/bin/python           
import socket   
import hl7                 
host = '127.0.0.1' 
port = 4106               
with MLLPClient(host, port) as client:
  client.send_message('test1')
print s.recv(1024)
s.close 

You can do this in different ways;

If you import the top-level package

import hl7

You should create the object with its complete name:

with hl7.client.MLLPClient(host, port) as client:
    client.send_message('test1')

or you can import only the specific class:

from hl7.client import MLLPClient

and use it like you did in your example.

See the modules documentation for more information.

maybe from hl7 import MLLPClient ?

or maybe do

with hl7.MLLPClient(...) as ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM