2016-08-26 6 views
0

특정 정보를 Google 문서 도구에 업로드하려면 회사의 Jira 인스턴스의 RESTful API를 쿼리하기 위해 Python으로 스크립트를 작성했습니다. 틀림없이, 나는 전문 프로그래머가 아니며 여전히 아마추어이다. 어떻게이 코드를 정리하고 Pythonic과 우아한 만들 수 있습니까?이 파이썬 코드를 더 좋게/좀 더 우아하게 만들 수 있습니까?

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/. 그들은 사람들의 ** working ** 코드를 받아 들여 그것을 향상시킬 수 있습니다. 나는 그곳으로 옮길 것을 제안한다. –

+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]) 

미안 코드를 정리하기 위해 루프를 사용하고 절약 할 수있다. :/

+0

좋은 제안이지만,이 유형의 질문은 실제로 여기에 속하지 않으므로 혼자있게해야합니다. –