473,287 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

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

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
2 1059
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
12
by: Gaurav Veda | last post by:
Hi ! I am a poor mortal who has become terrified of Python. It seems to have thrown all the OO concepts out of the window. Penniless, I ask a basic question : What is the difference between a...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
14
by: Mike Labosh | last post by:
How do you define whether the return value of a function is ByRef or ByVal? I have a utility class that cleans imported records by doing *really heavy* string manipulation in lots of different...
59
by: Pierre Quentel | last post by:
Hi all, In some program I was testing if a variable was a boolean, with this test : if v in My script didn't work in some cases and I eventually found that for v = 0 the test returned True ...
7
by: divya | last post by:
What is an equivalent TimeSerial() function of VBscript in the Java Script?? I have two variables hour and minutes. Timeserial(hour,minutes) returns the time hour : minutes. But I want to do...
36
by: AB3004 | last post by:
Hi, I'm currently working on this piece of code & unfortunately, whenever I run it, it states that selectNumbers isn't defined and it errors on Line 1 (?) can anyone tell me why? I'm tearing my...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.