Created
December 11, 2009 16:40
-
-
Save hktechn0/254319 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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