473,486 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Question about raw string and regex

I'm looking through the tools/scripts folder from the python install,
trying to get reacquanted with the language. Got a question on the
following classfix.py snippet:

# This expression doesn't catch *all* class definition headers,
# but it's pretty darn close.
classexpr = '^\([ \t]*class +[a-zA-Z0-9_]+\) *( *) *\(\(=.*\)?\):'
classprog = regex.compile(classexpr)

Since the classexpr isn't a raw string (not r prefix), doesn't the \t
get converted to a tab character before it gets to the regex compiler?

Mar 24 '06 #1
8 1672
Em Qui, 2006-03-23 Ã*s 17:11 -0800, jl*****@blarg.net escreveu:
Since the classexpr isn't a raw string (not r prefix), doesn't the \t
get converted to a tab character before it gets to the regex compiler?

print '^\([ \t]*class +[a-zA-Z0-9_]+\) *( *) *\(\(=.*\)?\):'

^\([ ]*class +[a-zA-Z0-9_]+\) *( *) *\(\(=.*\)?\):

Yes... maybe that's the intention?

--
Felipe.

Mar 24 '06 #2
I doubt it, although it might work anyway.

Here's another from the same program:

(a0, b0), (a1, b1), (a2, b2) = classprog.regs[:3]

Nothing in the Python lib reference on the regs attribute for regex
objects.

Mar 24 '06 #3
On 24/03/2006 12:36 PM, jl*****@blarg.net wrote:
I doubt it, although it might work anyway.
You could dispel all doubt in about 15 seconds flat were you to actually
try it out.
import regex __main__:1: DeprecationWarning: the regex module is deprecated; please
use the re module regex.match(r"[ \t]", "\t") -1 regex.match("[ \t]", "\t") 1 import re
re.match("[ \t]", "\t") <_sre.SRE_Match object at 0x00AE9058> re.match(r"[ \t]", "\t") <_sre.SRE_Match object at 0x00AE9918>


Here's another from the same program:

(a0, b0), (a1, b1), (a2, b2) = classprog.regs[:3]

Nothing in the Python lib reference on the regs attribute for regex
objects.


Dunno where you're looking, but my Python 1.5.2 has the regex docs,
which include a big fat note to the effect of the above
DeprecationWarning, plus documentation on the regs attribute.
Mar 24 '06 #4
Gotta love the attitude of people on .lang newsgroups....
The unraw '\t' might work, but all the example in the tutorial use raw
strings, so why not be consistent in the example scripts?

1.5.2? Aren't we at 2.4.2 now? So the regs documentation was pulled,
yet the source code shipped with the installer still uses it? How are
people suppose to make heads or tails of a language when it ships with
deprecated, undocumented code?

sheesh.

Mar 24 '06 #5
On 24/03/2006 2:57 PM, jl*****@blarg.net wrote:
Gotta love the attitude of people on .lang newsgroups....
The unraw '\t' might work, but all the example in the tutorial use raw
strings, so why not be consistent in the example scripts?
classfix.py is not an *example* script. It is (was!) a *tool* script.

1.5.2? Aren't we at 2.4.2 now? So the regs documentation was pulled,
yet the source code shipped with the installer still uses it?
You are missing the point. The whole *regex* module was deprecated
around 1.something. It was replaced by the *re* module. At some stage
the whole regex docs were "pulled". 1.5.2 is the latest version that I
have on my machine that still provided the docs for regex. The regs
attribute is documented there. When you said "Nothing in the Python lib
reference on the regs attribute for regex objects" you must have been
referring to the *re* documentation.
How are
people suppose to make heads or tails of a language when it ships with
deprecated, undocumented code?
Here is line 3 of classfix.py:
# This script is obsolete -- it is kept for historical purposes only.
sheesh.


