<p><br>
On 9 Feb 2012 13:34, "David Craig" <<a href="mailto:dcdavemail@gmail.com">dcdavemail@gmail.com</a>> wrote:<br>
><br>
> Hi,<br>
> I'm trying to write a function that will either take arguments when the function is called, such as myFunc(x,y,z) or if the user does not enter any arguments, myFunc() the raw_input function will ask for them. But I dont know how to check how many arguments have been entered. My code is below. Anyone know how??<br>
> Thanks<br>
> D<br>
><br>
><br>
> def NoiseCorr(file1,file2,500,0.25,0.35):<br>
><br>
> #######################################################################################<br>
> ### Check number of arguments<br>
> ??????????????????<br>
><br>
> #######################################################################################<br>
> ### User inputs.<br>
> if numArgs == 0:<br>
> file1 = raw_input('Path to Station 1: ')<br>
> file2 = raw_input('Path to Station 2: ')<br>
> shift_length = raw_input('Length of Correlation: ')<br>
> freqMin = raw_input('Min. Frequency: ')<br>
> freqMax = raw_input('Max. Frequency: ')<br></p>
<p>Hi David,</p>
<p>From your description, it doesn't sound as though you do need the number of arguments. Are you familiar with keyword args and default values?</p>
<p>I would do it like so:</p>
<p>def myfunc(x=None):<br>
if x is None:<br>
x=raw_input(a_prompt)</p>
<p>expanding the arg list as needed. This also allows for callers to specify only some of the values.</p>
<p>HTH,</p>
<p>Brian vdB </p>