py_compile vs. built-in compile, with __future__

dhyams dhyams at gmail.com
Tue Jun 11 17:25:35 EDT 2013


On Tuesday, June 11, 2013 11:37:17 AM UTC-4, Neil Cerutti wrote:
> On 2013-06-10, dhyams <dhyams at gmail.com> wrote:
> 
> > On Monday, June 10, 2013 6:36:04 PM UTC-4, Chris Angelico wrote:
> 
> >> Can you read the file into a string, prepend a future directive, and
> 
> >> 
> 
> >> then compile the string?
> 
> >
> 
> > Technically yes, except that now there is complication of
> 
> > writing the modified module back to a file so that I can still
> 
> > use py_compile.compile() to byte compile that code.
> 
> 
> 
> You would use StringIO instead of writing a temp file.
> 

I don't think that would work...py_compile takes a filename as input, not a file object.



More information about the Python-list mailing list