Re: Importing an output from another function

2006-03-20 Thread Magnus Lycka
Byte wrote: > Now what do I do if Func1() has multiple outputs and Func2() requires > them all to give its own output, as follows: > > import random > > def Func1(): > choice = ('A', 'B', 'C') > output = random.choice(choice) > output2 = random.choice(choice) > return output >

Re: Importing an output from another function

2006-03-18 Thread John Salerno
Byte wrote: > "Try this (I think its called "argument expansion", but I really don't > know what its called, so I can't point you to docs):" > > This works, thanks. But how acn I get rid of the ugly surrounding > brackets and commas? > > e.g. If the scripts overall output was (('B', 'C'),), how

Re: Importing an output from another function

2006-03-18 Thread Byte
"Try this (I think its called "argument expansion", but I really don't know what its called, so I can't point you to docs):" This works, thanks. But how acn I get rid of the ugly surrounding brackets and commas? e.g. If the scripts overall output was (('B', 'C'),), how to change it to just B C?

Re: Importing an output from another function

2006-03-17 Thread Ben Cartwright
James Stroud wrote: > Try this (I think its called "argument expansion", but I really don't > know what its called, so I can't point you to docs): > > def Func1(): > choice = ('A', 'B', 'C') > output = random.choice(choice) > output2 = random.choice(choice) > return output, outp

Re: Importing an output from another function

2006-03-17 Thread Paul Rubin
"Byte" <[EMAIL PROTECTED]> writes: > Probably a stupid question, but I'm a newbie and this really pisses me > off. Run this script: > > import random > > def Func1(): > choice = ('A', 'B', 'C') > output = random.choice(choice) > > def Func2(): > print output > > Func1() > Func2() Y

Re: Importing an output from another function

2006-03-17 Thread Terry Hancock
On 17 Mar 2006 12:15:28 -0800 "Byte" <[EMAIL PROTECTED]> wrote: > Probably a stupid question, but I'm a newbie and this > really pisses me off. Run this script: > > import random > > def Func1(): > choice = ('A', 'B', 'C') > output = random.choice(choice) > > def Func2(): > print out

Re: Importing an output from another function

2006-03-17 Thread James Stroud
John Salerno wrote: > James Stroud wrote: > > Try this (I think its called "argument expansion", but I really don't > know what its called, so I can't point you to docs): > > def Func1(): > choice = ('A', 'B', 'C') > output = random.choice(choice) > output2 = random.choice(choice) > return output

Re: Importing an output from another function

2006-03-17 Thread John Salerno
James Stroud wrote: > Yours is better, after I wrote mine, I realized the asterisk was > unnecessary for this particular example, except that it makes Func2 more > general. Yeah, I tested it. Func2 prints a tuple of a tuple when the asterisk is used. But your generator still wins. :) -- http

Re: Importing an output from another function

2006-03-17 Thread James Stroud
John Salerno wrote: > James Stroud wrote: > >> Try this (I think its called "argument expansion", but I really don't >> know what its called, so I can't point you to docs): >> >> def Func1(): >> choice = ('A', 'B', 'C') >> output = random.choice(choice) >> output2 = random.choice(choi

Re: Importing an output from another function

2006-03-17 Thread John Salerno
James Stroud wrote: > Try this (I think its called "argument expansion", but I really don't > know what its called, so I can't point you to docs): > > def Func1(): > choice = ('A', 'B', 'C') > output = random.choice(choice) > output2 = random.choice(choice) > return output, outpu

Re: Importing an output from another function

2006-03-17 Thread James Stroud
Byte wrote: > Now what do I do if Func1() has multiple outputs and Func2() requires > them all to give its own output, as follows: > > import random > > def Func1(): > choice = ('A', 'B', 'C') > output = random.choice(choice) > output2 = random.choice(choice) > return output >

Re: Importing an output from another function

2006-03-17 Thread John Salerno
Byte wrote: > Now what do I do if Func1() has multiple outputs and Func2() requires > them all to give its own output, as follows: You can return them as a tuple: >>> def func1(): output1 = 'hi' output2 = 'bye' return (output1, output2) >>> def func2(data): prin

Re: Importing an output from another function

2006-03-17 Thread Byte
Now what do I do if Func1() has multiple outputs and Func2() requires them all to give its own output, as follows: import random def Func1(): choice = ('A', 'B', 'C') output = random.choice(choice) output2 = random.choice(choice) return output return output2 def Func2(item1,

Re: Importing an output from another function

2006-03-17 Thread Byte
Great, thanks -- /usr/bin/byte -- http://mail.python.org/mailman/listinfo/python-list

Re: Importing an output from another function

2006-03-17 Thread bearophileHUGS
Generally, a name defined into a function can't be read outside of it, so you have to return the function result explicitely: import random def Func1(): choice = ('A', 'B', 'C') output = random.choice(choice) return output def Func2(item): print item output1 = Func1() Func2(outp

Importing an output from another function

2006-03-17 Thread Byte
Probably a stupid question, but I'm a newbie and this really pisses me off. Run this script: import random def Func1(): choice = ('A', 'B', 'C') output = random.choice(choice) def Func2(): print output Func1() Func2() And: an error message.. It says: Traceback (most recent cal