functon invoke or not

2013-01-09 Thread skyworld
Hi,

I see someone's code as this:

class ABC: 
def __init__(self, env):
 ...
 self.jmpTable['batchQ']['submit_job']  = self.lsf_submit
 ...
def lsf_submit(self, cmd,env):
 .

what confused me is why there is no parentheses for self.lsf_submit in
self.jmpTable['batchQ']['submit_job']  = self.lsf_submit? what does
this piece of code mean? thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: functon invoke or not

2013-01-09 Thread skyworld
On 1月9日, 下午4时46分, Mitya Sirenef msire...@lightbird.net wrote:
 On Wed 09 Jan 2013 03:23:56 AM EST, skyworld wrote:

  Hi,

  I see someone's code as this:

  class ABC: 
       def __init__(self, env):
            ...
            self.jmpTable['batchQ']['submit_job']  = self.lsf_submit
            ...
       def lsf_submit(self, cmd,env):
            .

  what confused me is why there is no parentheses for self.lsf_submit in
  self.jmpTable['batchQ']['submit_job']  = self.lsf_submit? what does
  this piece of code mean? thanks.

 Presumably it will be called at a later point:

 def f(): print 'foo'

 lst = [f]
 # la la
 lst[0]()

 HTH,  -m

 --
 Lark's Tongue Guide to Python:http://lightbird.net/larks/

Thanks for both of your replies. I got it.
-- 
http://mail.python.org/mailman/listinfo/python-list


question on subprogram parameter

2012-10-28 Thread skyworld
Hi,

I'm studying python now and I saw a piece of code like this:

def storeDbase(db, dbfilename=dbfilename):
 .
 dbfile=open(dbfilename,'w')
 for key in db:
  print(key, file=dbfile)


can anybody help me to understand what does this file=dbfile mean
and what is its function? thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: how to change os.popen4 to subprocess

2012-10-27 Thread skyworld
On Oct 27, 11:02 am, MRAB pyt...@mrabarnett.plus.com wrote:
 On 2012-10-27 03:28, skyworld wrote: Hi,

  I'm new to python and I'm trying to porting some scripts from v0.96 to
  v2.0.1. A piece of code is like this:

  cmd_h = os.popen4(env['SYSCMDLINE'])[1]

  the system indicates the popen4 is deprecated and suggest to use
  subprocess. Can anybody tell me how to use subprocess in this case?
  and what does [1] here means?

 os.popen4 returns a tuple of (child_stdin, child_stdout_and_stderr).
 The [1] gets the child_stdout_and_stderr member.

 Using the subprocess module:

 # Untested!
 cmd_h = subprocess.Popen(env['SYSCMDLINE'], stdout=subprocess.PIPE,
 stderr=subprocess.STDOUT, shell=True).stdout

 Explanation:

 The command line: env['SYSCMDLINE']

 Return stdout: stdout=subprocess.PIPE

 stderr should be combined with stdout: stderr=subprocess.STDOUT

 Let the shell parse the command line: shell=True

thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


how to change os.popen4 to subprocess

2012-10-26 Thread skyworld
Hi,

I'm new to python and I'm trying to porting some scripts from v0.96 to
v2.0.1. A piece of code is like this:

cmd_h = os.popen4(env['SYSCMDLINE'])[1]

the system indicates the popen4 is deprecated and suggest to use
subprocess. Can anybody tell me how to use subprocess in this case?
and what does [1] here means?

thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list