The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by kdpao]

I'm having a problem getting re methods to work in JPython. I've tried the
example on pages 238-239 without success. My co-worker was able to use it in
CPython, but his code will not work for me. In each case I get a
malformedPatternException at the Java level. Do I have to import more than
just the re module?
import-bot (20211) [Avatar] Offline
#2
Re: regular expressions with jpython
[Originally posted by daryl harms]

> I'm having a problem getting re methods to work in JPython. I've tried the
> example on pages 238-239 without success. My co-worker was able to use it in
> CPython, but his code will not work for me. In each case I get a
> malformedPatternException at the Java level. Do I have to import more than
> just the re module?

Hi Karim,

The re module is all you should need.
However, if you try to type or enter the examples directly into the Jython
command line interpreter you will run into the following Jython bug:

-----------------------------------------------------------------------------
http://sourceforge.net/bugs/?func=detailbug&bug_id=122805&group_id=12867


[ Bug #122805 ] multi-line statements in the JPython interpreter
Date:
2000-Nov-18 11:04
Submitted By:
bckfnn Assigned To:
nobody
Category:
Core Priority:
1
Bug Group:
None Resolution:
None
Summary:
multi-line statements in the JPython interpreter
Original Submission:
The following kinds of multi-line statements work if written in
an imported module:

s = (
'Hello, world.'
)

s =
'Hello, world.'

i = (
3+ 4
}

i =
3 + 4

All of them fail in the JPython interpreter as soon as the first line is typed
in.

Is multi-line functionality supposed to be supported in the interactive
interpreter?

JPython 1.1beta2 on java1.2.1
Copyright (C) 1997-1999 Corporation for National Research Initiatives
>>>
>>> s = (
Traceback (innermost last):
(no code object) at line 0
File "<console>", line 1
SyntaxError: invalid syntax
>>> s =
Traceback (innermost last):
(no code object) at line 0
File "<console>", line 1
SyntaxError: invalid syntax
>>>
-----------------------------------------------------------

Until this is fixed, the split of "regexp" across multiple lines (as in the
examples on page 237 and 23smilie will not work if you type it in directly to the
interpreter. These examples should work, however if you save them to a file
and import this file as a module.

Note also that this bug will cause problems with other examples in the book as
well. It also is a little less general than stated in the report as some forms
of multiple line statement do work (i.e. those where a line would be a valid
python expression on its own).

Daryl