Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Eh, print/log debugging works fine. Especially in an interactive environment: you've got direct access to the variables and objects, and can easily inspect them directly.

At some point I felt like I was a bad dev for not using a debugger, but at this point I think I'm more versatile since I'm less dependent on finicky tooling to figure out what some code is doing... Every language has it's own debugger to learn, but logging (and good strategies for logging) works about the same everywhere.



Debugging nested dicts and high-dim arrays is a nightmare using print


in python you can turn nested dictionaries and other data structures into json, but only if the data structures doesn't include circular references. I use that a lot.

something like

  >>> d = { "a":1, "b":[1,2,3] }
  >>> import json
  >>> print( json.dumps(d, indent=2) )
  {
    "a": 1,
    "b": [
      1,
      2,
      3,
    ]
  }


Try pprint:

  >>> d = { "a":1, "b":[1,2,3] }
  >>> d["d"] = d
  >>> import pprint
  >>> pprint.pprint(d)
  {'a': 1, 'b': [1, 2, 3], 'd': <Recursion on dict with id=4516761856>}


thanks, great!


Try `str`




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: