1

If I run my program dash2ink.py

#!/usr/bin/env python3
s = input('Enter a long line please: ')
print('len(s) =', len(s))
print('end of s =', repr(s[-100:]))

and enter/paste a very long line, the length reported doesn't match the input length - the end is cut off to a length of 4095 characters.

Searching the web got me onto this answer on unix.stackexchange.com which (for my question) boils down to

4095 is the limit of the tty line discipline internal editor length on Linux

which seems to be used by the input function.

As suggested by the answer, I was able to get the whole entered/pasted string if I ran run my program like so:

saved=$(stty -g); stty -icanon icrnl; ./dash2ink.py ; stty "$saved"

Is there a way so I can simply run ./dash2ink.py and still have a relaxed input length limit?

wim
  • 338,267
  • 99
  • 616
  • 750
FriendFX
  • 2,929
  • 1
  • 34
  • 63
  • 3
    Do you strictly need to enter/paste the long lines of input interactively? Have you considered putting the data in a file and redirecting it directly to stdin, e.g. `/dash2ink.py < input.txt`, or just reading a file outright? `input` itself has no restriction on line length AFAIK -- it just reads from stdin. The issue is entirely with what program/method you're using to provide stdin. – Brian61354270 Oct 06 '21 at 00:54
  • Are you running on Windows or Linux (which appears to be the case) and if Linux, what clipboard are you pasting from exactly? (the suggestion @Brian is giving you is definitely the best one, if you have that option) – Grismar Oct 06 '21 at 01:02
  • @Grismar this is running Linux, but ideally this would also work under Windows. I do like to run it interactively, since I'd like the user to paste clipboard contents (copied from the Firefox Developer Tools Inspector window). Does that answer your question about what clipboard? – FriendFX Oct 06 '21 at 04:12
  • @Brian Yes, I'd like to paste text interactively as introducing a (temporary) file would just add complexity. – FriendFX Oct 06 '21 at 04:14
  • @FriendFX I'm not 100% sure if the answer on dupe is working for you, if it's not let me know and I'll get this reopened. – wim Oct 06 '21 at 04:52
  • 1
    @wim Yes, the duplicate answer is working for me, thanks - I hand't found it previously. Which is why I'm not too keen to delete this question, as it may point someone else to the duplicate. Hope this is OK. – FriendFX Oct 06 '21 at 04:58
  • Glad to hear it helped. Yes that's 100% okay, that's the whole purpose of duplicates (as "signposts" to help searchers find the already-answered content) – wim Oct 06 '21 at 06:46

0 Answers0