- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What does the 'U' modifier do when a file is opened using Python?
In a Python with universal newline support open() the mode parameter can also be "U", meaning "open for input as a text file with universal newline interpretation". This is needed for crossplatform support as newlines on Unix os are represented by a single character \n while those on windows are represented by 2 characters \r\n. When opened in Python, All line ending conventions will be translated to a "\n" in the strings returned by the various file methods such as read() and readline(). For example you have a file on windows with the text −
Hello\r\nworld When you open it in Python using the 'U' modifier, and read it: with open('hello.txt', 'rU') as f: print(f.read())
You'll get the output −
- What does the 'b' modifier do when a file is opened using Python?
- What are the modes a file can be opened using Python?
- What does the modifier transient in Java do?
- What does the modifier volatile in Java do?
- What does synchronized modifier do in Java?
- What does abstract modifier in Java do?
- Determine when a Frame or Window is Opened in Java
- What does opening a file actually do on Linux?
- How to close an opened file in Python?
- How do we specify the buffer size when opening a file in Python?
- What is a lunar eclipse? When does it occur?
- How to close all the opened files using Python?
- What does 'is' operator do in Python?
- What does the &= operator do in Python?
- How do we do a file upload using Python CGI Programming?