By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,621 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,621 IT Pros & Developers. It's quick & easy.

function returns , but variable values has not changed in theinteractive prompt

P: n/a
if you run execfile function to run a python script and that script
has variables and functions, should't those variable change in the
interactive prompt too?

script snippet that calls the function which should return like this
return (stuffedname,bigstring, numbertimes,num_times_search_string)

this is the variable that calls the functions. when a function returns
something AND there is a variable set as shown immediately below,
does't the variable get updated?

tu_count = CountStrings (name, balance, searchstr)

this is the output from the script.
notice how tu_count actually differs when called from interactive
prompt after script exits.

tu_count: ('peterjackson', 'peterjacksonpeterjacksonpeter', 2, 0)
<type 'tuple'>
>>tu_count
('davidjacksondavidjacksondavid', 2, 0)

thanks
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On May 24, 5:04 am, davidj411 <davidj...@gmail.comwrote:
if you run execfile function to run a python script and that script
has variables and functions, should't those variable change in the
interactive prompt too?
Yes.
>cat a.py
a = 7
b = 'seven'

Python 2.5.1 (r251:54863, May 1 2007, 17:47:05) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>execfile('a.py')
a
7
>>b
'seven'

I think you need to show us the actual code in question, rather than
the odd behaviour you're experiencing. It's generally easier to debug
real code over blackboxing behaviour.
Jun 27 '08 #2

P: n/a
En Fri, 23 May 2008 16:04:43 -0300, davidj411 <da*******@gmail.comescribió:
if you run execfile function to run a python script and that script
has variables and functions, should't those variable change in the
interactive prompt too?
Yes, they do:

C:\TEMP>type test.py
a = 123

def foo():
return "hello"

(enter Python)
pya = "Old value"
pya
'Old value'
pyexecfile("test.py")
pya
123
pyfoo()
'hello'

--
Gabriel Genellina

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.