Hi,
sorry if this is a faq. I've searched and got no result. I'm willing
to pass a custom object to re.search method, but I'm getting the
error:
TypeError: expected string or buffer
I don't want to make my object to inherit from basestring (nor I know
how to do it...). Then I was left with 'buffer'. I tried to make my
object inherit from types.BufferTyp e and got the error:
TypeError: Error when calling the metaclass bases
type 'buffer' is not an acceptable base type
If I call the function buffer passing an instance of my object I get:
TypeError: buffer object expected
Is it possible to make what I want (to pass a custom object to
re.search)?
regards,
Bruno 4 1542
<br************ ***@gmail.comwr ote:
Is it possible to make what I want (to pass a custom object to
re.search)?
Try to implement __str__() for your object and provide a string
representation for it.
re.search(str(c ustom_object))
--
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair
Try to implement __str__() for your object and provide a string
representation for it.
re.search(str(c ustom_object))
I've done that (and added __unicode__ too). I only didn't want to, I
want to do:
re.search(custo m_object)
so, code that worked before as:
re.search(paren tobj.custom_obj ect)
don't have to be changed for:
re.search(str(p arentobj.custom _object))
and I'm also curious to know if it is possible to do that... :-)
<br************ ***@gmail.comwr ote:
and I'm also curious to know if it is possible to do that... :-)
Only if re.search() doesn't check for the type of the argument, which it
seems it does.
--
Lawrence, oluyede.org - neropercaso.it
"It is difficult to get a man to understand
something when his salary depends on not
understanding it" - Upton Sinclair br************* **@gmail.com wrote:
I've done that (and added __unicode__ too). I only didn't want to, I
want to do:
re.search(custo m_object)
so, code that worked before as:
re.search(paren tobj.custom_obj ect)
don't have to be changed for:
re.search(str(p arentobj.custom _object))
and I'm also curious to know if it is possible to do that... :-)
Not without monkeypatching the re module:
import re
_original_compi le = re._compile
def _wrapped_compil e(*key):
try:
custom_compile = key[0].__compile__
except AttributeError:
return _original_compi le(*key)
else:
return custom_compile( *key[1:])
re._compile = _wrapped_compil e
class Aaa(object):
def __compile__(sel f, *args):
return re.compile("[Aa]+")
print re.findall(Aaa( ), "a yadda so whaaaat")
Peter This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Michael ALbanese |
last post by:
I am developing a telephone directory for my company.
I have Fist Name, Last Name, Department and Phone Number
as fields. A user can search by entering data into any
one, or combination of these fields.
I have been trying to write a custom validation control
that will test each of the textboxes and reject the
request if they are ALL blank.
|
by: Steve |
last post by:
All --
This occasionally happens, and there's no set pattern on why this
is... perhaps it happens a few times every few months or so.
I have a custom ATL COM object that handles data from multiple pages
and sites on my server. Occasionally, I'll get the following errors:
ASP_0241|CreateObject_Exception|-|ASP_0241|CreateObject_Exception|42|ASP_0177_:_c0000005|Server.CreateObject_Failed
500
|
by: Srini |
last post by:
Hi,
I am working on a project and a portion of which involves
receiving xml files on internet, extract values to build a
string and pass that string to legacy system.
I am planning on using XMLReader to read passed xml file
and extract values that need to be mapped to string
buffer. However, in this method I am not able to get the
full path (ie., path information from root to this node)
|
by: Todd Schinell |
last post by:
Back in July, Jeffery Tan posted this:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=OWOTdf0VDHA.2296%40cpmsftngxa06.phx.gbl
In response as to how to get click events from a user control to
invoke a method in the parent form.
This code doesn't seem to work for me, I've tried it a number of times
with very simple test cases (A user control with a single button and a
parent form with a single text box) and it always...
|
by: Whoever |
last post by:
Here's what I have
A custom collection:
public class aUser {
public string UserName { get {...} set {...}
}
public class UserList : System.Collection.CollectionBase {
public void Add(aUser user) {...}
public aUser this {...}
| |
by: rdcpro |
last post by:
Hi all,
I've been building a nifty deserializing configuration handler that I use in
conjunction with my web.config in an ASP.NET web app. This is working quite
well, but I'm planning on servicing a number of different web service
operations from a single application, and because it's all XML, I've been
scoping everything to a specific namespace targeting a specific application
(these are all InfoPath forms).
It seems that the...
|
by: klynn |
last post by:
I'm wondering what the best way to do the following:
I have a page with a table. I built a custom class that creates a
System.Web.UI.WebControls table object and return it to the webpage as a
property. But its not reading the table correctly. It doesnt see the
tablerows and tablecell objects.
First, I'm not sure why its not reading the table properly?
Second, I wonder if there's a better way to do this? Maybe a custom control?
I haven't...
|
by: Glenn |
last post by:
Hello
Is it possible to pass arguements to a .net service once it is in a
running state.
If this is not possible , are they alternative ways in which to achive
the same thing?
Glenn
|
by: Val |
last post by:
I have a complex object that I need to serialize. Rather than rely on a
standard routine, which is called during the serialization/deserialization, I
would like to be able to use my own functions that would convert this object
into a string and would then write that string to a file. Upon
deserialization, I need to be able to call another custom function to
recreate the object.
I have looked and both implementing the ISerializable...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |