ConfigParser: Can I read(ConfigParser.get()) a configuration file and use it to call a funciton?

2008-06-26 Thread jamitwidme
Hello. I am a novice programmer and have a question

I have a configuration file(configuration.cfg)
I read this from reading.py using ConfigParser
When I use ConfigParser.get() function, it returns a string.
I want to call a function that has the same name as the string from
the configuration file.


configuration.cfg
---
[1234]
title: abcd
function: efgh
---


reading.py

import ConfigParser

def efgh():
   print 'blah'

config = ConfigParser.ConfigParser()
config.read('configuration.cfg')

fcn = config.get('1234','function')
type(fcn)
print fcn



efgh


Is there any way to call efgh() ?
One way I know is using if statement
if fcn == 'efgh':
   efgh()

But I am going to have many functions to call, so I want to avoid
this.


Thank you for your help
--
http://mail.python.org/mailman/listinfo/python-list


Re: ConfigParser: Can I read(ConfigParser.get()) a configuration file and use it to call a funciton?

2008-06-26 Thread jamitwidme
Thank you for the answers.
Now I understood how to call a function, let me ask you another
question.

configuration.cfg
---
[1234]
title: abcd
function: efgh
---

reading.py

import ConfigParser

class Functions:
   def efgh(self):
  print 'blah'

fcn = Functions()

config = ConfigParser.ConfigParser()
config.read('configuration.cfg')
title = config.get('1234','title') # number 1
function_name = config.get('1234','function')

title = getattr(fcn, function_name)
title()


instead of assigning string value('abcd') to title at number 1

I want to assign this function(fcn.efgh()) to abcd and make abcd a
FunctionType.
so later on, I want to call it by abcd(), not title().
The reason is I will have a loop reading from configuration file, so I
need to have different names for each function.
abcd is a string I read got it from config.get('1234','title')

Thanks again.
--
http://mail.python.org/mailman/listinfo/python-list


raw_input into Tkinter ?

2008-06-30 Thread jamitwidme
Is there any way to type into a Tkinter frame window?
I want to use raw_input() within a Tkinter frame.
--
http://mail.python.org/mailman/listinfo/python-list


Pyro: ProtocolError('connection failed')

2008-07-02 Thread jamitwidme
Hello everyone
Can someone help me fix this problem?

I am using an example from Pyro(Python Remote Object) website
directly.
It is the last example from
http://pyro.sourceforge.net/manual/8-example.htm

I have two computers to run Server and Client.

server.py

import Pyro.naming
import Pyro.core
from Pyro.errors import PyroError,NamingError


## testclass Pyro object

class testclass(Pyro.core.ObjBase):
def mul(s, arg1, arg2): return arg1*arg2
def add(s, arg1, arg2): return arg1+arg2
def sub(s, arg1, arg2): return arg1-arg2
def div(s, arg1, arg2): return arg1/arg2

## main server program

def main():
Pyro.core.initServer()
daemon = Pyro.core.Daemon()
# locate the NS
locator = Pyro.naming.NameServerLocator()
print 'searching for Name Server...'
ns = locator.getNS(host='drizzle.des.hep.uiuc.edu', port=9090)
daemon.useNameServer(ns)

# connect a new object implementation (first unregister
previous one)
try:
# 'test' is the name by which our object will be known
to the outside world
ns.unregister('test')
except NamingError:
pass

# connect new object implementation
daemon.connect(testclass(),'test')

# enter the server loop.
print 'Server object "test" ready.'
daemon.requestLoop()

if __name__=="__main__":
main()

###

###
client.py

import Pyro.naming, Pyro.core
from Pyro.errors import NamingError

# locate the NS
locator = Pyro.naming.NameServerLocator()
print 'Searching Name Server...',
ns = locator.getNS(host='drizzle.des.hep.uiuc.edu',port=9090)

# resolve the Pyro object
print 'finding object'
try:
URI=ns.resolve('test')
print 'URI:',URI
except NamingError,x:
print 'Couldn\'t find object, name server says:',x
raise SystemExit

# create a proxy for the Pyro object, and return that
test = Pyro.core.getProxyForURI(URI)

print test.mul(111,9)
print test.add(100,222)
print test.sub(222,100)
print test.div(2.0,9.0)
print test.mul('*',10)
print test.add('String1','String2')
###

It does not matter which computer Pyro NameServer is located.
When Server and Client are in a same computer, it works perfectly
fine.
But whenever Server and Client run in different computers, I get a
following error message.



Pyro Client Initialized. Using Pyro V3.7
Searching Name Server... finding object
URI: PYRO://127.0.0.1:7888/7f01193649ab6a89d5592bc843bb
Traceback (most recent call last):
 File "client.py", line 22, in 
   print test.mul(111,9)
 File "/usr/local/lib/python2.5/site-packages/Pyro/core.py", line
390, in __call__
   return self.__send(self.__name, args, kwargs)
 File "/usr/local/lib/python2.5/site-packages/Pyro/core.py", line
467, in _invokePYRO
   self.adapter.bindToURI(self.URI)
 File "/usr/local/lib/python2.5/site-packages/Pyro/protocol.py", line
255, in bindToURI
   raise ProtocolError('connection failed')
Pyro.errors.ProtocolError: connection failed


Thanks a lot.
--
http://mail.python.org/mailman/listinfo/python-list