2

I am trying to convert few camera-clicked images of handwritten Gujarati characters to the form of MNIST dataset as I intend to pass the Gujarati handwritten characters images to the MNIST deep learning model. And as part of that, I'm trying to assign a file path to a variable named "datadir". But when executing the below code in Ubuntu 16.04, the terminal throws the error which looks like this: File "gujaratinn.py", line 7 datadir = /home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize ^ SyntaxError: invalid syntax

Note that the name of the file is gujaratinn.py and all the camera-clicked images are stored in the Resize folder.

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("/home/cryptoaniket256/Desktop/opencv- 
3.4.1/project/Resize")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
1
  • Also do os.path.dirname(__file__) to get the script's directory instead of hardcoding it. Commented Oct 29, 2018 at 14:12

1 Answer 1

3

Are you affecting datadir with a path you wrote on 2 rows in your code ?

Try to put line 7 and 8 on the same row or change the quotes like that:

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
Sign up to request clarification or add additional context in comments.

2 Comments

Hello @NickNick! Actually, line number 7 and 8 are on the same line itself in the actual code.
Hurray! The change of quotes solution worked @NickNick! Thank You, buddy, for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.