472,353 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Bug when using with_statement with exec

I think I'm going to create a new issue in Pythons issue database, but
I wanted to run it by the news group first. See if I can get any
useful feed back.

The following session demonstrates the issue:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>exec "def foo():\n return 0" # no ending newline works fine
foo()
0
>>exec "def foo():\n return 1\n" # with an ending newline works fine
foo()
1
>>from __future__ import with_statement
exec "def foo():\n return 2\n" # with an ending newline works fine
foo()
2
>>exec "def foo():\n return 3" # without an ending new line... breaks
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 2
return 3
^
SyntaxError: invalid syntax

If I create a function by using exec on a string and _don't_ end the
string with a new-line it will work just fine unless I "from
__future__ import with_statement". I can imagine that it is probably a
good practice to always end function body's with a new-line, but the
requirement should be consistent and the syntax error text could be a
_little_ more descriptive (and flag something other than the 2nd to
last character). Note that you don't need to be in the interpreter to
reproduce this issue.

I searched python's issue database and didn't see anything similar to
this. If there is already an issue related to this, please point me to
it... or better yet, let me know how you found it.

Matt
Jul 14 '08 #1
1 1287
On Mon, Jul 14, 2008 at 6:00 PM, Matimus <mc******@gmail.comwrote:
If I create a function by using exec on a string and _don't_ end the
string with a new-line it will work just fine unless I "from
__future__ import with_statement".
[snip]
I searched python's issue database and didn't see anything similar to
this. If there is already an issue related to this, please point me to
it... or better yet, let me know how you found it.
Possibly related to http://bugs.python.org/issue1184112, and/or
http://bugs.python.org/issue501622?

Since you asked, I found it by googling the words "python exec with
newline". The second item was an email on Python-Dev with a similar
bug and referencing an issue id. The comments on that issue led to
the other one.

--
Jerry
Jul 14 '08 #2

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

Similar topics

4
by: Andrew Crowe | last post by:
Hi guys, I'm using ImageMagick to do scaling / filtering to uploaded images by calling the following: exec("cmd.exe /c convert.exe -filters...
1
by: Rasjid Wilcox | last post by:
Hi, I found references on Google to a discussion a little while ago about using RestrictedPython instead of rexec and Bastion. But I've had...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the...
4
by: prasad | last post by:
I am getting sql error during binding a program which access a temporary table. The temporary table declaration and access methods are given below....
5
by: snicks | last post by:
I'm trying to exec a program external to my ASP.NET app using the following code. The external app is a VB.NET application. Dim sPPTOut As...
4
by: comp.lang.php | last post by:
I wrote my own version of memory_get_usage() if that function is not available: if (!function_exists('memory_get_usage')) { /** * Determine...
10
by: David C. Ullrich | last post by:
What version added decorators (using the @decorator syntax)? (Is there a general way I could have found out the answer myself?) Is there a...
0
by: Chris Rebert | last post by:
On Fri, Nov 14, 2008 at 10:40 AM, Indian <write2abdul@gmail.comwrote: You don't need and shouldn't be using `exec` here. It appears as though...
3
by: Shayco | last post by:
hey, in my code i'm using Runtime.getRuntime().exec() in order to run a .bat file that calls another java program (they communicate with each other...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...

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.