473,396 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Altering the namespace of the calling function

Hi,

First off I know that in almost all cases this would be a terrible thing to
do, but this is an unusual case where this makes sense.

Basically I have a procedure where you pass a string containting a template
for a tuple, the function then finds a tuple that matches this template and
then returns it. The template may contain variable names, which match
against anything in that position in the tuple - this is all working fine,
except that I would like a variable to be created in the caller's scope by
the matching function.

I can retrieve the scope of the calling function using
sys._getframe(1).f_locals however whenever I try to modify it the changes
are made but the variable doesn't match to the new variable in the scope. I
tried creating a variable of the same name before calling the matching
function, but when the matching function returns the changes to the scope
for that variable are discarded.

Can anyone suggest how to make this work?
Andrew Wilkinson

Jul 18 '05 #1
1 2140
Andrew Wilkinson asks:
except that I would like a variable to be created in the caller's scope by
the matching function.
Pass in a mutable or use return. The obvious intent is to use this in the
calling routine, and you're asking how to change the called routine, so
you've got access to both.

I can retrieve the scope of the calling function using
sys._getframe(1).f_locals however whenever I try to modify it the changes
are made but the variable doesn't match to the new variable in the scope. I

No surprise here. From the manual:
"The contents of this dictionary should not be modified; changes may not
affect the values of local variables used by the interpreter. "

tried creating a variable of the same name before calling the matching
function, but when the matching function returns the changes to the scope
for that variable are discarded.

Can anyone suggest how to make this work?


If both routines are within the same global module scope, you could use
global. If not, you could hang shared variables on a mutually imported
module.

HTH,

Emile van Sebille
em***@fenx.com

Jul 18 '05 #2

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

Similar topics

8
by: Elaine Jackson | last post by:
I would like to be able to write a function f, which will live in a module M, and will call a function g, such that, when f is imported from M into the interpreter, and invoked there, its...
7
by: vegetax | last post by:
I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj()...
2
by: Karthik Kumar | last post by:
Hi, I was writing this application that used namespaces. The structure of the file was as follows. //Header file #ifndef MYNS_MYHEADER_H #define MYNS_MYHEADER_H
4
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which...
30
by: Pep | last post by:
Is it best to include the code "using namespace std;" in the source or should each keyword in the std namespace be qualified by the namespace tag, such as std::cout << "using std namespace" <<...
3
by: Frederick Gotham | last post by:
Back in the day, if you wanted a function to be self-contained within a translation unit, you defined the function as "static". If there were an external linkage function by the same name...
2
by: Safalra | last post by:
The problem below is obviously some sort of namespace clash, but I don't understand exactly why - can anyone explain? Take the following simple Javascript code: <script type="text/javascript">...
9
by: JimmyKoolPantz | last post by:
IDE: Visual Studio 2005 Language: VB.NET Fox Pro Driver Version: 9.0.0.3504 Problem: I currently have a problem altering a DBF file. I do not get any syntax errors when running the program. ...
12
by: Taras_96 | last post by:
Hi everyone, AFAIK external linkage allows you to refer to variables/functions outside of the current translation unit. A variable in an unnamed namespace is similar to declaring a static...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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
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...

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.