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?
624 Views Asked by jcomeau_ictx At
2
There are 2 best solutions below
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
- new thread blocks main thread
- Extracting viewCount & SubscriberCount from YouTube API V3 for a given channel, where channelID does not equal userID
- Display images on Django Template Site
- Difference between list() and dict() with generators
- How can I serialize a numpy array while preserving matrix dimensions?
- Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
- Why is my program adding int as string (4+7 = 47)?
- store numpy array in mysql
- how to omit the less frequent words from a dictionary in python?
- Update a text file with ( new words+ \n ) after the words is appended into a list
- python how to write list of lists to file
- Removing URL features from tokens in NLTK
- Optimizing for Social Leaderboards
- Python : Get size of string in bytes
- What is the code of the sorted function?
Related Questions in PATH
- formatting path string in javascript
- Simplexml get path from variable
- Azure Web App PATH Variable Modification
- In Android, would it be possible to open a file in the 'values' folder and to read its content?
- Using paths bonded to a XCode project to be shared
- How would I be able to use a file in visual studio project on any computer?
- How to add directories to Cygwin gcc default search path
- Joomla css path incorrect
- R CMD recognize only some commands
- Generate TCPDF output to a shared drive folder
- How to get the exe path in nsis script?
- Issues with relative/absolute path
- relative path to .Exe
- Path of the current, parents and root directory
- JOptionPane Message with File Path
Related Questions in POSIX
- How to write data to stdin of the first process in a Python shell pipeline?
- C - does read() add a '\0'?
- What does a POSIX interface refer to in terms of microkernels?
- mq_timedsend() returns error 14 "bad address"
- Posix message queues and the command line?
- Copying existing function into memory buffer
- Ghost variable "idle" in terminal/cygwin?
- converting "1984-03-25 02:00:00" to POSIX gives NA
- Issue with pthread_setschedparam, system hangs
- tee stdout and stderr independently, without adding jitter
- POSIX-compliant file locking (within a single process)?
- Linux : pthread_cond_signal() is not working inside a Signal Handler()
- Compiling GRUB on Cygwin (64 bit)
- Counting bytes received by posix read()
- Bash: "invalid number" error when passing array elements value to variable
Related Questions in FILENAMES
- Saving multiple files with same name
- Calling a variable in Matlab without using the full name?
- Remove part of filename of files that are in different folders
- VBA – print file name in each row until the file closes
- Tail command - follow by name on Solaris
- Why the names of some css, js files have random numbers in them?
- How to capture a photo and immediately put it into an existing pdf?
- Get fileName property of PharFileInfo Object
- PHP - Find File in Directory By File Name
- Issue creating .txt file with long name
- Rename files if already exists centos7
- Only convert files with the string "DUPLICATE" in the name
- Database Table Path Combinations
- how to get the filename from the mentioned list
- Batch-Script: Replace every "@" in file name with "_" in network drive including subfolders
Related Questions in PYTHON-ZIPFILE
- Renaming ZipFile in Python
- Python - Compress all files in a directory using zipfile module
- ZipFile.testzip() returning different results on Python 2 and Python 3
- Extract files from zip without keeping the structure using python ZipFile?
- zipfile cant handle some type of zip data?
- Does Python zipfile always use posixpath filenames regardless of operating system?
- Python zipfile, bizarre limit to number of files: "folder is invalid"
- Python's zipfile library can't extract password protected file
- Read files with ZipFile using multiprocessing
- How do I convert a ZipFile object to an object supporting the buffer API?
- Python Zipfile read file and output each line instead of text block?
- Problem with the python zipfile library if you share a file between linux and windows
- Extract files from zip without keep the top-level folder with python zipfile
- get file list of files contained in a zip file
- zipping up xhtml2pdf pdf's with zipfile
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)
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?
Yes.
You can see these lines from the zipfile module:
And in the Zip specification: