2016-08-26 11 views
0

PythonでGoogleのJiraインスタンスのRESTful APIをクエリして特定の情報をGoogle Docにアップロードするスクリプトを作成しました。確かに、私はプロのプログラマーではなく、まだまだアマチュアです。どのように私はこのコードをきれいにしてPythonicとエレガントにすることができますか?このPythonコードをより良く/よりエレガントにする方法を教えてください。

cell = 2 

for issue in issues: 
    title = issue.fields.customfield_xxxx 
    first_name = issue.fields.customfield_xxxx 
    last_name = issue.fields.customfield_xxxx 
    email = issue.fields.customfield_xxxx 
    username = first_name[0] + last_name 
    wks.update_acell('A{}'.format(cell), '{}'.format(first_name)) 
    wks.update_acell('B{}'.format(cell), '{}'.format(last_name)) 
    wks.update_acell('C{}'.format(cell), '{}'.format(title)) 
    wks.update_acell('I{}'.format(cell), '{}'.format(email)) 
    wks.update_acell('E{}'.format(cell), '{}'.format(
     username + "@company.com")) 
    wks.update_acell('F{}'.format(cell), '{}'.format(username)) 
    wks.update_acell('H{}'.format(cell), '{}'.format(
     first_name + " " + last_name)) 
    wks.update_acell('G{}'.format(cell), '{}'.format(
     first_name + " " + last_name)) 
    wks.update_acell('J{}'.format(cell), '{}'.format(x)) 

cell += 1 
+3

この質問は、おそらくコードビューでもっとうまくいくでしょう:http://codereview.stackexchange.com/。彼らは人々の**作業**コードを受け入れ、あなたの改善に役立てることができます。私はそこに移動することをお勧めします。 –

+0

素晴らしいアイデア。ありがとうございました! – mpoggy

+0

あなたは非常に歓迎しています:)私は貴重なレビューサービスを見つけました。 –

答えて

3

手始めに、あなたが悪いの変数の命名のためにいくつかの入力

cellfields = [['a',first_name],['b',last_name]['c',title]] ... etc 
    for fields in cellfields: 
     wks.update_acell(fields[0] + str(cell), fields[1]) 

申し訳ありませんが、あなたのコードをクリーンアップするためにforループを使用し、救うことができます。 :/

+0

良い提案ですが、このタイプの質問は本当にここに属していないので、それらは一人で放置されるべきです。 –

関連する問題