Web サイトにデータを投稿するための簡単な Python スクリプトを作成しました。
#Imports
url_to_short = sys.argv[1]
post_url = 'https://www.googleapis.com/urlshortener/v1/url'
headers = {'Content-Type': 'application/json'}
data = {'longUrl': url_to_short}
post_data = json.dumps(data)
req = urllib2.Request(post_url, post_data, headers)
resp = urllib2.urlopen(req)
if resp.getcode() == 200:
content = json.loads(resp.read())
#Other stuff
pylint
ここで、ツールを使用してスクリプトのコーディング標準を確認してみましょう。
私のpylint
出力は次のとおりです。
************* Module post
C: 1,0: Missing docstring
C: 6,0: Invalid name "url_to_short" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 8,0: Invalid name "post_url" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 9,0: Invalid name "headers" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
# Other stuff
さて、私の質問はpylint
、変数名が として表示される理由ですInvalid name
。このように変数に名前を付けているのは、間違ったコーディング規則です。