Python syntax to use File.separator

My instructor uses the Java syntax in Processing, and I’m trying to convert it to Python. The relevant part of his code is:

//Global variables
String fname4 = "gumballs.jpg";
String loadName = fname4;
int ncolors = 8;

//Inside the setup function
String fileName = loadName;
int nc = ncolors;
String paletteName = "palettes" + File.separator + fileName.substring(0, fileName.length()-4) + 
                "_" + str(nc) + ".bmp";
readPalette(paletteName, colorTable);

Python throws an error saying:

NameError: global name 'File' is not defined

Is there something wrong with the code, or is there a Python alteration needed?

2 Likes

File.separator is a java feature and it doesn’t exist in Python. Here’s one link to file separator in Python https://kite.com/python/examples/1093/os-get-the-path-separator-for-the-system.

3 Likes

Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/io/File.html
from java.io import File

2 Likes