4 ms·
From their examples: projects.insert({ '_id': "BedquiltDB", 'description': "A ghastly hack.", 'quality': "pre-alpha", 'tags': ["jso
by kevincox 11y ago
From their examples:
projects.insert({
'_id': "BedquiltDB",
'description': "A ghastly hack.",
'quality': "pre-alpha",
'tags': ["json", "postgres", "api"]
})
Does anyone actually mix quotes like this in python? It's horrible.
- bpicolo 11y agoSingle-quotes is the typical way to go. I do know when I'm not linting that I mix and match unintentionally. Easy to forget
- illumen 11y agoI wish this was defined by pep8, but sort of glad it's not. Much python code uses single quotes, with double quotes for doc strings. Except where it is more convenient. More convenient places include structures when escaping strings. "Joe's easier here's why." Is better than 'Joe\'s easier here\'s why.' Also structures which are JSON structures too (makes copy/pasta easier).
- sago 11y agoAnother commenter articulated this, but my general style was single quotes on 'atoms' (e.g. mostly dictionary keys or set values), double quotes on anything intended to be read by a person. For that reason: to avoid \' all over. Though with py3, using alt-shift-] on my machine gives me ’, so I can do 'Joe’s easier, here’s why.'
- bpicolo 11y agoOr py2 via # -- coding: utf-8 --
- jxcl 11y agoIt depends. It's useful to be able to contain quotes in other quotes without escaping them. i.e. '"hello there"' or "it's nice to see you" Also, on many projects I've worked on, single quotes were for strings that were not meant to be shown to users (keys etc), and double quotes were for strings that would eventually be shown on a screen. It looks like that's what they're doing here.
- kevincox 11y ago> Also, on many projects I've worked on, single quotes were for strings that were not meant to be shown to users (keys etc), and double quotes were for strings that would eventually be shown on a screen. It looks like that's what they're doing here. Interesting, I've never seen that convention before.
- s_kilk 11y agoHuh, good catch. I guess I default to using single-quotes for dictionary keys, and double quotes for text strings
- Mahn 11y agoI do this too, single quotes for simple/static strings, double quotes for (potentially) complex/dynamic strings. Nothing wrong with that as long as you are consistent, though I suppose it's a very subjective thing.
- derefr 11y agoI have no idea why I'd do that in Python. In Ruby, I use single-quoted strings for things that can't possibly, by their nature, contain any string interpolation, to indicate that this is so; and then double-quoted strings for more arbitrary text that either contains interpolation, or might, in the future, get interpolation added. The coder here might be used to Ruby programming. Though, also, it occurs to me that—since this is a dictionary that will become JSON—its type is {String => Object}. The single-quoted strings sort of read to me as indicating strings that couldn't be any other type; while the double-quoted strings are strings just because strings happen to be the response there, but could be any other object.
- abiox 11y ago> It's horrible. i can dig it. works decently as visual articulation.