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
return
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?
--
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 to change
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
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()
Great, thanks
-- /usr/bin/byte
--
http://mail.python.org/mailman/listinfo/python-list
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,
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
return
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, output2
def
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
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. :)
--
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, output2
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 output
Func1()
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()
You could declare
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, output2
def
15 matches
Mail list logo