Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 16:51, 24 September 2008.

How to execute another script from a script

From Forum Nokia Wiki

In order to execute a Python script from another script, we use the execfile(file[, globals[, locals]]) function.

For example, we have the file b.py (located in "C:\\Python\\b.py") which we want to execute from another script, say a.py

b.py contains the following code:

x=4
print x

a.py contains the following code:

import appuifw, e32
 
def quit(): 
  app_lock.signal()
 
appuifw.app.exit_key_handler=quit
 
#Now we specify the path to the file we want to execute, and give the instruction
f='C:\\Python\\b.py'
execfile(f)
#In some cases there may be a NameError error in the executed script regarding variables not being defined
#To overcome this, use execfile(f, {})
 
app_lock=e32.Ao_lock()
app_lock.wait()

This should display 4 on the screen.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Pyspy Skarabeus Python 12 2007-07-31 14:11
python script that can automate Number keys in mobile sumimadhavan Python 2 2008-03-10 05:46
prob in embedding python interpretor abhinavkaushik Python 6 2005-12-07 16:10
Database with Wml Script Jameel Browsing and Mark-ups 3 2002-05-15 18:49
Positioning Module with Error -46 Permission Denied julierico Python 4 2008-04-03 15:36
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtopicQUqfnTopicZpythonQ
     qfnZtopicQUqfnTopicZseriesE5f60Q
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX