I constantly ask this to myself when reading/writing Python related questions or answers, so I'll use the Python console as example, but I'm pretty sure it can be extended to other contexts.
See for example my answer here, the code part is:
>>> from functools import reduce>>> d = {1: pd.Timedelta('0 days 01:44:39'), 2: pd.Timedelta('0 days 02:34:01'), 3: pd.Timedelta('0 days 00:49:15'), 4: pd.Timedelta('0 days 01:13:26'), 5: pd.Timedelta('0 days 00:38:14')}>>> reduce(lambda a,b: a+b, d.values())#Timedelta('0 days 06:59:35')
I use >>>
for denoting a console entry, so one can easily distinguish different entries. Nevertheless, if someone wants to test it, it would be unavoidable to copy line by line because copying the whole code means to copy the >>>
's too, which will lead to an error if pasted in the Python console.
Then, my question is, is there a way to make the >>>
not selectable when copying, in order to make testing easy?
I've seen something like this a few times in other websites like here, where you can copy the example code omitting >>>
and ...
.
I'm also open to the idea that this is not necessary since one could just omit >>>
, but I'm not convinced at all because in some contexts it could be better to explicitly show a console-formatted code. Also, it would make easier to copy from console to paste it in SO.
Something similar is discussed here, but it is focused on Python console conventions instead of a way to make text not selectable and, as I mentioned before, it is not necessarily a Python topic only.