Skip to content
Advertisement

Tag: arguments

Python function that takes one compulsory argument from two choices

I have a function: However, my intention is for the function to take only one argument (either title OR pageid). For example, delete(title=”MyPage”) or delete(pageid=53342) are valid, while delete(title=”MyPage”, pageid=53342), is not. Zero arguments can not be passed. How would I go about doing this? Answer There is no Python syntax that’ll let you define exclusive-or arguments, no. You’d have

Disable/Remove argument in argparse

Is it possible to remove or disable an argument in argparse, such that it does not show in the help? How? It is easy to add new arguments: And I know you can override arguments with a new definition by specifying the “resolve” conflict handler: But this still includes arg1 in the help message and results of parse_args Is there

Python :TypeError: this constructor takes no arguments

When the user enters an email address, and the program reads the email and display it according to its criteria (e.g yeo.myy@edu.co), like criteria: username is yeo.myy domain is edu.co I know its something to do with the “@”. this is the code this is the error I got: Answer Did you mean __init__? You’re also missing a couple selfs

format strings and named arguments in Python

Case 1: It will give KeyError: ‘arg1′ because I didn’t pass the named arguments. Case 2: Now it will work properly because I passed the named arguments. And it prints ’10 20’ Case 3: And, If I pass wrong name it will show KeyError: ‘arg1’ But, Case 4: If I pass the named arguments in wrong order It works… and

Getting HTTP GET arguments in Python

I’m trying to run an Icecast stream using a simple Python script to pick a random song from the list of songs on the server. I’m looking to add a voting/request interface, and my host allows use of python to serve webpages through CGI. However, I’m getting hung up on just how to get the GET arguments supplied by the

How to pass elements of a list as arguments to a function?

I’m building a simple interpreter in python and I’m having trouble handling differing numbers of arguments to my functions. My current method is to get a list of the commands/arguments as follows. Then to execute com, I check to see if it is in my dictionary of command-> code mappings and if it is I call the function I have

Advertisement