Search code examples
pythonpython-3.xcinema-4d

Python for C4D invalid syntax underneath file path?


Hi does anyone know why I have an error here underneath the t ?:

SyntaxError: invalid syntax File "'scriptmanager'", line 3 filepath = r '/Users/luke/Documents/water.numbers.csv' ^
SyntaxError: invalid syntax

regards,

import c4d

filepath = r '/Users/luke/documents/water.numbers.csv'

fileobj = (filepath, 'r')

print fileobj.readline ()


Solution

  • Is what you want this?

    1 import c4d
    2 
    3 filepath = r'/Users/luke/documents/water.numbers.csv'
    4             ^
    5 fileobj = open(filepath, 'r')
    6           ^^^^
    7 print fileobj.readline()
                            ^
    
    • You had a space between "r" and "'" after "filepath =" which I think would make trouble (line 3).
    • You were missing the 'open' for creating a file object (line 5.
    • I think Python probably also won't like the space between "readline" and "()" (line 7).