惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cloudbric
Cloudbric
T
Threat Research - Cisco Blogs
Simon Willison's Weblog
Simon Willison's Weblog
AWS News Blog
AWS News Blog
P
Privacy & Cybersecurity Law Blog
H
Help Net Security
云风的 BLOG
云风的 BLOG
G
GRAHAM CLULEY
Spread Privacy
Spread Privacy
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
A
Arctic Wolf
Project Zero
Project Zero
Engineering at Meta
Engineering at Meta
P
Privacy International News Feed
Blog — PlanetScale
Blog — PlanetScale
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence
The Register - Security
The Register - Security
Recorded Future
Recorded Future
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
PCI Perspectives
PCI Perspectives
Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
A
About on SuperTechFans
W
WeLiveSecurity
GbyAI
GbyAI
V
Vulnerabilities – Threatpost
The GitHub Blog
The GitHub Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Check Point Blog
Y
Y Combinator Blog
月光博客
月光博客
Scott Helme
Scott Helme
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
U
Unit 42
G
Google Developers Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Threatpost
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google Online Security Blog
Google Online Security Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Cisco Talos Blog
Cisco Talos Blog
博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 司徒正美

Chip Cullen

The need for importance, and AI: Chip Cullen An updated Colorosetta: Chip Cullen The Return of the Font Combinator!: Chip Cullen Changing the number of an item in an ordered list: Chip Cullen My pizza dough recipe as of May 2025: Chip Cullen Gonna try to be a bit more personal: Chip Cullen How I built dynamic social media images in Eleventy using Cloudinary: Chip Cullen My current approach to AI : Chip Cullen Lessons Learned Surviving a Major Product Launch: Chip Cullen How to Build a Drop Down Menu with Modern CSS: Chip Cullen How to stop page scrolling when you have an open dialog element: Chip Cullen Distraction Driven Development: Chip Cullen How I learned to code: the art of letting go: Chip Cullen In praise of the switch statement: Chip Cullen Project stuck? Think about how you’re breaking it down & question everything: Chip Cullen So how did the onboarding experiment go?: Chip Cullen Ideas for an Onboarding Checklist: Chip Cullen I really like Post Mortems: Chip Cullen Raise Red Flags Early: Chip Cullen How to mock fetch requests in React Testing Librarty tests: Chip Cullen Running a Structured Meeting: Chip Cullen Adding the View Transitions API to my personal site: Chip Cullen A Lightweight Way to Read GraphQL Data: Chip Cullen How to make a color changing favicon: Chip Cullen Using a Pros/Cons list to help navigate technical discussions: Chip Cullen How to use variable fonts from Google Fonts: Chip Cullen A new website: now on Eleventy!: Chip Cullen How to Truncate Type at More Than One Line with Just CSS: Chip Cullen Colorosetta: the VS Code Extension!: Chip Cullen Using CSS Custom Properties and Logical Properties Together: Chip Cullen Browser Dev Tools: Element Inspector Popover: Chip Cullen The Link with rel=preload is a Seperate Thing: Chip Cullen How to have Dark & Light Mode Images that also works with User Choice: Chip Cullen Don’t use Viewport Units for Font Size on their own: Chip Cullen A little known Media Query: Aspect Ratio: Chip Cullen Meta thinking: Managing Decisions: Chip Cullen Give Your To-Do's Context: Chip Cullen Say What the Impact is when Reporting Issues: Chip Cullen Firefighting 101: How to Manage Breakages: Chip Cullen How to Deal With Large Pieces of Technical Debt: Chip Cullen Make Your Request Clear: Chip Cullen Analytics events, HTML classes, and protecting against refactoring: Chip Cullen How We Removed jQuery from a large app: Chip Cullen New tool: ColoRosetta: Chip Cullen What width and height attributes should you use with responsive images?: Chip Cullen Django 3.1 gotcha: Referrer Policy has a new default, and it might break iframes and links: Chip Cullen A Javascript Component Pattern: Chip Cullen CSS min(), max() and clamp() Functions: Chip Cullen Pointer Events and Inline Elements in Chrome: Chip Cullen Resolving a github repo and a new Create React App: Chip Cullen How to POST *Data* with the Fetch API: Chip Cullen The Contrast Triangle: Chip Cullen Advice on interviewing for Junior Developers: Chip Cullen Life Lessons Learned From Running a Marathon: How to do something really hard: Chip Cullen A (Brief) intro to Search Engine Structured Data: Chip Cullen Javascript Fallback Values on Variables and Booleans - a hard lesson: Chip Cullen Alfred Tip: Quickly Access Common URLs: Chip Cullen Responsive Images in Hugo - by Laura Kalbag: Chip Cullen Making a Gatsby Site with Multiple Content Types: Chip Cullen How to Create and Use Fixtures in Cypress Tests: Chip Cullen Fixing the 'Bad Interpreter' Error from AWS and Python 3.7: Chip Cullen Creating a Canonical Tag in a Django Template: Chip Cullen Responsive spacing with viewport and ch units: Chip Cullen Welcome to my New Design - 2019: Chip Cullen Django Templates: Block and If statements don’t work like you might expect: Chip Cullen Books I Read in 2018: Chip Cullen Lifehack: 4 ways to help tame common email noise: Chip Cullen How to make better Pull Requests: Adding Steps to Test: Chip Cullen The unsung develpment tool: Spreadsheets: Chip Cullen Troubleshooting Adding and Removing EventListeners: with Arguments, Debounced, and in a React Class: Chip Cullen How to Fake the Window Object in Jest and Enzyme: Chip Cullen Migrating From Wordpress to Hugo: Chip Cullen Background Repeat and its Possibilities: Chip Cullen Getting Started With Front End Tests: a Mindset: Chip Cullen Migrating a Blog - An Opportunity for a Content Inventory: Chip Cullen Moving to Hugo: Chip Cullen JavaScript events: .target vs .currentTarget: Chip Cullen Leading Ampersands for modifiers in Sass: An anti-pattern: Chip Cullen How to get rid of the "You have mail" message in your terminal: Chip Cullen Why three typefaces rule the web, and what you can do about it: Chip Cullen You shouldn't worry about Section 508 - it's Section 504: Chip Cullen Looping Video Backgrounds: pointers and pitfalls: Chip Cullen How to “preview” a click event tag in the Google Tag Manager console: Chip Cullen Moving on from a technology, or: life after Drupal: Chip Cullen Don’t be a dumb developer: Chip Cullen Two level breadcrumbs with CSS :only-child: Chip Cullen Simplicity comes with experience: Chip Cullen Do the least amount possible: Chip Cullen SVGs vs. Icon Fonts: Two points in favor of Icon Fonts: Chip Cullen Accessible links without underlines: Chip Cullen The Strategic Job Hunt: Chip Cullen Surviving Getting Laid Off: Chip Cullen How to structure your typography in Sass: Chip Cullen Layer Cake: A Responsive Design Layout Pattern: Chip Cullen Creativity is yet to come in Web Design: Chip Cullen Front End Testing with Wraith: A Step by Step Recipe: Chip Cullen Where to begin? How I start a visual design for the web: Chip Cullen If you could only have five Google Fonts: Chip Cullen Why SVG is so cool (or: what happens when you're late to the party on something): Chip Cullen How to apply classes to elements with CKEditor 4, in Drupal 7: Chip Cullen
Things I wish I knew when starting with Python: Chip Cullen
2018-04-13 · via Chip Cullen

