Import TXT

john's Avatar


19 Oct, 2017 11:40 PM

Attached is a demo network with a custom node, import_txt. Import_txt works just like import_csv: point it at a txt file and it will return a list of each line (string) in that file.

To use it, like all custom nodes, you must not only copy/paste the node, but also copy the file (usually into the same folder holding your NodeBox file) and then add it to your Code Library (under the Nodebox File menu).

There are many situations where it is useful to read in text files. In the past I have done this using the import_csv node, taking the first key, and feeding that into a lookup node. However, this is kludgy and will not work if the first line of the text file contains a character forbidden for keys (column headers) like commas.

The zipped demo file contains a folder with the Import_TXT NodeBox network, the python code file, and a sample text file: the works of Golden Age sci-fi-fi writer Henry Kuttner. The demo reads that text file and then culls and sorts lines beginning with an asterisk to produce a list of all the Kuttner books in my collection.

Frederik, if you're listening, this would be easy to add as another standard node.



  1. Support Staff 1 Posted by Frederik De Ble... on 20 Oct, 2017 07:29 AM

    Frederik De Bleser's Avatar

    Hi John,

    Having a "import text file" node would indeed be useful. I see here that you split by lines, do you ever have a need of importing it as a single string?

  2. Support Staff 2 Posted by john on 20 Oct, 2017 09:11 AM

    john's Avatar

    No, so far I have only needed multiple lines. I am hard pressed to think of a case where I would want a single string.

    I was going to add that it would be easy enough to recombine multiple lines into a single string, but that is hard in NodeBox, isn’t it? I have occasionally wanted to recombine a list of individual strings into one string but didn’t see a way to do that (since NodeBox doesn’t have recursion or state). The characters node will turn a string into a list, but there seems to be no way to do the reverse.

    So I guess instead of providing an “import giant string” option, I would prefer a simple import text that splits by line, but I’d also like a “join” node that would join a list into a single string. That would be useful even without an import_txt node!



  3. Support Staff 3 Posted by Frederik De Ble... on 20 Oct, 2017 02:13 PM

    Frederik De Bleser's Avatar

    I was thinking about"concatenate" but that doesn't work on a list of inputs. An  "string join" that works on lists would help...

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:


Already uploaded files

  • 9.78 KB
  • import_txt_screenshot.png 468 KB

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

29 May, 2024 05:47 AM
29 May, 2024 05:15 AM
29 May, 2024 05:12 AM
28 May, 2024 07:37 PM
25 May, 2024 11:52 AM


24 May, 2024 07:39 AM
16 May, 2024 02:11 AM
14 May, 2024 01:29 AM
12 May, 2024 07:46 PM
05 May, 2024 04:38 PM
03 May, 2024 06:50 AM