Tuesday, October 20, 2015

How long is the pound symbol?

In Python 3, the pound symbol, £, is one character long, as you would expect.

Python 3.4.0 (default, Jun 19 2015, 14:20:21)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> len('£')
1



But in Python 2 (which I, like many people, have to use for work), it is two characters long.

Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> len('£')
2


Unless you convert it to unicode.

In [152]: len(u'£')
Out[152]: 1

Worth knowing!

It's also worth being aware that 'str's get a bit funny in Python 2 when you wander out of ascii-land. And iterating through them will not do what you expect. I recommend sticking to unicode where you can.

Sunday, October 4, 2015

"java.lang.RuntimeException: Reader tag must be a symbol" Clojure

Very quick blog post because I couldn't see this anywhere on the top page of results:

If you're learning clojure, and you get this error
'java.lang.RuntimeException: Reader tag must be a symbol'

check if you're putting whitespace between # and ( in an anonymous function literal. Don't do that. 


(If it was something else causing that error for you, please add it to the comments when you work it out)