Reputation: 127
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
Upvotes: 2
Views: 2085
Reputation: 43533
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.
Upvotes: 4
Reputation: 114038
maybe from hl7 import MLLPClient
?
or maybe do
with hl7.MLLPClient(...) as ...
Upvotes: 3