[英]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.