Python — How do you view output that doesn't fit the screen?

前端 未结 9 1845
挽巷
挽巷 2021-02-05 10:27

I should say I\'m looking for a solution to the problem of viewing output that does not fit on your screen. For example, range(100) will show the last 30ish lin

9条回答
  •  面向向阳花
    2021-02-05 11:06

    if your data is json serilizable then you can try

    import simplejson
    print simplejson.dumps({'shipping-line': {'price': '0.00', 'code': 'Local Pickup (Portland, OR)', 'title': 'Local Pickup (Portland, OR)'}}, indent=4)
    

    Output will be look something like

    {
        "shipping-line": {
            "price": "0.00", 
            "code": "Local Pickup (Portland, OR)", 
            "title": "Local Pickup (Portland, OR)"
        }
    }
    

    this is specifically used to debug and to see the actual content......in well readble format..

    EDIT:

    if your screen is limited to 25 lines..........

    import simplejson
    data = simplejson.dumps({'shipping-line': {'price': '0.00', 'code': 'Local Pickup (Portland, OR)', 'title': 'Local Pickup (Portland, OR)'}}, indent=4)
    
    cnt = 0
    
    for line in data.split('\n'):
        cnt+=1
        print line
        raw_input() if cnt%25==0 else None
    

提交回复
热议问题