Last year, after getting a promotion, I found myself suddenly in charge of a lot more back end python code. As someone who had almost exclusively worked in the front end (except for some PHP when dealing with Drupal or WordPress) this was new territory for me.

I’ve decided to jot down a few things that I’ve learned that I hope will help folks in a similar position. This is by no means for anyone with even intermediate python knowledge. I’m sure a lot of this will seem super obvious to a lot of folks.

But, if you’re like me and have spent most of your time in the front end, I hope this will orient you a bit.

Living interpreter

One of the first things that was disorienting to me was that in Python, you can have a terminal window open, running a script, and it is actually a living interpreter. That is you can actually interact with your script and make real changes.

The python interpreter

This is quite a bit different from a browser console, where you typically only read data; or if you do interact with it, it’s in a temporary way.

White space means something

If you’ve worked in the front end for years, you’re very conditioned to not worry about white space when it comes to the functionality of your code.

Well, in Python white space means something.

White space is how block level is determined. Getting it wrong is actually a syntax error that can cause your script to break.

def functionOuter():
    return True

    def functionInner():
    return True # will break your script

While I’m sure this is laughingly obvious to anyone who has written Python for more than an hour, it’s truly strange for a front ender.

Named arguments

One of things that I love about Python is that functions can have named arguments. That means your calling function can pass only the arguments that are relevant, and in an intuitive way:

