Slightly off topic, i know, but here goes:
I'm trying to xlate a module of mine to C++. Only problem is, it makes
heavy use of "setattr". Anyone know a straightforward way to do
"setattr" in C++ ?
thanks,
Eric 3 2712
Eric wrote: Slightly off topic, i know, but here goes:
I'm trying to xlate a module of mine to C++. Only problem is, it makes heavy use of "setattr". Anyone know a straightforward way to do "setattr" in C++ ?
Thinking about what setattr() does, and about how C++ works, I suspect
there is no straightforward way. There _might_ be some existing library
for introspection that can do something resembling what you want.
Think about it: setattr() uses the names of arbitrary (possibly
non-existing, but of course you can't solve that in C++ at all)
attributes that are contained in strings. That means the resolution is
done at run-time. In C++, on the other hand, all the names pretty much
vanish at compile-time, so unless you prepare mappings of some kind
ahead of time, or have a package which can read dynamically from header
files or something, you're plain screwed. AFAICS.
-Peter
Eric <er**@lentil.co m> wrote in message news:<87******* *****@subopt.au stin.rr.com>... Slightly off topic, i know, but here goes:
I'm trying to xlate a module of mine to C++. Only problem is, it makes heavy use of "setattr". Anyone know a straightforward way to do "setattr" in C++ ?
No, but there's a workaround.
Instead of referring to the fields of an object as, for example, x.foo
and x.bar, store your object's data in a hash table with "foo" and
"bar" as keys. da*****@yahoo.c om (Dan Bishop) writes: Eric <er**@lentil.co m> wrote in message news:<87******* *****@subopt.au stin.rr.com>... Slightly off topic, i know, but here goes:
I'm trying to xlate a module of mine to C++. Only problem is, it makes heavy use of "setattr". Anyone know a straightforward way to do "setattr" in C++ ?
No, but there's a workaround.
Instead of referring to the fields of an object as, for example, x.foo and x.bar, store your object's data in a hash table with "foo" and "bar" as keys.
You could even store the hash table as a __dict__ instance variable in
your C++ object. And use a PyDict_Object instead of the has table.
;-)
Thomas This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Daniel Klein |
last post by:
Hello,
I'm quite new to Python, and since a not-so-superficial look into the
docs didn't answer my question (although it still feels quite basic), I
decided to turn to this place:
Is there a way to 'extract' a dictionary into the current namespace?
That is, if you have
{'foo' : 23, 'bar' : 42}
you would get a variable foo with value 23 and a variable bar with value
|
by: Anthony Baxter |
last post by:
To go along with the 2.4a3 release, here's an updated version of
the decorator PEP. It describes the state of decorators as they
are in 2.4a3.
PEP: 318
Title: Decorators for Functions and Methods
Version: $Revision: 1.34 $
Last-Modified: $Date: 2004/09/03 09:32:50 $
Author: Kevin D. Smith, Jim Jewett, Skip Montanaro, Anthony Baxter
|
by: Noam Raphael |
last post by:
Hello,
I thought about a new Python feature. Please tell me what you think
about it.
Say you want to write a base class with some unimplemented methods, that
subclasses must implement (or maybe even just declare an interface, with
no methods implemented). Right now, you don't really have a way to do
it. You can leave the methods with a "pass", or raise a
NotImplementedError, but even in the best solution that I know of,
|
by: Jim Hill |
last post by:
I've done some Googling around on this and it seems like creating a here
document is a bit tricky with Python. Trivial via triple-quoted strings
if there's no need for variable interpolation but requiring a long, long
formatted arglist via (%s,%s,%s,ad infinitum) if there is. So my
question is:
Is there a way to produce a very long multiline string of output with
variables' values inserted without having to resort to this wacky
"""v...
|
by: Paul D.Smith |
last post by:
Can Python create a variable "on-the-fly". For example I would like
something like...
make_variable('OSCAR', 'the grouch');
print OSCAR;
....to output...
the grouch
| |
by: samjnaa |
last post by:
Please check for sanity and approve for posting at python-dev.
In Visual Basic there is the keyword "with" which allows an object-
name to be declared as governing the following statements. For
example:
with quitCommandButton
.enabled = true
.default = true
end with
|
by: WaterWalk |
last post by:
I've just read an article "Building Robust System" by Gerald Jay
Sussman. The article is here:
http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf
In it there is a footprint which says:
"Indeed, one often hears arguments against building exibility into an
engineered sys-
tem. For example, in the philosophy of the computer language Python it
is claimed:
\There should be one|and preferably only one|obvious...
|
by: mfglinux |
last post by:
Hello to everybody
I would like to know how to declare in python a "variable name" that
it is in turn a variable
In bash shell I would wrote sthg like:
for x in `seq 1 3`
do
M$i=Material(x) #Material is a python class
done
|
by: akonsu |
last post by:
hello,
i need to add properties to instances dynamically during run time.
this is because their names are determined by the database contents.
so far i found a way to add methods on demand:
class A(object) :
def __getattr__(self, name) :
if name == 'test' :
def f() : return 'test'
|
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: 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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |