473,491 Members | 3,350 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Re: Don't understand syntax error: unqualified exec is not allowed ..

Stef Mientki wrote:
hello,

I've syntax error which I totally don't understand:

########## mainfile :
import test_upframe2

if __name__ == '__main__':
var1 = 33
code = 'print var1 + 3 \n'
test_upframe2.Do_Something_In_Parent_NameSpace ( code )

########### file = test_upframe2 :
class Do_Something_In_Parent_NameSpace ( object ) :
def __init__ ( self, code ) :
def do_more ( ) :
nonvar = [3,4]
while len ( nonvar ) 0 : # <<<===
nonvar.pop() # <<<===
Indendation is screwed. Is the above all do_more body?
import sys
p_locals = sys._getframe(1).f_locals
Which locals does this get you? __init__'s? (locals()?)
p_globals = sys._getframe(1).f_globals
Isn't this just the same as globals()?
try :
exec ( code, p_globals, p_locals )
This is 3.0 exec function syntax. Postings should specify which
interpreter you are running, especially when mucking with
internals.
except :
print 'ERROR'
gives me:
SyntaxError: unqualified exec is not allowed in function '__init__' it
contains a nested function with free variables (gui_support.py, line
408)
"unqualified exec" : I thought that meant there is some ambiguity in the
namespace, but I explictly definied the namespace

The function "do_more" is never called, so what does it matter what's
in there ?

If I remove the while-loop (which of course I can't) the syntax error
disappears.

I can place the function either as a class method or as a normal
function outside the class,
which both works well.
But I want the method / function not to be hidden.
Since you are hiding it, I presume you mean to be, not not to be.
>
Why does the above syntax error appear ?
Are there other ways to hide the function ?
Either use module level __all__ or name the function _do_more and anyone
will know it is private to the module.

Oct 20 '08 #1
0 2969

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

Similar topics

3
3931
by: kepes.krisztian | last post by:
Hi ! In Unifying types and classes in Python 2.2 article I see that: >>> print a # show the result
1
38563
by: Justin Wong | last post by:
CREATE PROCEDURE dbo.Synchronization_GetNewRecords ( @item varchar(50), @last datetime ) AS SET NOCOUNT ON
4
22032
by: matt hegarty | last post by:
Hi I am relatively new to XML, but am having problems with a validation issue. When the XML is parsed and validated using Xerces, the following error is seen: cvc-complex-type.3.2.2:...
6
2440
by: Ivan Shevanski | last post by:
Here's a noob question for everyone (I'm not sure if my first message got through, is had a "suspicious header" so sorry for double post is so), is there a way to turn off syntax warnings or just...
1
11214
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." ...
127
5369
by: bz800k | last post by:
Hi Does this code satisfy ANSI C syntax ? void function(void) { int a = 2; a = ({int c; c = a + 2;}); /* <<-- here !! */ printf("a=%d\n", a);
4
3559
by: gregpinero | last post by:
It's the strangest thing, I'm pulling some text out of a MySQL table and trying to run exec on it, and it keeps giving me a syntax error, always at the end of the first line. Thanks in advance...
2
1488
by: sva0008 | last post by:
I am writing a dynamic query insert into Tablename select '1111', name,address,phone,'1111', exec usp_storedProcedureName '1111', '1111', 'KA','EA' from edi856Item where autoid = '1111'I dont...
0
1769
by: Stef Mientki | last post by:
hello, I've syntax error which I totally don't understand: ########## mainfile : import test_upframe2 if __name__ == '__main__': var1 = 33 code = 'print var1 + 3 \n'
0
320
by: Stef Mientki | last post by:
Terry Reedy wrote: sorry, don't know how this happened, as I always copy/paste ? AFAIK locals() == sys._getframe(0).f_locals AFAIK, again one level up weird, I use it in 2.5 and if I remember...
0
7157
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
7192
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
6862
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
7364
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...
0
5452
agi2029
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,...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
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 ...
1
637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
282
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.