def functionWithNamedParams(
    param1,
    param2,
    param3=default
):
    # does stuff
...
def callingFunction():
    return functionWithNamedParams(
        param1='foo',
        param2='bar')
        # the third parameter doesn't need to be specified

Note that param3 has a "default parameter value" - which is a fallback in case it’s not specified. You can read more about it here.

Breakpoints

Something I found myself needing in very short order was a way to stop a long, complex script so I could get in there and figure out what was happening at a given step.

Coming from a JavaScript background I was happy to find out that you can insert breakpoints and take a look around.

I usually throw this in at the point I want to break:

import pdb; pdb.set_trace()

Which will import pdb - the Python Debugger, then enter the debugger at that point in your code.

Want to inspect the state of a variable (let's say it's called foo) at that point? In your shell, enter

pp(foo)

when you've hit the breakpoint. This will “pretty print” foo - which is especially handy if foo is a long object of some kind.

If you have control over the python packages you install, there is a nicer version of pdb called ipdb.

If, else and conditions ending with colons

I don't know why, but this syntatical difference took me a while to get used to:

if condition == true:
     # do stuff
else:
     # do other stuff

I keep wanting to put in brackets, but no, it's colons. But, I get it. However, there is one thing I do not get …

Elif

One of the things that I absolutely loathe about Python is this syntactical detail - when writing an else if statement, you write it as elif.

if condition == true:
     # do stuff
elif other_condition == true:
     # do other stuff
else:
     # do other other stuff

Which is different from pretty much every other language that I’ve experienced, anyway.

I’m not sure why it gets stuck in my craw so much. I’ve been told that there is a reason for it.

I just think it’s stupid - it’s unintuitive and hard to remember if you’re jumping between languages a lot. Is else if really so hard?

Objects vs Arrays :: Dictionaries vs Lists

Data is stored in a few different ways in Python, among the most commonly used are:

Dictionaries

Dictionaries are most easily equatable with JavaScript objects, for the simple fact that they have key/value pairs:

iAmADictionary = {
    key: 'value',
    otherKey: 'otherValue',
    nestedDictionary: {
        nestedKey: 'nestedValue',
    },
    hereIsAList: [0, 1, 2, 3],
}

Note the last line in a dictionary can have a trailing comma , which is different from JSON / JavaScript objects.

Another thing to note about dictionaries is that Python did not maintain their order prior to version 3.6. Before that version, keys/values can get returned in any order.

Lists

Lists, on the other hand, are closer to what we think of as Arrays in JavaScript:

iAmAList = [0, 1, 2, 'three']

Lists will maintain their order, and can use mixed data types.

There are actual things called "arrays" in Python, but they are something else, and have a very specific use-case. For the vast majority of the time, you’re never going to have to deal with them - you’ll be dealing with lists.

Getting something by key

You can get at information in an obje... I mean dictionary in a couple different ways. This will look familiar to JS folks (using our dictionary from earlier):

iAmADictionary['nestedDictionary']['nestedKey']
# returns 'nestedValue'

The one drawback here is that if any of the keys don't exist for some reason, you will raise a KeyError.

This is also a way to get data in a dictionary:

iAmADictionary.get('nestedDictionary', {}).get('nestedKey', 'someDefaultValue')
# returns 'nestedValue'

So, instead of square brackets, we can use .get, which can optionally be given a default fallback value.

One … (wait for it) … key difference is that .get won't raise a KeyError if the key isn't present, it'll just return None. (Which is usually why you get errors that say something about NoneType a lot.)

Try / except

If you've used try ... catch in JavaScript, Python has something like it, but it's a little better in that you can specify errors that you respond to.

try:
    # try to do something
except KeyError:
    # do something if there is a KeyError
except ValueError:
    # do something else if there is a ValueError
except:
    # handle any other errors

Raise

You can also force a specific error at a specific place, if you want:

if num < minimumAcceptedValue:
    raise ValueError('Number does not meet minimum!')

Decorators

I'm not going to go all the way into it, but decorators are a weird animal. It's basically a bit like calling another function, from a function, and passing the second function as an argument.

@decoratorFunction
def anotherFunction():
    # do stuff

Is another way of saying

anotherFunction = decoratorFunction(anotherFunction)

There's a lot more to it, and you have to jump through certain hoops to make decorators, but that's the concept in a nutshell.

Thank You

Thanks to Chris MacDonald, Julia Rose and James Turk for feedback on this article, and to Carl Johnson for the idea of including decorators, because yeah, they're weird.