GIDForums  

Go Back   GIDForums > Computer Programming Forums > Python Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Jun-2006, 20:06
woovy28 woovy28 is offline
New Member
 
Join Date: Jun 2006
Posts: 1
woovy28 is on a distinguished road
Question

Pyhton and Java


Hi !
I'm new to Python, and i want to use the following code to connect to a xmlrpc server for some inquiry, I wanna know if there is anything wrong with the code ?
Shouln't it when run prints the server_url and then connected ? (it doesn't print any)

Second can I activate and call this class from a java class using jython ???? or even pass a parameter from java class to this class ????

how could that be done using jython ????

Thanks in advance

the code :
----------

Python Code:
import sys, string, xmlrpclib

class DrugInteraction :
        
    def _init_(self):
        self.url = "http://hherb.com"
        self.port = 8001
        self.server_url = "%s:%d" % (url, port)
        self.effects = {'i':'inhibits (non-clinical)', 'I':'inhibits', 'a':'augments (non-clinical)', 'A':'augments'}
        print self.server_url
        self.server=xmlrpclib.ServerProxy(server_url)
        print "Connected"
        return
    
    def checkInteraction(self,drugs):
        self.druglist = string.split(drugs, ',')
        self.results = self.server.interaction(druglist)
        for self.result in self.results:
            self.drug, = self.server.atc2text(self.result['drug'])
            self.affected_drug, = self.server.atc2text(self.result['affected_drug'])
            self.effect = self.effects[self.result['effect']]
            self.resultData = [self.drug['text'], self.drug['code'], self.effect, self.affected_drug['text'], self.affected_drug['code'], self.result['evidence'], self.result['reference']]
            return

x = DrugInteraction()
Last edited by LuciWiz : 14-Jun-2006 at 00:31. Reason: Please insert your Python code between [py] & [/py] tags
  #2  
Old 14-Jun-2006, 12:43
crystalattice's Avatar
crystalattice crystalattice is offline
Aspiring author
 
Join Date: Apr 2004
Location: Japan (again)
Posts: 1,635
crystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nicecrystalattice is just really nice

Re: Pyhton and Java


Well, I haven't learned Jython yet so I can't really answer your questions regarding that. However, you should be able to call it from Java w/ the right methods; I just don't know what they are.

Regarding the print problem, how are you running this module? Normally you could create a
Python Code:
def test():
outside of your class then call your test() method like so:
Python Code:
if __name__ == "__main__":
    test()
The test() method would just code necessary to show that your module worked, i.e. it would create an instance and the necessary parameters to make the instance do something. It's probably a good place to put the print "Connected" code; I don't believe having it in the __init__ constructor is the best place (but I'm not totally certain).

Take a look at the other Python modules I've posted in these forums; they should explain better what I mean.
__________________
Start Programming with Python-A beginner's guide to programming and the Python language.
-------------
Common Sense v2.0-Striving to make the world a little bit smarter.
 
 

Recent GIDBlogProblems with the Navy (Enlisted) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:46.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.