473,386 Members | 1,958 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,386 software developers and data experts.

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 2958

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

Similar topics

3
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
by: Justin Wong | last post by:
CREATE PROCEDURE dbo.Synchronization_GetNewRecords ( @item varchar(50), @last datetime ) AS SET NOCOUNT ON
4
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.