Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

re

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


michael_armbruster at eu

Oct 17, 2001, 1:37 AM

Post #1 of 9 (124 views)
Permalink
re

Hi Oleg,

could you please tell me, what I would have to do
with the dos extender.
My aim is to boot pc with dos by FD. Then
I have to execute the built standalone app.

Could you imagine that this would be possible
with the DOS extender?

Mike

-----Original Message-----
From: Oleg Broytmann [mailto:phd[at]phd.pp.ru]
Sent: Wednesday, October 17, 2001 10:26 AM
To: Michael Armbruster
Cc: python-list[at]python.org
Subject: Re: pure 16-bit DOS app


On Wed, Oct 17, 2001 at 10:17:12AM +0200, Michael Armbruster wrote:
> I read many articles in the grup and the web, but till now I have not
found
> the real solution for my problem.
> I would like to have a pure standalone DOS 16-bit app built out of
> a python prog with inserted c-code but I don't know how to do this.
> perhaps you could help me,

Near to be impossible. 16bit DOS just doesn't have enough memory for
Python. Can you use 32bit DOS (DOS Extender)?

Oleg.
--
Oleg Broytmann http://phd.pp.ru/ phd[at]phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.


loewis at informatik

Oct 17, 2001, 7:16 AM

Post #2 of 9 (121 views)
Permalink
re [In reply to]

"Michael Armbruster" <michael_armbruster[at]eu.exch.agilent.com> writes:

> could you please tell me, what I would have to do
> with the dos extender.
> My aim is to boot pc with dos by FD. Then
> I have to execute the built standalone app.
>
> Could you imagine that this would be possible
> with the DOS extender?

You need a compiler that supports DOS extenders, such as djgpp. Then,
your entire program would a be 32-bit executable (and thus require a
386, minimum). The DOS extender would be either incorporated into your
DOS program, or be shipped along with the main application.

If you want to compile Python on your own as a 16-bit application,
good luck. There are old MSVC 1.5 makefiles to build a 16-bit Windows
application, maybe they can be of use. I'd rather recommend that you
look for a Python 1.2 or so source distribution: Don't worry about the
features you lose, since you couldn't use them in 640k, anyway.

Regards,
Martin


dullrich at sprynet

Jun 4, 2008, 9:21 AM

Post #3 of 9 (107 views)
Permalink
Re: re [In reply to]

Actually using regular expressions for the first
time. Is there something that allows you to take the
union of two character sets, or append a character to
a character set?

Say I want to replace 'disc' with 'disk', but only
when 'disc' is a complete word (don't want to change
'discuss' to 'diskuss'.) The following seems almost
right:

[^a-zA-Z])disc[^a-zA-Z]

The problem is that that doesn't match if 'disc' is at
the start or end of the string. Of course I could just
combine a few re's with |, but it seems like there should
(or might?) be a way to simply append a \A to the first
[^a-zA-Z] and a \Z to the second.

--
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

Jun 4, 2008, 9:52 AM

Post #4 of 9 (106 views)
Permalink
Re: re [In reply to]

David C. Ullrich schrieb:
> Actually using regular expressions for the first
> time. Is there something that allows you to take the
> union of two character sets, or append a character to
> a character set?
>
> Say I want to replace 'disc' with 'disk', but only
> when 'disc' is a complete word (don't want to change
> 'discuss' to 'diskuss'.) The following seems almost
> right:
>
> [^a-zA-Z])disc[^a-zA-Z]
>
> The problem is that that doesn't match if 'disc' is at
> the start or end of the string. Of course I could just
> combine a few re's with |, but it seems like there should
> (or might?) be a way to simply append a \A to the first
> [^a-zA-Z] and a \Z to the second.

Why not

($|[\w])disc(^|[^\w])

I hope \w is really the literal for whitespace - might be something
different, see the docs.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


russblau at hotmail

Jun 4, 2008, 10:02 AM

Post #5 of 9 (109 views)
Permalink
Re: re [In reply to]

