You Are Here:

Community: Developer Discussion Boards

#1 Old Question how to run a part of a script from another script???? - 2008-12-05, 16:51

Join Date: Sep 2008
Posts: 32
Location: India
gnanasenthil654321
Offline
Registered User
hi,i have two scripts say a.py and b.py.now i want to execute A PART OF THE SCRIPT b.py FROM a.py.Is this possible....If so how should the code be........
Reply With Quote

#2 Old Re: how to run a part of a script from another script???? - 2008-12-05, 17:02

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
How do you determine which part of the other file you want to run? You can always load the file as a large string and exec parts of it. Something like this (not tested):

b.py:

Code:
appuifw.note(u"I don't want this to run.", "info")

# START HERE

appuifw.note(u"I'm running.", "info")

# STOP HERE

appuifw.note(u"This is also something I don't want to run.", "info")
a.py:
Code:
import appuifw

myprog = open("b.py", "r").read()

startoffset = myprog.find("# START HERE")
stopoffset = myprog.rfind("# STOP HERE")

if startoffset >= 0 and stopoffset >= 0:
    exec myprog[startoffset:stopoffset]
A better way is to structure your b.py as a Python module, import it from a.py and call its functions.
Last edited by jethro.fn : 2008-12-05 at 17:07. Reason: exec, not eval()
Reply With Quote

#3 Old Re: how to run a part of a script from another script???? - 2008-12-06, 21:38

Join Date: Mar 2003
Posts: 937
Location: Espoo, Finland
JOM's Avatar
JOM
Offline
Forum Nokia Champion
Really nice!!! I had no idea you can do anything like that

Thanx,

--jouni
Reply With Quote

#4 Old Re: how to run a part of a script from another script???? - 2008-12-07, 18:51

Join Date: May 2004
Posts: 524
Location: Tampere, Finland
jethro.fn's Avatar
jethro.fn
Offline
Forum Nokia Champion
Quote:
Originally Posted by JOM View Post
Really nice!!! I had no idea you can do anything like that
Dynamic languages are cool that way. You have the language parser/compiler around at all times, so why not make use of it?
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
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 Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make my python script run at background? mdzhao Python 5 2007-07-02 17:02
help in run script perthachy Python 6 2007-07-02 04:01
How to run my python script? Gowtham_India Python 2 2007-06-25 11:15
I can't run Python script on my mobile. HELP!!! Nirvana Python 3 2007-05-30 14:04
write perl/python script in your S60 phone kamijawa Python 5 2006-06-03 16:59

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d81449X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