當前位置: 首頁>>代碼示例>>Python>>正文


Python pprint.pprint方法代碼示例

本文整理匯總了Python中pprint.pprint方法的典型用法代碼示例。如果您正苦於以下問題:Python pprint.pprint方法的具體用法?Python pprint.pprint怎麽用?Python pprint.pprint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pprint的用法示例。


在下文中一共展示了pprint.pprint方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def main():
    global output_file
    num_args = len(sys.argv)
    if num_args < 3:
        print("usage: %s <json-file-1> [json-file-2 ...] <output-csv-file>" % sys.argv[0], file=sys.stderr)
        exit(1)

    json_files = sys.argv[1:num_args - 1]
    output_file = sys.argv[num_args - 1]

    merged_json_data = {}
    for json_file in json_files:
        print("> reading JSON file '%s'..." % json_file)
        with open(json_file) as f:
            json_data = json.load(f)
            for label, data in json_data.items():
                if label not in merged_json_data:
                    merged_json_data[label] = data
                else:
                    merged_json_data[label]['data'].extend(data['data'])

    # pprint(merged_json_data)
    analyse(merged_json_data) 
開發者ID:internaut,項目名稱:facebook-discussion-tk,代碼行數:25,代碼來源:analyze_noun_counts.py

示例2: import_daily_schedule

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def import_daily_schedule(self):

        """Dropping previous Daily Schedule table before adding the imported data"""
        self.db.remove_all_daily_scheduled_items()
        with open('pseudo-daily_schedule.json') as data_file:    
            data = json.load(data_file)
        #pprint(data)
        for row in data:
            """print row"""
            self.db.import_daily_schedule_table_by_row(
                row[2], 
                row[3], 
                row[4], 
                row[5], 
                row[6], 
                row[7], 
                row[8], 
                row[9], 
                row[10], 
                row[11], 
                row[12],
                row[13],
            )
        print "+++++ Done. Imported Daily Schedule." 
開發者ID:justinemter,項目名稱:pseudo-channel,代碼行數:26,代碼來源:PseudoChannel.py

示例3: pos_pyscf

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def pos_pyscf ():
    '''converts ase position lists to a long string which is readable for Pyscf'''
    import re        
    import pprint
    for k in sorted (data.keys()):
            nn=sum(1 for c in data[k]['symbols'] if c.isupper()) #number of atoms
            a=re.findall('[A-Z][^A-Z]*', data[k]['symbols']) #atom index e.g. a=['H','Al','Cl']
            num=[]        
            for i in range(len(data[k]['positions'])):
                pos= (str(data[k]['positions'][i]).strip('[]'))
                pos = a[i]+' '+pos
                if (i!= (len(data[k]['positions'])-1)): pos=pos+';'
                num.append(pos)
            pos_py=" " .join(map(str,num))
            data[k]['position_pyscf']=pos_py
    pprint.pprint(data) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:18,代碼來源:m_g297.py

示例4: train

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def train(config):
    c = Classifier.classifier(config)
    pprint.pprint(c.tuples.all_tuples)
    print('All tuples:',len(c.tuples.all_tuples))
    model_path = config.get("train", "output")
    model_dir = os.path.dirname(model_path)
    if not os.path.exists(model_dir):
        os.makedirs(model_dir)
    print('output to {}'.format(model_path))
    dataroot = config.get("train", "dataroot")
    dataset = config.get("train", "dataset")
    dw = sutils.dataset_walker(dataset = dataset, dataroot=dataroot, labels=True)
    c = Classifier.classifier(config)
    c.cacheFeature(dw)
    c.train(dw)
    c.save(model_path)
    with zipfile.ZipFile(os.path.join(model_dir, 'svm_multiwoz.zip'), 'w', zipfile.ZIP_DEFLATED) as zf:
        zf.write(model_path) 
開發者ID:ConvLab,項目名稱:ConvLab,代碼行數:20,代碼來源:train.py

示例5: parse

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def parse(self, utterance, context=[]):
        """
        Predict the dialog act of a natural language utterance and apply error model.
        Args:
            utterance (str): A natural language utterance.
        Returns:
            output (dict): The dialog act of utterance.
        """
        # print("nlu input:")
        # pprint(utterance)

        if len(utterance) == 0:
            return {}

        tokens = self.tokenizer.split_words(utterance)
        instance = self.dataset_reader.text_to_instance(tokens)
        outputs = self.model.forward_on_instance(instance)

        return outputs["dialog_act"] 
開發者ID:ConvLab,項目名稱:ConvLab,代碼行數:21,代碼來源:nlu.py

示例6: mark_not_mentioned

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def mark_not_mentioned(state):
    for domain in state:
        # if domain == 'history':
        if domain not in ['police', 'hospital', 'taxi', 'train', 'attraction', 'restaurant', 'hotel']:
            continue
        try:
            # if len([s for s in state[domain]['semi'] if s != 'book' and state[domain]['semi'][s] != '']) > 0:
                # for s in state[domain]['semi']:
                #     if s != 'book' and state[domain]['semi'][s] == '':
                #         state[domain]['semi'][s] = 'not mentioned'
            for s in state[domain]['semi']:
                if state[domain]['semi'][s] == '':
                    state[domain]['semi'][s] = 'not mentioned'
        except Exception as e:
            # print(str(e))
            # pprint(state[domain])
            pass 
開發者ID:ConvLab,項目名稱:ConvLab,代碼行數:19,代碼來源:policy.py

