Re: Execute commands from file

2007-05-19 Thread Martin Blume
"Steve Holden" schrieb > > I simply meant that the whole source has to be presented > to the exec statement and not chunked into lines. > That's what I meant: With exec open(f).read() it is not broken into several exec invocations. > > I was probably just a little over-zealous in pursuing >

Re: Execute commands from file

2007-05-19 Thread Steve Holden
Martin Blume wrote: > "Steve Holden" schrieb >>> [ difference between exec open(fname).read() >>>and for line in open(fname): exec line ] >>> >>> So it seems to depend on the way the file is read. >>> >> It depends on the way the lines of the file are executed, >> not how they are read. >>

Re: Execute commands from file

2007-05-19 Thread Martin Blume
"Steve Holden" schrieb > > > > [ difference between exec open(fname).read() > >and for line in open(fname): exec line ] > > > > So it seems to depend on the way the file is read. > > > It depends on the way the lines of the file are executed, > not how they are read. > Could you elaborate

Re: Execute commands from file

2007-05-18 Thread Douglas Woodrow
On Fri, 18 May 2007 04:45:30, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote >On 17 May 2007 13:12:10 -0700, i3dmaster <[EMAIL PROTECTED]> declaimed >the following in comp.lang.python: > >> 'b' is generally useful on systems that don't treat binary and text >> files differently. It will improve porta

Re: Execute commands from file

2007-05-17 Thread Steve Holden
Martin Blume wrote: > "Steve Holden" schrieb Try it on a file that reads something like xxx = 42 print xxx and you will see NameError raised because the assignment hasn't affected the environment for the print statement. >>> [...] >>> >> No, because there i

Re: Execute commands from file

2007-05-17 Thread i3dmaster
On May 17, 3:02 am, Douglas Woodrow <[EMAIL PROTECTED]> wrote: > On Thu, 17 May 2007 00:30:23, i3dmaster <[EMAIL PROTECTED]> wrote > > >f = open(file,'rb') > >for i in f: > >exec i > > Why are you opening the file in binary mode? > > -- > Doug Woodrow 'b' is generally useful on systems tha

Re: Execute commands from file

2007-05-17 Thread Martin Blume
"Steve Holden" schrieb > >> > >> Try it on a file that reads something like > >> > >> xxx = 42 > >> print xxx > >> > >> and you will see NameError raised because the assignment > >> hasn't affected the environment for the print statement. > >> > > [...] > > > No, because there isn't one. Now try

Re: Execute commands from file

2007-05-17 Thread Maric Michaud
Steve Holden a écrit : > i3dmaster wrote: >> On May 16, 1:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote: >>> Martin Blume wrote: "tmp123" schrieb > > We have very big files with python commands > (more or less, 50 commands each file). > It is possible to execute them command by

Re: Execute commands from file

2007-05-17 Thread Steve Holden
i3dmaster wrote: > On May 16, 1:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote: >> Martin Blume wrote: >>> "tmp123" schrieb > We have very big files with python commands (more or less, 50 commands each file). It is possible to execute them command by command, >>> inp = open(cmd_fi

Re: Execute commands from file

2007-05-17 Thread Douglas Woodrow
On Thu, 17 May 2007 00:30:23, i3dmaster <[EMAIL PROTECTED]> wrote >f = open(file,'rb') >for i in f: >exec i Why are you opening the file in binary mode? -- Doug Woodrow -- http://mail.python.org/mailman/listinfo/python-list

Re: Execute commands from file

2007-05-17 Thread i3dmaster
On May 16, 1:05 pm, Steve Holden <[EMAIL PROTECTED]> wrote: > Martin Blume wrote: > > "tmp123" schrieb > > >> We have very big files with python commands > >> (more or less, 50 commands each file). > > >> It is possible to execute them command by command, > > > inp = open(cmd_file) > > for line

Re: Execute commands from file

2007-05-16 Thread Steve Holden
Martin Blume wrote: > "tmp123" schrieb > >> We have very big files with python commands >> (more or less, 50 commands each file). >> >> It is possible to execute them command by command, > > inp = open(cmd_file) > for line in inp: > exec line > > might help. You don't get quite the sam

Re: Execute commands from file

2007-05-16 Thread Martin Blume
"tmp123" schrieb > > We have very big files with python commands > (more or less, 50 commands each file). > > It is possible to execute them command by command, inp = open(cmd_file) for line in inp: exec line might help. You don't get quite the same feeling as "like if the commands wa

Re: Execute commands from file

2007-05-16 Thread Steve Holden
tmp123 wrote: > Hello, > > Thanks for your time. > > We have very big files with python commands (more or less, 50 > commands each file). > Those are BIG programs. Presumably other programs are writing them? > It is possible to execute them command by command, like if the > commands was typ

Re: Execute commands from file

2007-05-16 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, tmp123 wrote: > We have very big files with python commands (more or less, 50 > commands each file). > > It is possible to execute them command by command, like if the > commands was typed one after the other in a interactive session? Take a look at the `code` module