setup(**config); rookie

C

cate

I going thru a 101 and came upon this (http://
learnpythonthehardway.org/book/ex46.html)

try:
from setuptools import setup
except ImportError:
from distutils.core import setup

config = {
'description': 'My Project',
'author': 'My Name',
'url': 'URL to get it at.',
'download_url': 'Where to download it.',
'author_email': 'My email.',
'version': '0.1',
'install_requires': ['nose'],
'packages': ['NAME'],
'scripts': [],
'name': 'projectname'
}

setup(**config)

What is the construct **?

Thank you
 
R

Roy Smith

cate said:
I going thru a 101 and came upon this (http://
learnpythonthehardway.org/book/ex46.html)

try:
from setuptools import setup
except ImportError:
from distutils.core import setup

config = {
'description': 'My Project',
'author': 'My Name',
'url': 'URL to get it at.',
'download_url': 'Where to download it.',
'author_email': 'My email.',
'version': '0.1',
'install_requires': ['nose'],
'packages': ['NAME'],
'scripts': [],
'name': 'projectname'
}

setup(**config)

What is the construct **?

Thank you

It calls setup with all the elements of config as if they had been
passed as discrete arguments.

def x(foo, bar):
print foo
print bar

args = {'foo': 1,
'bar': 2,
}

x(**args)
 
S

Steven D'Aprano

setup(**config)

What is the construct **?


It expands the dict "config" into keyword arguments. A single * expands
to positional arguments.

A simple example:

args = [1, 2, 3]
kwargs = {'x': 4, 'y': 5}

somefunc(*args, **kwargs)

is expanded to

somefunc(1, 2, 3, x=4, y=5)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,779
Messages
2,569,606
Members
45,239
Latest member
Alex Young

Latest Threads

Top