Sheesh vobiscum :-)
Mar 24 '06 #6
jl*****@blarg.net wrote:
1.5.2? Aren't we at 2.4.2 now? So the regs documentation was pulled,
yet the source code shipped with the installer still uses it? How are
people suppose to make heads or tails of a language when it ships with
deprecated, undocumented code?
$ more classfix.py

# This script is obsolete -- it is kept for historical purposes only.
#
# Fix Python source files to use the new class definition syntax, i.e.,
# the syntax used in Python versions before 0.9.8:
# class C() = base(), base(), ...: ...
# is changed to the current syntax:
# class C(base, base, ...): ...

....

(if you don't understand that comment, it says that this is a conversion
script for converting code written for Python 0.9.8 to the current syntax,
which is left in there for historical purposes only)
Gotta love the attitude of people on .lang newsgroups....


I don't think the attitude problem is where you think it is...

</F>

Mar 24 '06 #7
> classfix.py is not an *example* script. It is (was!) a *tool* script.

I see. 2.4.2 includes a tool for modifying 0.9.8 python classes to 1.1
somthing format using a now-defunct regex module. Oh, okay. Very
useful, I can see why it would still be included as part of the
distribution.

I was using 'regex' as the general term for regular expressions, not
the module. I hadn't realized the (old, decrepit) script was using
something other than 're' (r standing for 'regular', and e for
'expressions' [I'm guessing]).

Pylint (with everything switched on) doesn't flag anything as
deprecated, or at least I didn't notice that it did. Maybe it was
because the method for deprecation hadn't been devised yet? -- I don't
know, as I'm not a Python archivist.

I don't think I missed line 3, but just interpeted it to apply to the
purpose of the script, not the script itself.

And, BTW, people will look at the source that's distributed with Python
for purposes of writing their own code, be it in tools, libs, or
whatever. They (should) serve as examples of current practice, IM(H)O.
Old cruft should go in a source archive to dwell in the shadows
forevermore.

Mar 24 '06 #8
I understood the comment, just misinterpreted the meaning of the first
statement.

And speaking of my attitude, it's just as bad as anyone else's here.
Double check the membership of the comp.lang.python set...

Mar 24 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
396
by: Du Dang | last post by:
Text: ===================== <script1> ***stuff A </script1> ***more stuff <script2> ***stuff B
3
1703
by: Sped Erstad | last post by:
There must be a simple regexp reason for this little question but it's driving me nuts. Below is a simple regexp to determine if a string contains only numbers. I'm running these two strings...
7
1412
by: Ioannis Vranos | last post by:
What is the difference among the following. Please correct me if I am wrong (this is not a homework, I am just checking System::Regex these days and have not figured out everything yet). "a*":...
1
1586
by: George Durzi | last post by:
Consider this excerpt from some HTML. (This is a copy from View->Source, except for the comment) <TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0 border=0> <?xml version="1.0" encoding="UTF-16"?>...
4
1793
by: Leon | last post by:
why is the following not correct in asp.net? I'm trying to match all subdomain names 'leon.domain.com', but not 'www.domain.com'? Dim sdm As Regex sdm = New Regex (?!www\.)(.*)\.domain\.com
8
1420
by: Leon | last post by:
My web application allow the user to enter the site by typing in a subdomain such as 'name.domain.com'. However, I want to retrieve just the 'name' part of the subdomain. see code below (the equal...
6
255
by: Craig Buchanan | last post by:
I have a string in the format "name" <address> that i would like to split into an array of two values. name should be the first value, address the second value. what does my regex pattern need to...
8
1808
by: vbmark | last post by:
I'm new to RegEx in vb.net so I'm not sure how to do this. I want to know if a string contains two minus signs "-". If there are two then I want it to return TRUE. I also need to know if the...
5
5076
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
6
3924
by: Sa¹o Zagoranski | last post by:
Hi, could someone help me putting together a regex expression for my problem? I need my search filter to treat spaces and commas in the query the same way no matter how many there are... ...
0
7123
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7305
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4863
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
259
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.