How can I get Express to output nicely formatted HTML?

In your main app.js or what is in it’s place: Express 4.x if (app.get(‘env’) === ‘development’) { app.locals.pretty = true; } Express 3.x app.configure(‘development’, function(){ app.use(express.errorHandler()); app.locals.pretty = true; }); Express 2.x app.configure(‘development’, function(){ app.use(express.errorHandler()); app.set(‘view options’, { pretty: true }); }); I put the pretty print in development because you’ll want more efficiency with … Read more

Pretty-Print JSON Data to a File using Python

You should use the optional argument indent. header, output = client.request(twitterRequest, method=”GET”, body=None, headers=None, force_auth_header=True) # now write output to a file twitterDataFile = open(“twitterData.json”, “w”) # magic happens here to make it pretty-printed twitterDataFile.write(simplejson.dumps(simplejson.loads(output), indent=4, sort_keys=True)) twitterDataFile.close()

How do I get python’s pprint to return a string instead of printing?

The pprint module has a function named pformat, for just that purpose. From the documentation: Return the formatted representation of object as a string. indent, width and depth will be passed to the PrettyPrinter constructor as formatting parameters. Example: >>> import pprint >>> people = [ … {“first”: “Brian”, “last”: “Kernighan”}, … {“first”: “Dennis”, “last”: … Read more

Pretty-Print JSON in Java

Google’s GSON can do this in a nice way: Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonParser jp = new JsonParser(); JsonElement je = jp.parse(uglyJsonString); String prettyJsonString = gson.toJson(je); or since it is now recommended to use the static parse method from JsonParser you can also use this instead: Gson gson = new GsonBuilder().setPrettyPrinting().create(); JsonElement je = … Read more

How can I pretty-print JSON using Go?

By pretty-print, I assume you mean indented, like so { “data”: 1234 } rather than {“data”:1234} The easiest way to do this is with MarshalIndent, which will let you specify how you would like it indented via the indent argument. Thus, json.MarshalIndent(data, “”, ” “) will pretty-print using four spaces for indentation.

Pretty-print a NumPy array without scientific notation and with given precision

Use numpy.set_printoptions to set the precision of the output: import numpy as np x = np.random.random(10) print(x) # [ 0.07837821 0.48002108 0.41274116 0.82993414 0.77610352 0.1023732 # 0.51303098 0.4617183 0.33487207 0.71162095] np.set_printoptions(precision=3) print(x) # [ 0.078 0.48 0.413 0.83 0.776 0.102 0.513 0.462 0.335 0.712] And suppress suppresses the use of scientific notation for small numbers: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)