I'm wondering what is going on with the file open()
mode validation (Python2.7):
>>> with open('input.txt', 'illegal') as f:
... for line in f:
... print line
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: mode string must begin with one of 'r', 'w', 'a' or 'U', not 'illegal'
>>> with open('input.txt', 'rock&roll') as f:
... for line in f:
... print line
...
1
2
3
So, I cannot open the file in illegal
mode, but I can open it in rock&roll
mode. What mode is actually used for opening the file in this case?
Note that on python3 I cannot use both illegal
and rock&roll
:
>>> with open('input.txt', 'rock&roll') as f:
... for line in f:
... print(line)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid mode: 'rock&roll'
>>> with open('input.txt', 'illegal') as f:
... for line in f:
... print(line)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid mode: 'illegal'
And, this is confusing, why the behavior is different for python3.x?
You need a suitable software like Rockbox from The Rockbox Crew to open a ROCK file. Without proper software you will receive a Windows message "How do you want to open this file?" or "Windows cannot open this file" or a similar Mac/iPhone/Android alert.
Plug-in file used by Rockbox, an open source firmware for portable music players; stores a game or another small application that can run on Rockbox; enables Rockbox "apps" to be used on iPods, SanDisk MP3 players, and other portable music players.
The Python 2.x open
function essentially delegates its work to the C library fopen
function. On my system, the documentation for fopen
contains:
The argument
mode
points to a string beginning with one of the following sequences (Additional characters may follow these sequences.):
Your ock&roll
is considered "additional characters".
In Python 3, the allowed open modes are more restricted (essentially, only valid strings are permitted).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With