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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • davidj411

    #1

    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,bi gstring, numbertimes,num _times_search_s tring)

    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' , 'peterjacksonpe terjacksonpeter ', 2, 0)
    <type 'tuple'>
    >>tu_count
    ('davidjacksond avidjacksondavi d', 2, 0)

    thanks
  • alex23

    #2
    Re: function returns , but variable values has not changed in theinteractive prompt

    On May 24, 5:04 am, davidj411 <davidj...@gmai l.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.p y')
    >>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.

    Comment

    • Gabriel Genellina

      #3
      Re: function returns ,but variable values has not changed in the interactive prompt

      En Fri, 23 May 2008 16:04:43 -0300, davidj411 <davidj411@gmai l.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("tes t.py")
      pya
      123
      pyfoo()
      'hello'

      --
      Gabriel Genellina

      Comment

      Working...