"Diez B. Roggisch" <deets[at]nospam.web.de> wrote in message
news:6anvi4F38ei08U1[at]mid.uni-berlin.de...
> David C. Ullrich schrieb:
>> Say I want to replace 'disc' with 'disk', but only
>> when 'disc' is a complete word (don't want to change
>> 'discuss' to 'diskuss'.) The following seems almost
>> right:
>>
>> [^a-zA-Z])disc[^a-zA-Z]
>>
>> The problem is that that doesn't match if 'disc' is at
>> the start or end of the string. Of course I could just
>> combine a few re's with |, but it seems like there should
>> (or might?) be a way to simply append a \A to the first
>> [^a-zA-Z] and a \Z to the second.
>
> Why not
>
> ($|[\w])disc(^|[^\w])
>
> I hope \w is really the literal for whitespace - might be something
> different, see the docs.

No, \s is the literal for whitespace.
http://www.python.org/doc/current/lib/re-syntax.html

But how about:

text = re.sub(r"\bdisc\b", "disk", text_to_be_changed)

\b is the "word break" character, it matches at the beginning or end of any
"word" (where a word is any sequence of \w characters, and \w is any
alphanumeric
character or _).

Note that this solution still doesn't catch "Disc" if it is capitalized.

Russ



--
http://mail.python.org/mailman/listinfo/python-list


dullrich at sprynet

Jun 4, 2008, 10:24 AM

Post #6 of 9 (106 views)
Permalink
Re: re [In reply to]

In article <6anvi4F38ei08U1[at]mid.uni-berlin.de>,
"Diez B. Roggisch" <deets[at]nospam.web.de> wrote:

> David C. Ullrich schrieb:
> > Actually using regular expressions for the first
> > time. Is there something that allows you to take the
> > union of two character sets, or append a character to
> > a character set?
> >
> > Say I want to replace 'disc' with 'disk', but only
> > when 'disc' is a complete word (don't want to change
> > 'discuss' to 'diskuss'.) The following seems almost
> > right:
> >
> > [^a-zA-Z])disc[^a-zA-Z]
> >
> > The problem is that that doesn't match if 'disc' is at
> > the start or end of the string. Of course I could just
> > combine a few re's with |, but it seems like there should
> > (or might?) be a way to simply append a \A to the first
> > [^a-zA-Z] and a \Z to the second.
>
> Why not
>
> ($|[\w])disc(^|[^\w])
>
> I hope \w is really the literal for whitespace - might be something
> different, see the docs.

Thanks, but I don't follow that at all.

Whitespace is actually \s. But [\s]disc[whatever]
doesn't do the job - then it won't match "(disc)",
which counts as "disc appearing as a full word.

Also I think you have ^ and $ backwards, and there's
a ^ I don't understand. I _think_ that a correct version
of what you're suggesting would be

(^|[^a-zA-Z])disc($|[^a-zA-Z])

But as far as I can see that simply doesn't work.
I haven't been able to use | that way, combining
_parts_ of a re. That was the first thing I tried.
The original works right except for not matching
at the start or end of a string, the thing with
the | doesn't work at all:

>>> test = compile(r'(^|[^a-zA-Z])disc($|[^a-zA-Z])')
>>> test.findall('')
[]
>>> test.findall('disc')
[('', '')]
>>> test.findall(' disc ')
[(' ', ' ')]
>>> disc = compile(r'[^a-zA-Z]disc[^a-zA-Z]')
>>> disc.findall(' disc disc disc')
[' disc ']
>>> disc.findall(' disc disc disc')
[' disc ', ' disc ']
>>> test.findall(' disc disc disc')
[(' ', ' '), (' ', ' ')]
>>> disc.findall(' disc disc disc')
[' disc ', ' disc ']
>>> disc.findall(' disc disc disc ')
[' disc ', ' disc ', ' disc ']


> Diez

--
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


deets at nospam

Jun 4, 2008, 11:07 AM

Post #7 of 9 (107 views)
Permalink
Re: re [In reply to]

> Whitespace is actually \s. But [\s]disc[whatever]
> doesn't do the job - then it won't match "(disc)",
> which counts as "disc appearing as a full word.

Ok, then this works:

import re

