Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Path not recognised
Using Python 3.7.4 ,I am providing the filepath of a videofile to the Googlecloud Python VideoIntelligence api for further processing.But it still complains that the path is not specified.Pylinter gives an "Anomalous backslash in string error".I have tried using r' \d "filepath"' but the error still persists.Please let me know , how to resolve this issue.

PS D:\Script\GCloud> d:\Script\GCloud\ usage: [-h] path error: the following arguments are required: path
Anomalous backslash in string: '\\S'. String constant might be missing an r prefix.

import argparse

from import videointelligence

path = "D:\Script\GCloud\sampleVidR1.mp4" #<--path not recognised
def analyze_labels(path):
    """ Detects labels given a GCS path. """
    video_client = videointelligence.VideoIntelligenceServiceClient()
    features = [videointelligence.enums.Feature.LABEL_DETECTION]
    operation = video_client.annotate_video(path, features=features)
    print('\nProcessing video for label annotations:')

    result = operation.result(timeout=90)
    print('\nFinished processing.')

    segment_labels = result.annotation_results[0].segment_label_annotations
    for i, segment_label in enumerate(segment_labels):
        print('Video label description: {}'.format(
        for category_entity in segment_label.category_entities:
            print('\tLabel category description: {}'.format(

        for i, segment in enumerate(segment_label.segments):
            start_time = (segment.segment.start_time_offset.seconds +
                          segment.segment.start_time_offset.nanos / 1e9)
            end_time = (segment.segment.end_time_offset.seconds +
                        segment.segment.end_time_offset.nanos / 1e9)
            positions = '{}s to {}s'.format(start_time, end_time)
            confidence = segment.confidence
            print('\tSegment {}: {}'.format(i, positions))
            print('\tConfidence: {}'.format(confidence))

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
    parser.add_argument('path', help='GCS file path for label detection.')
    args = parser.parse_args()

There is a number of special characters that in pair with \ have particular meaning
To avoid this behaviour use escape slashes
path = "D:\\Script\\GCloud\\sampleVidR1.mp4"
or construct paths using os.path.join
Other available options - use raw string
path = r"D:\Script\GCloud\sampleVidR1.mp4"
or use forward slash
path = "D:/Script/GCloud/sampleVidR1.mp4"
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

The above Code uses the Argparse module used to parse data from command-line interfaces.

On providing the python and video files locations via the commandline ,the script worked fine.

Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 407 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  Subprocess.Popen() not working when reading file path from csv file herwin 13 2,728 May-07-2021, 03:26 PM
Last Post: herwin
  Add file to sys.path permanently hcccs 5 1,852 Jan-31-2021, 11:26 AM
Last Post: hcccs
  PyDrive download file path MiniMinnow 0 1,828 Apr-28-2020, 03:01 PM
Last Post: MiniMinnow
  String to File Path creedX 4 1,360 Apr-06-2020, 07:29 PM
Last Post: creedX
  Add path to a local file in pop-up field pythonscripting 1 808 Feb-08-2020, 10:57 PM
Last Post: Larz60+
  How to get file name without the full path details and without extension aruncom2006 1 3,542 Jan-13-2020, 07:37 AM
Last Post: Larz60+
  How to include Variable in File Path penahuse 3 3,749 Jan-05-2020, 03:08 AM
Last Post: ichabod801
  How to search full path of specified file SriRajesh 3 1,223 Dec-14-2019, 04:52 PM
Last Post: Gribouillis
  how do i write a cross-platform relative file path? pseudo 2 1,385 Aug-23-2019, 05:07 PM
Last Post: ThomasL

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020