1

This is my code:

data_directory = Path('‪G:\Pneumonia\chest_xray\chest_xray')

train_directory = data_directory / 'train'
val_directory = data_directory / 'val'
test_directory = data_directory / 'test'

normal_cases_directory = train_directory / 'NORMAL'
pneumonia_cases_directory = train_directory / 'PNEUMONIA'

normal_cases = normal_cases_directory.glob('*.jpeg')
pneumonia_cases = pneumonia_cases_directory.glob('*.jpeg')

train_data = []

for images in normal_cases:
    train_data.append((images, 0))

for images in pneumonia_cases:
    train_data.append((images, 1))
    
train_data = pd.DataFrame(train_data, columns=['image', 'label'],index=None)

This is output: OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect: '\u202aG:\Pneumonia\chest_xray\chest_xray\train\NORMAL'.

I noticed the \u202a symbol in the beginning but I don't know how to fix it.

2 Answers 2

2

Use raw strings to pass the path:

Path(r'G:\Pneumonia\chest_xray\chest_xray')
1
  • This is probably unrelated to the original problem, but a good idea, and retyping the path probably removed the invisible Unicode character.
    – tripleee
    Commented Nov 17, 2020 at 5:45
0

U+202A is an invisible character which affects the text's direction. You probably accidentally copy/pasted it from somewhere into your program source.

(It doesn't change the text's direction because it's already left-to-right. The character would make sense if the path name was written in a piece of e.g. Arabic or Hebrew text which otherwise runs right-to-left, and you wanted this Latin string to display left-to-right. Perhaps you copy/pasted it from somewhere like that?)

You can't see it but you can remove it simply by backspacing over it. Place the cursor on G: and move left; you should notice that it takes two presses to move from the left side of the G to the left side of the opening single quote. Similarly, you can move back to the left of the G and type backspace to remove the invisible character there.

Not the answer you're looking for? Browse other questions tagged or ask your own question.