Positional Argument Follows Keyword Argument

Positional argument follows keyword argument, not sure how to resolve this

your code look ok you just need to change how you send the part param.

you need a commaseparated string not sevral strings seperated by a comma.

import pandas as pd 
import seaborn as sns

api_key = 'API_KEY'
channel_id = 'CHANNEL_ID'

youtube = build('youtube','v3', developerKey=api_key)

def get_channel_stats (youtube, channel_id):
request = youtube.channels().list(
part='snippet,contentDetails,statistics', id=channel_id)
response = request.execute()
return response

How can I slove SyntaxError: positional argument follows keyword argument

In Python, the order in which we pass (and receive) arguments to a function matters.

Positional arguments come first, variable-length arguments come next, vairable-length keyword arguments come last.

The expected syntax looks like this:

function(arg, *args, **kwargs)

The argument names above are only conventional examples, so a real-world function will look like:

about_user(name, *hobbies, **favorite_foods)

If we call (or receive) with the argument types out of order, we get errors similar to the one you encountered. In your specific case, your keyword arguments are first, when they should be last.

I wrote a small article about *args and **kwargs that has a few more related details and examples.

error positional argument follows keyword argument in snakefile

The problem is with:

rule prokka:
output:
faa = "{sample_id}/annotation/prokka/{sample_id}.faa",
directory("{sample_id}/annotation/prokka/{sample_id}}")

I don't know exactly what snakemake does under the hood but I think it's going to pass the arguments of each directive (input, output, etc) as a dictionary to a function. In python, function arguments without name (positional) must come before those with name. Google positional argument follows keyword argument to learn more.

Long story short: Either change the order of your output files:

rule prokka:
output:
directory("{sample_id}/annotation/prokka/{sample_id}"),
faa = "{sample_id}/annotation/prokka/{sample_id}.faa",

Or give a name to all of them (probably better):

rule prokka:
output:
faa = "{sample_id}/annotation/prokka/{sample_id}.faa",
outdir= directory("{sample_id}/annotation/prokka/{sample_id}"),
...
shell:
"prokka --outdir {output.outdir} --prefix {wildcards.sample_id} ..."

Besides, I think {sample_id}} should be {sample_id}

Syntax Error: positional argument follows keyword argument:

There are two types of arguments: positional and keyword.

If we have the function:

def f(a, b):
return a + b

Then we can call it with positional arguments:

f(4, 4)
# 8

Or keyword arguments:

f(a=4, b=4)
# 8

But not both in the order keyword --> positional, which is what you're doing:

f(a=4, 4)
# SyntaxError: positional argument follows keyword argument
f(4, b=4)
# 8

There's a reason why this is so. Again, imagine we have a similar function:

def f(a, b, *args):
return a + b + sum(args)

How would we know when calling this function what argument is a, what argument is b, and what is for args?



Related Topics



Leave a reply



Submit