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

D

davidj411

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)
('davidjacksondavidjacksondavid', 2, 0)

thanks
 
A

alex23

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.'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.
 
G

Gabriel Genellina

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)
py> a = "Old value"
py> a
'Old value'
py> execfile("test.py")
py> a
123
py> foo()
'hello'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top