test = """
disc
(disc)
foo disc bar
discuss
""".split("\n")

for t in test:
if re.search(r"(^|[^\w])(disc)($|[^\w])", t):
print "success:", t


> Also I think you have ^ and $ backwards, and there's
> a ^ I don't understand. I _think_ that a correct version

Yep, sorry for the confusion.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


dullrich at sprynet

Jun 4, 2008, 2:39 PM

Post #8 of 9 (96 views)
Permalink
Re: re [In reply to]

In article <mailman.79.1212598994.1044.python-list[at]python.org>,
"Russell Blau" <russblau[at]hotmail.com> wrote:

> "Diez B. Roggisch" <deets[at]nospam.web.de> wrote in message
> news:6anvi4F38ei08U1[at]mid.uni-berlin.de...
> > David C. Ullrich schrieb:
> >> Say I want to replace 'disc' with 'disk', but only
> >> when 'disc' is a complete word (don't want to change
> >> 'discuss' to 'diskuss'.) The following seems almost
> >> right:
> >>
> >> [^a-zA-Z])disc[^a-zA-Z]
> >>
> >> The problem is that that doesn't match if 'disc' is at
> >> the start or end of the string. Of course I could just
> >> combine a few re's with |, but it seems like there should
> >> (or might?) be a way to simply append a \A to the first
> >> [^a-zA-Z] and a \Z to the second.
> >
> > Why not
> >
> > ($|[\w])disc(^|[^\w])
> >
> > I hope \w is really the literal for whitespace - might be something
> > different, see the docs.
>
> No, \s is the literal for whitespace.
> http://www.python.org/doc/current/lib/re-syntax.html
>
> But how about:
>
> text = re.sub(r"\bdisc\b", "disk", text_to_be_changed)
>
> \b is the "word break" character,

Lovely - that's exactly right, thanks. I swear I looked at the
docs... I'm just blind or stupid. No wait, I'm blind _and_
stupid. No, blind and stupid and slow...

Doesn't precisely fit the _spec_ because of digits and underscores,
but it's close enough to solve the problem exactly. Thanks.

>it matches at the beginning or end of any
> "word" (where a word is any sequence of \w characters, and \w is any
> alphanumeric
> character or _).
>
> Note that this solution still doesn't catch "Disc" if it is capitalized.

Thanks. I didn't mention I wanted to catch both cases because I
already knew how to take care of that:

r"\b[dD]isc\b"

> Russ

--
David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list


dullrich at sprynet

Jun 5, 2008, 5:58 AM

Post #9 of 9 (94 views)
Permalink
Re: re [In reply to]

On Wed, 04 Jun 2008 20:07:41 +0200, "Diez B. Roggisch"
<deets[at]nospam.web.de> wrote:

>> Whitespace is actually \s. But [\s]disc[whatever]
>> doesn't do the job - then it won't match "(disc)",
>> which counts as "disc appearing as a full word.
>
>Ok, then this works:

Yes it does.

My real question was why doesn't a construction like

(A|B)C

work as expected. The code below shows that it does.
That puzzled me because I couldn't see any real
difference between your solution here and things
I'd tried that didn't work. But those things also
work in the code below - when I saw this just
now I was even more confused...

Oh. Turns out the actual reason for the confusion wasn't
regex syntax, it was the fact that findall doesn't
return what I thought it did - looking at the result
of findall() it seemed as thought the re was matching
empty strings and whitespace... Looking more
carefully at what findall is supposed to do everything
makes sense.

Sorry to be dense. Remind me to read more than the
first sentence next time:

"findall (pattern, string)
Return a list of all non-overlapping matches of pattern in string.
If one or more groups are present in the pattern, return a list of
groups;..."

>import re
>
>test = """
>disc
>(disc)
>foo disc bar
>discuss
>""".split("\n")
>
>for t in test:
> if re.search(r"(^|[^\w])(disc)($|[^\w])", t):
> print "success:", t
>
>
>> Also I think you have ^ and $ backwards, and there's
>> a ^ I don't understand. I _think_ that a correct version
>
>Yep, sorry for the confusion.
>
>Diez

David C. Ullrich
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.