简体   繁体   English

从 Python 中的共享驱动器读取不带扩展名的文件

[英]Read file without extension from shared drive in Python

I'm experiencing difficulties with accessing and reading a file without extension(which is a json inside, need to read it somehow, but I can't access it) from a shared drive.我在从共享驱动器访问和读取没有扩展名的文件(内部是 json,需要以某种方式读取它,但我无法访问它)时遇到困难。

This is what I've tried so far:这是我迄今为止尝试过的:

First try:第一次尝试:

open(r"X:\\shared_drive\Notes").read() on this one I'm getting FileNotFoundError: [Errno 2] No such file or directory: open(r"X:\\shared_drive\Notes").read()在这个我得到FileNotFoundError: [Errno 2] No such file or directory:

Second try:第二次尝试:

with open(r"\\DESKTOP-xxx\shared_drive\Notes", 'r') as f:
      f.read()

And on this one I'm getting OSError: [Errno 22] Invalid argument:在这个我得到OSError: [Errno 22] Invalid argument:

instead of writing the path as:而不是将路径写为:

\\DESKTOP-xxx\shared_drive\Notes

Have you tried using os package:您是否尝试过使用os package:

import os.path
file_to_open = os.path.join("DESKTOP-xxx", "shared_drive", "Notes")
f = open(file_to_open)

Or pathlib :pathlib

from pathlib import Path
data_folder = Path("//DESKTOP-xxx/shared_drive/Notes")
file_to_open = data_folder / "Notes"
f = open(file_to_open)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pydrive:如何从共享驱动器读取文件? - Pydrive : How to read file from Shared Drive? 在共享驱动器上运行python文件,而无需安装python或python框架 - Run python file on shared drive without installing python or python frameworks 如何使托管在 PCF 中的 python 代码从网络共享驱动器读取 excel 文件 - How to make my python code that is hosted in PCF to read excel file from network shared drive 使用 Python 从共享的 Google 驱动器文件夹中读取多个 csv - Read multiple csv from Shared Google drive folder using Python 从谷歌驱动器读取 excel 文件而不下载文件 - Read excel file from google drive without downloading file 如何将csv文件上传到谷歌驱动器并将其从同一个文件中读取到python中 - How to upload csv file into google drive and read it from same into python 运行代码以在 Python 中从谷歌驱动器读取文件时出现 KeyError - KeyError when running codes to read file from google drive in Python 从 Python 中具有相同文件扩展名的多个文件的目录中读取文件 - Read File From Directory with Multiple Files of the Same File Extension in Python 如何在python中读取扩展名为.dat的文件并从中提取数据 - How to read a file of extension .dat in python and extract data from it 如何使用 Python 读取 google 驱动器文件 - How to read a google drive file with Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM