2

Error:

Exception Value:     bad character range
Exception Location:  /usr/lib/python2.6/re.py in _compile, line 245
Python Executable:   /usr/bin/python

I have absolutely no idea what this means. Can anyone hazard a guess or point me in the right direction?

It was all working fine before.. I've only changed a few trivial bits of code! :S

if "-" in stop:
    dt1 = datetime.strptime(stop, "%Y-%m-%dT%H:%M:%S")
    stopInS = time.mktime(dt1.timetuple())
    stopInMS = int(startInS) * 1000
else:
    splitter = re.compile(r'[\D]')
    preStop = splitter.split(stop)
    stopInMS = ''.join(preStop)

I was merely playing around with the double quotes before the 'in'... then the whole thing collapsed with this error.

EDIT:

Another regex present:

    splitter1 = re.compile('[:]')
    arrayOfIDs = splitter1.split(identifier)
    idLens = len(arrayOfIDs)
Federer
  • 33,677
  • 39
  • 93
  • 121
  • And what would those bits of code be? – Dominic Rodger Oct 06 '09 at 15:04
  • I have no idea, it's not telling me the line of code it doesn't like? re.py is a Python module isn't it? – Federer Oct 06 '09 at 15:08
  • Yes - you said in the question that you've only changed a few trivial bits of code - I was wondering what those bits were. Are you using regular expressions anywhere? If so, post the bits of your code explicitly using regular expressions. If you're not explicitly using regular expressions, then I *think* that error could be down to a bad url pattern, but I may be wrong. – Dominic Rodger Oct 06 '09 at 15:11
  • 'Stop' is something that's being brought into the method via the URL. It's basically a stop time that I'm checking. I handle two date formats. If it contains the dash, then i'll handle that, otherwise if it doesn't then it's another type of data format that i'll handle differently. – Federer Oct 06 '09 at 15:23
  • That's why I'm so confused, Steven. The 'exception location' is referring to line 245 in re.py (not made by me obviously!!). The method I was editing was in a View.py. I'm completely perplexed. – Federer Oct 06 '09 at 15:31
  • What is the regular expression '[\D]' supposed to search for (in your words)? – Steven Oct 06 '09 at 16:07
  • 1
    @myusername - if you want a regex that accepts anything, you probably want `.*` (posting here so hopefully you'll get notified that I've responded to the comment you put on my answer). – Dominic Rodger Oct 08 '09 at 12:29

1 Answers1

7

The exception you're getting is because Python's re.py module can't compile a regular expression somewhere, because you've got a bad character range.

Character ranges are things like [a-z0-9] (accepts a lower-case letter or number).

For example:

import re
re.compile('[a-0]')

raises the bad character range exception you're getting. Look for somewhere you're creating a character range that doesn't make sense (it's not [:], that compiles fine).

Dominic Rodger
  • 97,747
  • 36
  • 197
  • 212
  • Actually, I just tested compiling `r'[\D]'` and it compiles. Any other regexs around? – Dominic Rodger Oct 06 '09 at 15:36
  • And does the error go away if you remove that line and set `stopInMS` to some benign value? – Dominic Rodger Oct 06 '09 at 15:37
  • Thanks a lot! This pretty much fixed the problem (and my own stupidity!). Another quick question for you... is there a regular expression that accepts everything(to go in the urls.py for another one of my project)? – Federer Oct 07 '09 at 07:36