Re: [Tutor] How can a function know where it was called from

2006-03-02 Thread Bob Gailer
Ben Vinger wrote: > Thanks to all who responded. I ended up using a sender parameter as > suggested by Andre and Alan, as this was very simple to do. When confronted with problems like this I tend to create classes, then subclass as needed for special circumstances. You might consider that app

Re: [Tutor] How can a function know where it was called from

2006-03-02 Thread Ben Vinger
Thanks to all who responded.  I ended up using  a sender parameter as suggested by Andre and Alan, as this was very simple to do.   Ben   ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] How can a function know where it was called from

2006-03-02 Thread Kent Johnson
Noufal Ibrahim wrote: > On Thu, March 2, 2006 3:55 pm, Ben Vinger wrote: > >>Hello >> >>I want myfunction in the pseudocode below return something different if it >>was called from indexfunction. > > > I'm new to this but maybe it would be good if you passed the appropriate > "version" of "myfun

Re: [Tutor] How can a function know where it was called from

2006-03-02 Thread Ewald Ertl
Hi Ben! After looking at the modules I detected the traceback-Module in my installation: >>> import traceback >>> def two(): ... one() ... >>> two() >>> def one(): ... print traceback.extract_stack() ... >>> def two(): ... one() ... >>> two() [('', 1, '?', None), ('', 2, 'two', None),

Re: [Tutor] How can a function know where it was called from

2006-03-02 Thread Noufal Ibrahim
On Thu, March 2, 2006 3:55 pm, Ben Vinger wrote: > Hello > > I want myfunction in the pseudocode below return something different if it > was called from indexfunction. I'm new to this but maybe it would be good if you passed the appropriate "version" of "myfunction" to indexfunction from where t

Re: [Tutor] How can a function know where it was called from

2006-03-02 Thread Alan Gauld
Ben, > I want myfunction in the pseudocode below return something > different if it was called from indexfunction. There are several approaches to this. > def indexfunction(): blah > > def myfunction(): >if : return x >else: return + x + The simplest approach simply includes a "

Re: [Tutor] How can a function know where it was called from

2006-03-02 Thread Andre Roberge
On 3/2/06, Ben Vinger <[EMAIL PROTECTED]> wrote: > > Hello > > I want myfunction in the pseudocode below return something different if it > was called from indexfunction. > How about adding a parameter to myfunction itself: def indexfunction(): blah myfunction(fromindexfunction=True) d

[Tutor] How can a function know where it was called from

2006-03-02 Thread Ben Vinger
Hello   I want myfunction in the pseudocode below return something different if it was called from indexfunction.   def indexfunction():    blah   def myfunction():   x = 'whatever'   if :  return x   else:  return + x +     Thanks Ben ___ Tuto