Skip to content

Instantly share code, notes, and snippets.

@hktechn0
Created December 11, 2009 16:40
Show Gist options
  • Save hktechn0/254319 to your computer and use it in GitHub Desktop.
Save hktechn0/254319 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
def test1(id, **kwargs):
print id, kwargs
def test2(*args, **kwargs):
print args
print kwargs
def test3(id, name, mail,
phone = None, addr = None):
print id, name
print mail, phone, addr
def test4(id, *args, **kwargs):
print id
print args
print kwargs
if __name__ == "__main__":
testt = ("a", "b", "c")
testd = {
"id" : "hogehoge",
"name" : "abcdefg",
"mail" : "test@example.com",
}
test1(**testd)
test1("foobar", name = "aabbcc")
test2(*testt, **testd)
test3(**testd)
# test4(*testt, **testd) # Error
# test1(id = "ovwrt", **testd) # Error
# Result:
# hogehoge {'mail': 'test@example.com', 'name': 'abcdefg'}
#
# foobar {'name': 'aabbcc'}
#
# ('a', 'b', 'c')
# {'mail': 'test@example.com', 'id': 'hogehoge', 'name': 'abcdefg'}
#
# hogehoge abcdefg
# test@example.com None None
#!/usr/bin/env python
def test1(a, b, c):
print a, b, c
def test2(*args):
print args
if __name__ == "__main__":
test = (1, 2, 3)
test1(*test)
test2(*test)
test2(10, 20, 30, 40)
# Result:
# 1 2 3
# (1, 2, 3)
# (10, 20, 30, 40)
#!/usr/bin/env python
def test1(id, name, mail):
print id, name, mail
def test2(**kwargs):
print kwargs
if __name__ == "__main__":
test = {
"id" : "hogehoge",
"name" : "abcdefg",
"mail" : "test@example.com",
}
test1(**test)
test2(**test)
test2(id = "foobar", name = "hijklmn",
mail = "hoge@example.com")
# Result:
# hogehoge abcdefg test@example.com
# {'mail': 'test@example.com', 'id': 'hogehoge', 'name': 'abcdefg'}
# {'mail': 'hoge@example.com', 'id': 'foobar', 'name': 'hijklmn'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment