Python Forum
UnboundLocalError, how to fix it please?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UnboundLocalError, how to fix it please?
#1
Hello, i'm facing a problem with python, i'm actually using the 2.6 version one because the scripts have been made for it, the 3.4 kept talking about syntax error.....

Anyhow it seems that there is still a problem, i'm getting the following error :

Error:
File "C:\script\cmio.py", in line 25, in <module> File "C:\script\cmio.py", in line 24, in swig_import_helper UnboundLocalError: Local variable '_mod' referenced before assignment
Here the begining of the script, included the lines :

# This file was automatically generated by SWIG (http://www.swig.org).
# Version 1.3.39
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
# This file is compatible with both classic and new-style classes.

from sys import version_info
if version_info >= (2,6,0):
    def swig_import_helper():
        from os.path import dirname
        import imp
        fp = None
	_mod = None
        try:
            fp, pathname, description = imp.find_module('_cmio', [dirname(__file__)])
        except ImportError:
            import _cmio
            return _cmio
        if fp is not None:
            try:
                _mod = imp.load_module('_cmio', fp, pathname, description)
            finally:
                fp.close()
                return _mod
    _cmio = swig_import_helper()
    del swig_import_helper
else:
Any idea on how to fix this please? thanks
Reply
#2
the indentation of this code doesn't look right, e.g lines 14-15.
Reply
#3
_mod = None that doesn't look needed at all. You immediately define it right before returning it, so setting it to None at the top of the function doesn't do anything.

That said, it says it's been generated by SWIG. Why not just regenerate it?
Reply
#4
Edit : ok i will try, thanks
Reply
#5
The last error was right before you imported _cmio. This error is saying _cmio is None, which means you didn't really fix the original error.

You shouldn't be editing this file. If it's not working, in it's original form, you should contact whoever wrote the package.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How does UnboundLocalError work? deanhystad 3 1,633 Feb-25-2022, 01:21 AM
Last Post: bowlofred
  UnboundLocalError: local variable 'wmi' referenced before assignment ilknurg 2 1,857 Feb-10-2022, 07:36 PM
Last Post: deanhystad
  exec + subprocess = UnboundLocalError paul18fr 6 3,443 Feb-04-2021, 06:27 AM
Last Post: Gribouillis
  UnboundLocalError: local variable 'figure_perso' referenced before assignment mederic39 2 2,229 Jun-11-2020, 12:45 PM
Last Post: Yoriz
  UnBoundLocalError Seaninho 3 2,622 May-31-2020, 07:22 AM
Last Post: azajali43
  UnboundLocalError: local variable referenced before assignment svr 1 3,261 Dec-27-2019, 09:08 AM
Last Post: perfringo
  UnboundLocalError: local variable ' ' referenced before assignment d3fi 10 5,433 Sep-03-2019, 07:22 PM
Last Post: buran
  'Exception Has occured: UnBoundLocalError' caston 1 2,417 Jun-12-2019, 02:33 PM
Last Post: perfringo
  UnboundLocalError Problem DrChicken24 1 2,186 Mar-27-2019, 02:53 AM
Last Post: ichabod801
  How to fix UnboundLocalError Tawnwen 5 5,272 Jan-07-2018, 05:38 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020