示例7: test_status_update

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def test_status_update(self, path1):
        # not a mark because the global "pytestmark" will end up overwriting a mark here
        pytest.xfail("svn-1.7 has buggy 'status --xml' output")
        r = path1
        try:
            r.update(rev=1)
            s = r.status(updates=1, rec=1)
            # Comparing just the file names, because paths are unpredictable
            # on Windows. (long vs. 8.3 paths)
            import pprint
            pprint.pprint(s.allpath())
            assert r.join('anotherfile').basename in [item.basename for
                                                    item in s.update_available]
            #assert len(s.update_available) == 1
        finally:
            r.update() 
開發者ID:pytest-dev,項目名稱:py,代碼行數:18,代碼來源:test_svnwc.py

示例8: _get_pretty_string

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def _get_pretty_string(obj):
    """Return a prettier version of obj

    Parameters
    ----------
    obj : object
        Object to pretty print

    Returns
    -------
    s : str
        Pretty print object repr
    """
    sio = StringIO()
    pprint.pprint(obj, stream=sio)
    return sio.getvalue() 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:18,代碼來源:scope.py

示例9: get_named_entities

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def get_named_entities(en_doc):
    prop_noun_entities = {}
    prop_noun_entities_pos = {}
    payload = {}
    i = 0
    for ent in en_doc.ents:
        prop_noun_entities_pos[ent.text] = ent.start
        if i < 10:
            payload["name["+str(i)+"]"] = ent.text
            print(ent.label_, ent.text)
        if i == 9:
            prop_noun_entities = get_gender(payload, prop_noun_entities)
            i = 0
        i += 1
    pprint(payload)
    if i < 10:
        prop_noun_entities = get_gender(payload, prop_noun_entities)
    return prop_noun_entities, prop_noun_entities_pos 
開發者ID:5hirish,項目名稱:adam_qas,代碼行數:20,代碼來源:anaphora_res.py

示例10: get_daily_schedule_cache_as_json

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def get_daily_schedule_cache_as_json(self):

        data = []
        try:
            with open('../.pseudo-cache/daily-schedule.json') as data_file:    
                data = json.load(data_file)
            #pprint(data)
        except IOError:
            print ("----- Having issues opening the pseudo-cache file.")
        return data 
開發者ID:justinemter,項目名稱:pseudo-channel,代碼行數:12,代碼來源:PseudoChannel.py

示例11: demo

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def demo():
    from en.parser.nltk_lite.corpora import ieer
    from itertools import islice
    from pprint import pprint

#    pprint(extract(75, ieer.raw()))
    pprint(extract(75, ieer.dictionary())) 
開發者ID:rafasashi,項目名稱:razzy-spinner,代碼行數:9,代碼來源:ieer.py

示例12: addBookingPointer

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def addBookingPointer(state, pointer_vector):
    """Add information about availability of the booking option."""
    # Booking pointer
    rest_vec = np.array([1, 0])
    if "book" in state['restaurant']:
        if "booked" in state['restaurant']['book']:
            if state['restaurant']['book']["booked"]:
                if "reference" in state['restaurant']['book']["booked"][0]:
                    rest_vec = np.array([0, 1])

    hotel_vec = np.array([1, 0])
    if "book" in state['hotel']:
        if "booked" in state['hotel']['book']:
            if state['hotel']['book']["booked"]:
                if "reference" in state['hotel']['book']["booked"][0]:
                    hotel_vec = np.array([0, 1])

    train_vec = np.array([1, 0])
    if "book" in state['train']:
        if "booked" in state['train']['book']:
            if state['train']['book']["booked"]:
                if "reference" in state['train']['book']["booked"][0]:
                    train_vec = np.array([0, 1])

    pointer_vector = np.append(pointer_vector, rest_vec)
    pointer_vector = np.append(pointer_vector, hotel_vec)
    pointer_vector = np.append(pointer_vector, train_vec)

    # pprint(pointer_vector)
    return pointer_vector 
開發者ID:ConvLab,項目名稱:ConvLab,代碼行數:32,代碼來源:policy.py

示例13: _get_num_items

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def _get_num_items(self):
        num_items = 0
        goal = self.state
        for domain in goal:
            if domain == 'domain_ordering':
                continue
            if 'info' in goal[domain]:
                num_items += len(goal[domain]['info'])
            if 'reqt' in goal[domain]:
                num_items += len(goal[domain]['reqt'])
            if 'book' in goal[domain]:
                num_items += len(goal[domain]['book'])
        pprint(goal)
        print("Num of remaining items:", num_items)
        return num_items 
開發者ID:ConvLab,項目名稱:ConvLab,代碼行數:17,代碼來源:worlds.py

示例14: test_repo

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def test_repo():
    r = requests.get(
        "http://localhost:5000/repos?keyword=natural+language+processing"
    )
    pprint.pprint(r.json()) 
開發者ID:prkumar,項目名稱:uplink,代碼行數:7,代碼來源:Tests.py

示例15: test_users_for_repos

# 需要導入模塊: import pprint [as 別名]
# 或者: from pprint import pprint [as 別名]
def test_users_for_repos():
    r = requests.get(
        "http://localhost:5000/users/JustFollowUs/repo/Natural-Language-Processing"
    )
    pprint.pprint(r.json()) 
開發者ID:prkumar,項目名稱:uplink,代碼行數:7,代碼來源:Tests.py


注:本文中的pprint.pprint方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。