24 ms·
Hello, my name is Tim. I'm a lead at Google with over 30 years coding experience and I need to look up how to get length of a python string. <sarcasm> The prob
by canadian_voter 10y ago
Hello, my name is Tim. I'm a lead at Google with over 30 years coding experience and I need to look up how to get length of a python string.
<sarcasm>
The problem with Python is the arcane, arbitrary and nonsensical syntax. It sure as hell isn't anything as obvious as length(str) or string.length like any reasonable language.
And god help you if you want to do something complicated like define a function.
</sarcasm>
But seriously: I have no problems with the rest of the article, but that one just seems silly. How many times do you have to look something like that up before it sticks? For those of you not versed in the more esoteric secrets of Python, you would use the built-in function len, as in len(str).
Of course there are alternatives: http://stackoverflow.com/questions/3992192/string-length-without-len-function http://stackoverflow.com/questions/3992192/string-length-wit...
Edit: Added <sarcasm> tags for clarity.
- adsims2001 10y agoSeems overly harsh. Why is the actual code, "len(s)" so much worse than your suggestion of "length(s)"?
- Fargren 10y agoAnd I can't count the times I tried to do s.len() or s.length().
- charles-salvia 10y agoOf course, s.__len__() actually works.
- sp332 10y agoI used Python for years, although I'm a little rusty now. I ran into that kind of problem all the time. Your first two examples are what came to mind first.
- Izmaki 10y agoJust as many things I love about python, I hate about python. Each time I get to the part where I need to modify the path which the import mechanism uses to look for modules, clean up the loaded modules to make sure I'm not reimporting an already loaded module by the same name, in order to import a module which is in the SAME DIRECTORY as - get this -__file__, I need another coffee. Also "len(...)" is not obvious.
- jghn 10y agoAs someone who has worked with a lot of languages over the years I can never remember which one is `length(x)`, `len(x)`, `x.length`, `x.len`, and so on. For me the answer is "never", apparently. Then again I tend to struggle with basic syntax no matter what language I'm using or how frequently I use it.
- mdinstuhl 10y agoYou forgot sizeOf()! If it makes you feel any better, I am in the same boat.