


How to read pdf or pptx or docx file from ADLS gen2 in python using Synapse?
I want to use python in synapse notebook to read files in different formats. These include .pdf, .pptx, .docx, .msg, and .eml. I want to be able to read files and then parse and manipulate them with python. I was able to do this in data blocks using different python libraries.
This is how I accomplish this task in data bricks:
from pptx import Presentation prs = Presentation(file_name) # for pdf from pypdf import PdfReader reader = PdfReader(open(filename, 'rb')) # word docs import docx doc = docx.Document(file_name) # .eml files import email msg = email.message_from_file(open(file_name))type here # .msg files import extract_msg msg = extract_msg.Message(file_name)
In synapse I get the error: FileNotFoundError: [errno 2] No such file or directory.
These file paths can read csv, excel or txt data using spark or pandas, so I don't think there is an authorization or connection issue. The format is: abfs[s]://file_system_name@account_name.dfs.core.windows.net/file_path
I also tried mounting the storage location. This does help reading text files, but not other formats. Mounting the storage location in synapse
Correct answer
Install is the correct way, This answer explains it. I'm using synapse studio. The key is to use the file format obtained from the path command to the mounted storage. Otherwise I can basically use what I mentioned previously in the question. Only for pdf I had to change from using pypdf library to pypdf2.
The valid format is:
path = mssparkutils.fs.getmountpath("/mounted_name") # this gave me this format '/synfs/{jobid}/mounted_path/{filename}'
Format obtained from mssparkutils fs does not work
mssparkutils.fs.ls("synfs:/{jobId}/mounted_path/") # this gave a different format which did not work 'synfs:/{jobId}/mounted_path/{filename}'
The above is the detailed content of How to read pdf or pptx or docx file from ADLS gen2 in python using Synapse?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

Regular expressions are powerful tools for pattern matching and text manipulation in programming, enhancing efficiency in text processing across various applications.

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

The article discusses popular Python libraries like NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow, Django, Flask, and Requests, detailing their uses in scientific computing, data analysis, visualization, machine learning, web development, and H

In Python, how to dynamically create an object through a string and call its methods? This is a common programming requirement, especially if it needs to be configured or run...
