2012-09-30 30 views
1

我是编程和Python的新手。Python 2.7 - 使用API​​(HL7)的帮助

我有一个连接到服务器的一个非常基本的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 

一切都很好,只是这个消息是HL7消息,需要包裹在MLLP 我发现这API,我觉得能为我做到这一点(http://python-hl7.readthedocs.org/en/latest/api.html#mllp-network-client

所以我修改我的程序如下,但我不断收到错误消息: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 

回答

3

您可以用不同的方式做到这一点;

如果导入的顶级包

import hl7 

你应该与它的全名创建对象:

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

,或者你可以只导入特定的类:

from hl7.client import MLLPClient 

并像你在你的例子中那样使用它。

查看modules documentation了解更多信息。

+0

它的工作。谢谢! – atomicluis

2

也许from hl7 import MLLPClient

也许做

with hl7.MLLPClient(...) as ... 
+0

如果您试图将HL7消息发送到特定的地方,您将如何找到例如某个特定城镇的医院的主机名和端口? –