What's the Pythonic way to store a data block in a Python script?

前端 未结 4 1427
孤街浪徒
孤街浪徒 2021-01-01 20:20

Perl allows me to use the __DATA__ token in a script to mark the start of a data block. I can read the data using the DATA filehandle. What\'s the Pythonic wa

4条回答
  •  梦谈多话
    2021-01-01 20:37

    It depends on your data, but dict literals and multi-line strings are both really good ways.

    state_abbr = {
        'MA': 'Massachusetts',
        'MI': 'Michigan',
        'MS': 'Mississippi',
        'MN': 'Minnesota',
        'MO': 'Missouri',
        }
    
    gettysburg = """
    Four score and seven years ago,
    our fathers brought forth on this continent
    a new nation, 
    conceived in liberty
    and dedicated to the proposition
    that all men are created equal.
    """
    

提交回复
热议问题