Knowledgebase

Working With Data: Everything That Matters, Briefly Print

  • python, database, performance, guide, howto, solution, zillionkinghost, hosting
  • 0

The summary.

ALWAYS SPECIFY THE ENCODING WHEN OPENING FILES

Defaults differ between systems, producing failures that appear only elsewhere.

And opening a file for writing destroys its contents immediately — be certain which mode you intend.

BUILD PATHS RELATIVE TO THE SCRIPT, NOT THE CURRENT DIRECTORY

Otherwise the script works from its own folder and fails from anywhere else.

Never use a path supplied from outside without validating it.

DO NOT PARSE CSV YOURSELF

Values containing commas, quotes or line breaks break naive splitting. Use the library.

Watch for reference codes with leading zeros, which get destroyed if treated as numbers.

THE ABSOLUTE DATABASE RULE

Never build a query by joining strings containing user input. Use parameterised queries, without exception.

FOR API CALLS

Always set a timeout. Without one a request can hang indefinitely and stop your program.

Check the status before using the response, and keep keys out of the code.

FOR DATES

Be explicit about time zones and parsing formats. Never rely on guessing the format.

FOR LARGE DATA

Process in a stream rather than loading everything. Measure before optimising — the cause is rarely where people guess.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot