Python can't read the file

Joy's Avatar

Joy

02 Feb, 2016 04:23 PM

I try to open the text file as I follow the Str tutorial.
str = open("joy.txt").read()

fill(0.2)
rect(0,0,WIDTH, HEIGHT)

fill(1)

font("Helvetica", 13)
text("Heading", 20, 30)

However I've got this error:
Traceback (most recent call last):
File "/Users/Joy/Documents/NodeBox/NodeBox.app/Contents/Resources/python/nodebox/gui/mac/__init__.py", line 361, in _execScript exec self._code in self.namespace File "", line 1, in IOError: [Errno 2] No such file or directory: 'joy.txt'

I use Nodebox Version 1.9.7rc1 (1) on OSX 10.11.3

Thank you.

  1. Support Staff 1 Posted by Frederik De Ble... on 02 Feb, 2016 07:30 PM

    Frederik De Bleser's Avatar

    Hi Joy,

    This can happen when your NodeBox file is not saved yet.

    NodeBox looks for files relative to the current .py file. However, if you haven't saved your file first, NodeBox doesn't know where to look. Try saving the script first, then placing the txt file in the same folder as the script.

    Best,

    F

  2. 2 Posted by Joy on 02 Feb, 2016 08:43 PM

    Joy's Avatar

    Hi Frederik,

    Thank you. I have saved the file and change the path to '/Users/Joy/Documents/NodeBox/sandbox/joy.txt'
    And it works now.

    Best,

    Joy

  3. Support Staff 3 Posted by Frederik De Ble... on 03 Feb, 2016 11:28 AM

    Frederik De Bleser's Avatar

    I just checked and it isn't mentioned anywhere in the documentation, so it would be very hard for you to just know that :-)

    I'll see if I can update it.

Reply to this discussion

Internal reply

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

Attaching KB article:

»

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

Generic

? 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

17 Jun, 2025 06:15 AM
17 Jun, 2025 06:11 AM
16 Jun, 2025 02:18 AM
11 Jun, 2025 10:57 AM
11 Jun, 2025 09:53 AM

 

10 Jun, 2025 08:03 AM
10 Jun, 2025 01:33 AM
08 Jun, 2025 09:25 AM
08 Jun, 2025 09:19 AM
08 Jun, 2025 09:19 AM
08 Jun, 2025 09:18 AM