Hi again

Playing with different parameter configurations, I have found  the next behaviour which I consider an inconsistency (maybe I am wrong).

Suppose the next function

def f1(a, b=2): print a, b

We can write

f1(1,4) or f1(1,b=4)

obtaining correctly

1 4

Using

def f2(a, b=2,*c): print a, b, c

f2(1,4) and f2(1,b=4)

gives correctly

1 4 ()

Again

f2(1,4, 3)

gives (correctly)

1 4 (3)

but

f2(1,b=4, 3)

gives the error: SyntaxError: non-keyword arg after keyword arg

Is this consistent?

josu

El 09-ots-20, a las 15:31, josu jugo escribió:

For example, if I want a plot function similar to the plot function in
Matlab with (for instance) the next possibilities

plot(x) plot(x,y,x1,y1) plot(x,y,'-r')

the combination on this kind of parameter possibilties can be
cumbersome (if you need it) and I think that the use of an "if-else"
solution  will result in a code difficult to maintain/improve.

Other solution can be a similar sintaxis, but no replicating the
previous one.

josu

El 09-ots-20, a las 13:50, Nicholas Riley escribió:

In article <D149F8E6-E3A3-4A80-B6B3-6FA8521559F6@we.lc.ehu.es>,
josu jugo <josu@we.lc.ehu.es> wrote:

When defining functions, I normally use if-else statement for parsing
its arguments. However, in this case, I want to define a more complex
function. can anybody suggest a better way to do this task?

Can you give an example?  The only other thing I've ever needed was to
loop through the positional or keyword arguments, which are no
different
to any other Python tuple or dictionary in that matter.

(Note: for generic Python questions such as the above, you will likely
get faster/more responses posting on a Python mailing list.)
--
Nicholas Riley <njriley@uiuc.edu>

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San
Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the
Enterprise
-Strategies to boost innovation and cut costs with open source
participation
-Receive a \$600 discount off the registration fee with the source
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a \$600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Jython-users mailing list
Jython-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jython-users