473,785 Members | 2,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

extra positional arguments before optional parameters syntax

I noticed that in PEP 3105, the PEP about turning print to print(),
the syntax for print() is defined as follows:
def print(*args, sep=' ', end='\n', file=None)

Ignoring the fact that print is a reserved keyword in python, this is
not valid python because extra positional arguments (*args), cannot
come before optional parameters (sep=' ', end='\n', file=None).
>>def f(*args, sep=' ', end='\n', file=None):
File "<stdin>", line 1
def f(*args, sep=' ', end='\n', file=None):
^
SyntaxError: invalid syntax

Am I misunderstandin g something? Is this type of syntax suppose to be
allowed in a future version of Python? (I can't find anything about
this through my searching.) This kind of syntax seems useful,
especially one wants to overwrite the new function print().

Thanks,
William Chang
Jun 27 '08 #1
1 1320
On Jun 18, 5:25 pm, MisterWilliam <mr.williamch.. .@gmail.comwrot e:
I noticed that in PEP 3105, the PEP about turning print to print(),
the syntax for print() is defined as follows:
def print(*args, sep=' ', end='\n', file=None)

Ignoring the fact that print is a reserved keyword in python, this is
not valid python because extra positional arguments (*args), cannot
come before optional parameters (sep=' ', end='\n', file=None).
>def f(*args, sep=' ', end='\n', file=None):

File "<stdin>", line 1
def f(*args, sep=' ', end='\n', file=None):
^
SyntaxError: invalid syntax

Am I misunderstandin g something? Is this type of syntax suppose to be
allowed in a future version of Python? (I can't find anything about
this through my searching.)
You didn't search hard enough; it's three PEPs earlier:

http://www.python.org/dev/peps/pep-3102/

George
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
4578
by: Rob Long | last post by:
Hey, I've just noticed a somewhat annoying feature with PHP5 type hinting. You cannot hint types on optional arguments like this: class MyClass { function someFunc(Type1 $arg1, Type2 $arg2 = new Type2()) { }
66
5036
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
13
1584
by: Madhusudan Singh | last post by:
Hi I know how to set optional arguments in the function definition. Is there an intrinsic function that determines if a certain argument was actually passed ? Like the fortran 95 present() logical intrinsic ? My required functionality depends on whether a certain argument is specified at all. (Setting default values is *not* good enough.). Thanks.
4
13572
by: Augustus S.F.X Van Dusen | last post by:
I have recently come across the following construction: #define P_VAR(output, string, args...) \ fprintf (output, "This is "string"\n", ##args) which can be invoked as follows: int x = 1, y = 2 ; char * str = "String" ;
12
2298
by: Nick Hounsome | last post by:
Can anyone tell me what the rational is for not supporting optional arguments. It is obviously a trivial thing to implement and, since C++ has them, I would not expect them to be omitted without a good reason.
14
3275
by: cody | last post by:
I got a similar idea a couple of months ago, but now this one will require no change to the clr, is relatively easy to implement and would be a great addition to C# 3.0 :) so here we go.. To make things simpler and better readable I'd make all default parameters named parameters so that you can decide for yourself which one to pass and which not, rather than relying on massively overlaoded methods which hopefully provide the best...
7
3224
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the bastard so posting it before I forgot again... By taking this minimum code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head>
6
2710
by: Rob Hoelz | last post by:
So these two functions are different: void foo(void); and void foo(); because the first one allows no arguments, but the second does. My question is: In the implementation of the second function, how does
2
12554
ADezii
by: ADezii | last post by:
When a call is made to a Sub or Function Procedure, you can supply Arguments in the exact order they appear in the Procedure's definition, or you can supply them in any position by name. To illustrate this point, I'll use a fictitious Function called fCalculateInterest() which accepts 3 Arguments (Currency, Single, and Long) and returns a value of type Currency. Public Function fCalculateInterest(curPrincipal As Currency, sngRate As Single,...
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4061
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.