Issue 3192: exec(open(filename)) doesn't work (original) (raw)

Created on 2008-06-24 20:45 by ms, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (8)
msg68700 - (view) Author: Mike Speciner (ms) Date: 2008-06-24 20:45
In 2.5, exec(open(filename)), where filename refers to a file with python code, executes the code. In 2.5, open returns an open file, but in 3.0, open returns a stream, and so exec (which wants "a string, file, or code object, not TextIOWrapper") returns an error. exec should probably be able to handle a stream.
msg68701 - (view) Author: Leif Walsh (leif.walsh) Date: 2008-06-24 21:00
There's 'execfile' in Lib/idlelib/PyShell.py...I'm looking for others. There is also a class of functions 'exec*' (and a related class, 'spawn*') in Lib/os.py that claims to do just what you want, but replacing the current process (or, in spawn*'s case, in a new thread). That said, I agree that exec should handle streams, and if you could give me a heads up as to where the code is for exec(), I could try my hand at a patch.
msg68702 - (view) Author: Mike Speciner (ms) Date: 2008-06-24 22:05
I'm actually quite new to Python. My current interpreter of choice is PostScript, followed by Matlab, but I've been discouraged from using either one here at EMC. (PostScript because it's obscure, Matlab because it's expensive!) Meanwhile, I'm on a wintel machine, making perusing the Python source tree difficult. So I'm not going to be much help in that regard. By the way, I was told that execfile is gone from python 3. --ms
msg68703 - (view) Author: Leif Walsh (leif.walsh) Date: 2008-06-24 22:08
On Tue, Jun 24, 2008 at 3:05 PM, Mike Speciner <report@bugs.python.org> wrote: > By the way, I was told that execfile is gone from python 3. It certainly isn't in the branch I just checked out.
msg68704 - (view) Author: Leif Walsh (leif.walsh) Date: 2008-06-24 22:09
(isn't gone, that is)
msg68705 - (view) Author: Mike Speciner (ms) Date: 2008-06-24 22:33
Well, I think I found exec in bltinmodule.c, but execfile isn't in that file. [In the 3.0 tree.]
msg68708 - (view) Author: Leif Walsh (leif.walsh) Date: 2008-06-24 22:56
execfile is in Lib/idlelib/PyShell.py, and is an instance function, so it's not really standard for regular code, and would also be hard to use correctly. Sorry.
msg68735 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2008-06-25 17:20
issue 1762972 supercedes this.
History
Date User Action Args
2022-04-11 14:56:35 admin set github: 47442
2008-06-26 08:58:37 georg.brandl set status: open -> closedresolution: duplicate
2008-06-25 17:20:23 brett.cannon set superseder: 'exec' does not accept what 'open' returnsmessages: + nosy: + brett.cannon
2008-06-24 22:56:25 leif.walsh set messages: +
2008-06-24 22:33:56 ms set messages: +
2008-06-24 22:09:18 leif.walsh set messages: +
2008-06-24 22:08:37 leif.walsh set messages: +
2008-06-24 22:05:43 ms set messages: +
2008-06-24 21:00:51 leif.walsh set nosy: + leif.walshmessages: +
2008-06-24 20:45:46 ms create