Question on File Input and AST
subhakolkata1234 at gmail.com
Tue Sep 8 11:56:40 CEST 2009
On Sep 6, 1:49 pm, Steven D'Aprano <st... at REMOVE-THIS-
> On Sun, 06 Sep 2009 00:53:43 -0700,joy99wrote:
> > Dear Group,
> > I have a file "test1.txt". Now, as I do the file handling, i try to do
> > any one of the following operations.
> > 1. open_file=open("/python26/test1.txt","r") # FOR READING 2.
> > open_file=open("/python26/test1.txt","r+") # FOR READING AND WRITING
> > BOTH
> > [Either of 1 or 2 to open as the need be] 3. read_file=open_file.read()
> > etc...
> > But how to work with "fileinput" or "ast".
> > I tried to read python docs and some backlog question answer in the
> > group but it did not help much.
> At the interactive interpreter, do this:
> >>> import fileinput
> >>> help(fileinput)
> and read the help text. It gives you an example:
> Typical use is:
> import fileinput
> for line in fileinput.input():
> This iterates over the lines of all files listed in sys.argv[1:],
> defaulting to sys.stdin if the list is empty. If a filename is '-' it
> is also replaced by sys.stdin. To specify an alternative list of
> filenames, pass it as the argument to input(). A single file name is
> also allowed.
> [end quote]
> If there is something unclear about that, then please try to be specific
> about what you don't understand. Try some code, and report what errors
> you get.
> As far as ast, there's an example here:
> and a discussion here:
> If you explain what you want to do, perhaps there's somebody out there
> who knows the ast module and can answer.
> Steven- Hide quoted text -
> - Show quoted text -
Thank you for your kind reply. I will have a check on them soon.
More information about the Python-list