[英]Python 2.7 - Help using an API (HL7)
I am new to programming and Python. 我是编程和Python的新手。
I have a very basic python script that connects to server and send a text message: 我有一个非常基本的python脚本,可以连接到服务器并发送文本消息:
#!/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 ) 一切正常,除了此消息是HL7消息并且需要用MLLP封装外,我发现此API我认为可以为我做到这一点( 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 因此,我将程序修改为以下内容,但始终收到错误消息:NameError:未定义名称“ MLLPClient”
#!/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
? 也许
from hl7 import MLLPClient
?
or maybe do 或者也许
with hl7.MLLPClient(...) as ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.