Check your indenting. This unhelpful SyntaxError error has fooled me before. :)

From the deleted question:

I'd expect this to be a duplicate, but I couldn't find it.

Here's Python code, expected outcome of which should be obvious:

x = {1: False, 2: True} # no 3

for v in [1,2,3]:
  try:
      print x[v]
  except Exception, e:
      print e
      continue
I get the following exception: SyntaxError: 'continue' not properly in loop.

I'd like to know how to avoid this error, which doesn't seem to be 
explained by the continue documentation.

I'm using Python 2.5.4 and 2.6.1 on Mac OS X, in Django.

Thank you for reading
Answer from Brian M. Hunt on Stack Overflow
🌐
Real Python
realpython.com › ref › builtin-exceptions › ioerror
IOError | Python’s Built-in Exceptions – Real Python
In Python, IOError is a built-in exception that was used to handle input/output (I/O) related errors, such as problems reading or writing files.
🌐
AskPython
askpython.com › python › examples › handling-ioerrors
Handling Built-in Exception IOError in Python (With Examples) - AskPython
May 8, 2023 - In Python 2, whenever we are performing an I/O operation and it fails, an exception is thrown called IOError.
Discussions

exception - catching an IOError in python - Stack Overflow
I wrote a method that does some stuff and catches bad filenames. what should happen is if the path doesn't exist, it throws an IOError. however, it thinks my exception handling is bad syntax... why... More on stackoverflow.com
🌐 stackoverflow.com
python - Difference between IOError and OSError? - Stack Overflow
I am always getting confused on whether a function would raise an IOError or OSError (or both?). What is the principle rule behind these exception types, what is the difference between them and whe... More on stackoverflow.com
🌐 stackoverflow.com
python - what are the all of the "causes" for an IOerror - Stack Overflow
From Python Docs exception IOError Raised when an I/O operation (such as a print statement, the built-in open() function or a method of a file object) fails for an I/O-related reason, e.g., “fil... More on stackoverflow.com
🌐 stackoverflow.com
What’s the difference between IOError and OSError in python?
Is that homework? More on reddit.com
🌐 r/learnpython
6
0
November 11, 2020
🌐
EDUCBA
educba.com › home › software development › software development tutorials › python tutorial › python ioerror
Python IOError | How IOError work in Python with Programming Examples
April 13, 2023 - In a Python program, where we have a simple operation of print the content of a file, we pass the file name and path of the file location. But if the file that we passed, does not exist at the passed location or the file name has been changed, then the operation we intend to execute won’t happen. Which will result in an error related to Input Output, which is IOError.
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
Initial Commit
initialcommit.com › blog › python-ioerror
IOError in Python | How to Solve with Examples - Initial Commit
The io error has more to it than the exception it throws, and it's important to understand that going forward. An io error is raised during the failure of an input/output system task. In Python, errors don't appear randomly but rather show up ...
🌐
TutorialsPoint
tutorialspoint.com › How-to-catch-IOError-Exception-in-Python
How to catch IOError Exception in Python?
In Python, an IOError (or OSError in latest versions) occurs when an input/output operation fails. For example, when we are trying to read a file that doesn’t exist, writing to a file that is read-only, or accessing a corrupted device. You can catch
🌐
Python
docs.python.org › 3 › builtins › exceptions.html
Built-in Exceptions — Python 3.14.7 documentation
Changed in version 3.3: EnvironmentError, IOError, WindowsError, socket.error, select.error and mmap.error have been merged into OSError, and the constructor may return a subclass.
Find elsewhere
🌐
HeyCoach Blog
heycoach.in › blog › handling-ioerror-in-python
Handling IOError In Python
December 27, 2024 - First things first, let’s tackle the big question: What on earth is an IOError? In the realm of Python, an IOError is raised when an input/output operation fails.
🌐
Vertabelo Academy
academy.vertabelo.com › course › python-basics-part-2 › operating-on-files › with-statement-and-exception-handling › exceptions-and-ioerror
Learn about IOError | Python Basics course
Specifically speaking, we expect that an IOError may occur. IO stands for Input-Output. An Input-Output error is one related to handling files – such as a full disk or nonexistent file – and other user input errors. If an IO error is thrown by the application, the execution of the try block is interrupted, and Python moves on to the except-block.
🌐
Python
peps.python.org › pep-3151
PEP 3151 – Reworking the OS and IO exception hierarchy | peps.python.org
July 21, 2010 - The first possibility is to adapt the PyErr_SetFromErrno() family of functions (PyErr_SetFromWindowsErr() under Windows) to raise the appropriate OSError subclass. This wouldn’t cover, however, Python code raising OSError directly, using the following idiom (seen in Lib/tempfile.py): raise IOError(_errno.EEXIST, "No usable temporary file name found")
🌐
Reddit
reddit.com › r/learnpython › what’s the difference between ioerror and oserror in python?
What’s the difference between IOError and OSError in python? : r/learnpython
November 11, 2020 - It also says IOError was merged with OSError. There is also a FileNotFoundError for when a file doesn't exist. Note that these are conventions, libraries can raise whatever they want. Your best bet is to read the documentation of the functions you're calling. ... I finished Helsinki's Advanced Programming course and would like to know what some popular courses are that could come after this one. Perhaps about DSA or other. ... Python is so confusing to me.
🌐
GitHub
github.com › asottile › pyupgrade › issues › 141
py3.3+: IOError (and others) -> OSError · Issue #141 · asottile/pyupgrade
May 10, 2019 - In Python 3.3+ the following exceptions are now simple aliases of OSError: IOError, EnvironmentError, WindowsError, mmap.error, socket.error and select.error. The aliases have been removed from the...
Author: asottile
🌐
Gnome
api.pygobject.gnome.org › GLib-2.0 › enum-IOError.html
IOError — GNOME Python API
GNOME Python API · Search Ctrl+K · System Settings · Light · Dark · Search Ctrl+K · System Settings · Light · Dark · Collapse Sidebar Expand Sidebar · class IOError# IOError is only used by the deprecated functions read(), write(), and seek(). class IOError ·
🌐
Reddit
reddit.com › r/learnpython › ioerror exception (in python 2.7.2?
r/learnpython on Reddit: IOError exception (in Python 2.7.2?
November 12, 2020 -

Hello, I am trying to read from the .gz file and it is giving me the following error. Below are the code and traceback.

f = glob.glob (*/.gz)
if f:
    for files in f:
        with zgip.open(files, 'r') as r:
            for line in r:
                for i in range (3):
                    print line

Traceback:

Traceback (most recent call last):
  File "tst.py", line 14, in <module>
    for line in r:
  File "python2.7/gzip.py", line 446, in readline
    c = self.read(readsize)
  File "python2.7/gzip.py", line 252, in read
    self._read(readsize)
  File "python2.7/gzip.py", line 287, in _read
    self._read_gzip_header()
  File "python2.7/gzip.py", line 181, in _read_gzip_header
    raise IOError, 'Not a gzipped file'
IOError: Not a gzipped file

Please help me in solving this.

🌐
Python Course
python-course.eu › python-tutorial › errors-and-exception-handling.php
32. Errors and Exception Handling | Python Tutorial
import sys try: f = open('integers.txt') s = f.readline() i = int(s.strip()) except IOError as e: errno, strerror = e.args print("I/O error({0}): {1}".format(errno,strerror)) # e can be printed directly without using .args: # print(e) except ValueError: print("No valid integer in line.") except: print("Unexpected error:", sys.exc_info()[0]) raise
🌐
Anenadic
anenadic.github.io › 2014-11-10-manchester › novice › python › 07-errors.html
Python errors and exceptions
If you try to read a file that does not exist, you will recieve an IOError telling you so.
🌐
The Teacher
theteacher.info › index.php › python-3 › errors-and-bugs › 1595-handling-io-exceptions-2
Handling IO exceptions
Get this code working in Python: #Handling an error associated with writing to and reading from a file. try: writefile = open("testFile", 'w') writefile.write("This is a lot of data that I want to save to a file") print('You can put some more lines of code here.') except IOError: print ("Error: can't write the data to the file for some reason.") else: print ("Content written to the file successfully.") writefile.close() Q2.