Last active
April 2, 2018 11:58
-
-
Save naokisekiguchi/3acfa2a1f747cbe07e47477f3350b781 to your computer and use it in GitHub Desktop.
Node.jsユーザーのためのpython事始め ref: https://qiita.com/naokisekiguchi@github/items/d7f764b0214b5b0d6bb5
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
python test.py -v |
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
def print_dict(): | |
''' print_dict test | |
>>> print_dict() | |
<class 'dict'> | |
1 | |
2 | |
{'hoge': 1, 'fuga': 2} | |
''' | |
dict = {'hoge':1,'fuga':2} | |
print(type(dict)) | |
print(dict['hoge']) | |
print(dict['fuga']) | |
print(dict) |
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
import json | |
def print_json(): | |
''' print_json test | |
>>> print_json() | |
<class 'dict'> | |
{'hoge': 1, 'fuga': 2} | |
''' | |
json_file = open('config.json','r') | |
json_dict = json.load(json_file) | |
print(type(json_dict)) | |
print(json_dict) |
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
import requests | |
requests.get(url) |
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
import requests | |
import json | |
url = 'http://...' | |
headers = {'Content-Type':'text/plain'} | |
jsonData = {'hoge':'fuga'} | |
requests.post( | |
url, | |
headers=headers, | |
data=json.dumps(jsonData), | |
auth=(user,passwd) | |
) |
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
from mymodule import Mymodule | |
mymodule = Mymodule('fuga') | |
mymodule.print_hoge() | |
#fuga が出力される |
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
class Mymodule(object): | |
def __init__(self, hoge): | |
self.hoge = hoge | |
def print_hoge(self): | |
print(self.hoge) |
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
import doctest | |
def hoge(): | |
'''hoge function test | |
>>> hoge() | |
'hote' | |
''' | |
return 'hoge' | |
if __name__ == "__main__": | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment