It probably won't matter for my current utility, but just for good coding practice, I'd like to know if files in a ZIP file, using the zipfile module, can be accessed using a POSIX-style pathname such as subdir/file.ext regardless of on which operating system it was made, or on what system my Python script is running. Or if, in the case of Windows, the file will be stored or accessed as subdir\file.ext. I read the pydoc for the module, and did some searches here and on Google, but couldn't see anything relevant to this question.
Does Python zipfile always use posixpath filenames regardless of operating system?
629 views Asked by jcomeau_ictx At
2
There are 2 answers
0
user18236245
On
I have the same problem in the zipfile.py module.
os.path.sep returns {AttributeError}module 'posixpath' has no attribute 'sep' so I modified the file in
def _extract_member(self, member, targetpath, pwd):
"""Extract the ZipInfo object 'member' to a physical
file on the path targetpath.
"""
by replacing os.path.sep by os.sep (which returns the correct value / on a mac operating system).
It solves the problem both for zipfile open and extract methods.
Related Questions in PYTHON
- How to store a date/time in sqlite (or something similar to a date)
- Instagrapi recently showing HTTPError and UnknownError
- How to Retrieve Data from an MySQL Database and Display it in a GUI?
- How to create a regular expression to partition a string that terminates in either ": 45" or ",", without the ": "
- Python Geopandas unable to convert latitude longitude to points
- Influence of Unused FFN on Model Accuracy in PyTorch
- Seeking Python Libraries for Removing Extraneous Characters and Spaces in Text
- Writes to child subprocess.Popen.stdin don't work from within process group?
- Conda has two different python binarys (python and python3) with the same version for a single environment. Why?
- Problem with add new attribute in table with BOTO3 on python
- Can't install packages in python conda environment
- Setting diagonal of a matrix to zero
- List of numbers converted to list of strings to iterate over it. But receiving TypeError messages
- Basic Python Question: Shortening If Statements
- Python and regex, can't understand why some words are left out of the match
Related Questions in PATH
- How to write a clickable link in VS Code terminal that points to a multiline range?
- Can't run Python's mapscript because of a missing DLL
- How change path to my new generated webp image in index.html?
- Correct way to compare file paths when one is canonical and other absolute
- make Error 2, The system cannot find the file specified
- Tkinter treeview displaying and selecting rows question
- Running clang64.exe or mingw64.exe incorrectly sets PATH
- Python project deployment on Ubuntu 18 server
- FileNotFoundError while trying to load dataset from drive
- Powershell Receive-File issue
- BlendMode does not work as expected with a path and circle in Jetpack Compose
- return all paths in a nested dictionary that also contains a list in python
- How to show and change Image inside a Flask Route?
- What is vue router :matchRest(.*)* and when should I use it?
- Cassandra Installation Issue on Windows 11- 64bit
Related Questions in POSIX
- Is it safe to assume 8-bit char on Linux and FreeBSD, based on POSIX?
- How many senders and receivers of a notification are possible in a POSIX message queue
- Does opendir() / FindFirstFile() get a snapshot of a directory?
- Differences in behavior of kill(pid, SIGINT) between Debian and Red Hat based distros
- select() always returns 0 Serial Port (UART) vxWorks
- some questions about posix_trace_* function
- In LDAP: Differentiating via OU or via attribute?
- recvmsg returns EAGAIN after select reports file descriptor is ready
- Can close of pipe's write end fail leaving reading process blocked?
- Why, on Linux (specifically Ubuntu 20.04 LTS), a POSIX shared memory object survives reboot and then suddenly belongs to the "root" user?
- file.tell() after a write is not correct in append mode?
- Map UNIX "nobody" and "nogroup" to Win32 Accounts/SIDs?
- POSIX Message Queue - "Message too long" on send
- Does the POSIX Standard really mean that a non-thread safe function can break the thread-safety of every other function?
- awk dot in regex doesn't match space
Related Questions in FILENAMES
- 1 filenames = [] 2 ----> 3 for file in os.zipfile('images.zip'):
- My Google Apps Script renames all files in a folder from data in a spreadsheet. Can someone explain why it returns an exception error?
- excel filename by vba script causes 2 filenames
- How to obfuscate windows long filenames without exceeding max length
- Applescript How to get the filename from open -a "xx.app" [file] --args "someargs" in the applescript
- How to rename file name in Linux using the command "rename"?
- Changing the all filename field of WooCommerce products
- C++ - Shell API - Is there a way to convert a display file name to a parsed file name?
- Call windows explorer to refresh recycle bin filename
- How to speed up Open Folder "whose name starts with" in AppleScript
- How can I use VBA coding to make word automatically remember the filename of a dragged and dropped image?
- Parent directory \results does not exist, in pytorch when trying to save a new network
- Extracting the date from a filename
- Render PDF from byte[] with specific filename using blazor .net 8
- Use Python or Shell to answer this challenge
Related Questions in PYTHON-ZIPFILE
- Python. Unzip archive to which the filenames are encoded using urlencode, and because of the encoding, the length of some names is > 260
- python check if compressed file is password-protected with just a small part of a file
- Why is my zip file not the same size as the zip file I'm trying to copy?
- Invalid Argument Error when using Zipfile to backup
- Fix concurrent writing in Zipfile
- Problem compressing files in python with zipfile
- Challenges with On-the-Fly ZIP File Downloads: Seeking Solutions for Files Beyond 4GB using python
- how to extract a multi-part zip with Python
- How to fix 502 error when deploying django project as a zip file using elastic beanstalk
- Python accessing hidden zip file using ZipFile permission error
- Moving files from a Zipped folder to respective folders(name of the folders to be derived from file names)
- Why the ZipFile python library does not enforce passwords if ZipCrypto encryption is set?
- Django app, how to download all files asociated a project?
- Python - WinError 32 when deleting last .zip file
- Python ZipFile's ZipInfo Empty
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Yes.
You can see these lines from the zipfile module:
And in the Zip specification: