2014-02-07 8 views
0

예상대로 이러한 메서드가 작동하지 않는 이유는 무엇입니까? 메서드를 인쇄 한 직후에 한 줄을 얻을 수 있지만 다른 기능 중 아무 것도 작동하지 않는 것 같습니다.클래스에서 메서드를 호출하는 메서드의 문제

나는 방법 요약을 사용하여 디렉토리

  • 에있는 각 파일에 파일 핸들러를 할당 글로브
  • 를 사용하여 디렉토리에게 파일을 통해
  • 으로 반복을 할당

    1. 에 노력하고있는 다음 통화 서로 부르는 일련의 다른 방법.
    2. 파일 정렬 및 파싱
    3. 정렬 및 구문 분석 결과 인쇄.

    코드 : 그것은 당신이 어떤 클래스 멤버가없는 것을 의미하는 당신의 변수 중 어느 것도 self. 시작 없다는 것을 나에게 이상한 것 같다

    #! /usr/bin/env python3 
    #This utility attempts to parse the output text files generated by dcp_inspect 
    #for faster inspection and when attending to multiple DCP inspections. 
    #dcp_inspect_parse runs on Python3.x 
    import logging 
    import os 
    import re 
    import sys 
    
    from glob import glob 
    
    logging.basicConfig(level=logging.DEBUG) 
    
    class DcpParser: 
        """Parses DCP Inspector output files, and writes summary files to a 
        directory whose path is supplied at construction.""" 
    
    
    
        def parse(self, dir): 
         """Parses all files in the current directory.""" 
         cpl     = [] 
         content    = [] 
         contentkind   = [] 
         container   = [] 
         errors    = [] 
         package    = [] 
         summary    = [] 
         mainsound   = [] 
         mainpicture   = [] 
         encryption   = [] 
         duration    = [] 
         fsp     = [] 
         dimensiontype  = [] 
         aspect    = [] 
         filesize    = [2] 
         audio    = [] 
         cpltype    = [] 
         os.chdir(dir) 
         files = glob('*') 
         logging.debug("Found files: %s", files) 
         for file in files: 
          try: 
           with open(file) as data: 
            logging.debug("Opening file: %s", data) 
            print("Scanning...\t\t\t", file) 
            for each_line in data: 
             #self.prints() 
             self.file_summary() 
             #self.audio() 
    
          except: 
           pass 
    
    
    
        def prints(self): 
    
          print('Container:    \t\t',container.strip())   
          print('CPL Type:    \t\t',cpltype) 
          print('Duration:    \t\t',duration.strip(',')) 
          print('Frame Rate:   \t\t',fps) 
          print('Aspect Ratio:   \t\t',aspect.strip(',')) 
          print('Dimension:    \t\t',dimensiontype.strip(',')) 
          print('Content Title:   \t\t',content.strip(',').strip('""')) 
          print('Audio for DCP:   \t\t', audio) 
          print('Package size:   \t\t',filesize) 
          print('Encryption status:  \t\t',encryption.upper().strip())  
          print('CPL ID:    \t\t', cpl[2]) 
          print('Content Kind:   \t\t',contentkind.upper()) 
          print('\n') 
          print('There are',errors[1],'Errors and',errors[3],'hints for', content.strip(',')) 
          if errors[1] != '0': 
           print('could be issues\n') 
          else: 
           print('This DCP appears to be OK\n')  
    
    
        def file_summary(self): 
         print('made it to summary') 
         self.file_audio() 
         for each_line in data: 
          if 'summary'in each_line: 
           summary.extend(each_line.split()) 
           print(summary.extend(each_line.split())) 
           for x in range(len(summary)): 
            if 'fps' in summary[x]: 
             fps = summary[(x-1)] 
             duration = summary[(x-2)].strip() 
    
            elif 'summary:' in summary[x]: 
             content = summary[(x+1)] 
             content.strip(',') 
    
            elif '2D' in summary[x]: 
             dimensiontype = summary[(x)] 
             aspect = summary[(x+1)].strip(',') 
    
            elif '3D' in summary[x]: 
             dimensiontype = summary[(x)] 
             aspect = summary[(x+1)] 
    
          elif 'Errors' in each_line: 
           errors=(each_line.split()) 
          elif 'Package with total size'in each_line: 
           if 'Bytes 0' in each_line: 
            pass 
           else: 
            temp =[] 
            temp.extend(each_line.split()) 
            filesize=(temp.pop()+' '+temp.pop()) 
    
    
        def file_audio(self): 
         print('made it to audio') 
         self.file_picture() 
         for each_line in data: 
    
          if 'MainSound'in each_line: 
    
           if 'audio' in each_line: 
            m = re.search('([0-9]+)bps', each_line) 
            if m is None: 
             bps = 'bps error' 
            else: 
             bps = int(m.group(1)) 
    
            m = re.search('([0-9]+)ch', each_line) 
            if m is None: 
             channels = 'channel error' 
            else: 
             channels = int(m.group(1)) 
    
            m = re.search('([0-9]+)kHz', each_line) 
            if m is None: 
             bandwidth = 'bandwidth error' 
            else: 
             bandwidth = int(m.group(1)) 
    
            audio = '%ich %ikHz %ibps' % (channels, bandwidth, bps) 
    
    
        def file_picture(self): 
         print('made it to picture') 
         for each_line in data: 
    
          if 'MainPicture'in each_line: 
           if 'pictures' in each_line: 
            temp = [] 
            temp.extend(each_line.split(',')) 
            container = temp[-2] 
            encryption= temp[-3] 
    
    
    
    
        def file_cplId(self): 
         print('cpl id') 
         if 'CPL Id:'in each_line: 
          cpl=(each_line.split()) 
    
    
        def file_cplType(self): 
         if 'CPL type: 'in each_line: 
          cpltype=(each_line.split()) 
          cpltype = cpltype[2] 
    
        def file_contentKind(self): 
         if 'ContentKind: 'in each_line: 
          contentkind=(each_line.split()) 
          contentkind = contentkind[1] 
    
        def file_contentTitleText(self): 
         if 'ContentTitleText:'in each_line: 
          content=(each_line.split(':')) 
          content = content[1] 
    
    
    
    
    
    
    
    
    
    
    if __name__ == '__main__': 
        print("Input directory name: " + os.getcwd()) 
        default_dir = os.getenv('HOME') + '/Desktop/dcp_output' 
        prompt = "Please enter the output directory name [" + default_dir + "]: " 
        dir = input(prompt) or default_dir 
        print("Output directory name: " + dir) 
    
        parser = DcpParser() 
    
        parser.parse(dir) 
    
  • +2

    조금만 좁힐 수있는 기회가 있으십니까? http://sscce.org – jonrsharpe

    +2

    을 읽으십시오. "왜 이러한 방법이 예상대로 작동하지 않습니까?" 당신은 당신이 무엇을 기대하고 실제로 무엇이 일어나는지 설명해 주시겠습니까? – SethMMorton

    답변

    2

    , 모든 변수는 각각의 방법에서 지역입니다.

    또한 편리하게도 코드의 주요 부분에서 try except pass을 사용 했으므로 오류가 발생해도 무시됩니다. 이러한 오류 중 하나는 전역 변수가 아니며 이전에 메서드에 할당 된 여러 메서드에서 data에 액세스하는 것입니다.

    디버그 목적으로 try except pass을 제거하고 어떤 일이 발생했는지보고하십시오.

    +0

    네 말이 맞아. 데이터가 나를 슬프게합니다. 데이터를 선언해야합니까? – inbinder

    +0

    @ user1124541 클래스 멤버이어야한다고 생각합니다.이 경우'data' 대신에'self.data'를 사용해야합니다. – Nabla

    +0

    클래스 멤버를 모든 함수/메서드에서 액세스 할 수있게하려면 어떻게해야합니까? – inbinder

    관련 문제