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
>
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
"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?
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
"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
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
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
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
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
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
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
>
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
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,
Great, thanks
-- /usr/bin/byte
--
http://mail.python.org/mailman/listinfo/python-list
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
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
16 matches
Mail list logo