(no subject)
Alex Martelli
aleaxit at yahoo.com
Tue Jan 2 17:07:38 EST 2001
<Patrick.Bussi at space.alcatel.fr> wrote in message
news:mailman.978436922.27803.python-list at python.org...
>
> Hello. Happy new Year.
>
> Basically, my need is to use the "seek" method on data retrieved from an
URL.
> The Python Reference Manual indicates that this method cannot be used
directly
> after opening the URL with urllib. Therefore I (unsuccessfully) tried
other
> ways.
>
> ---- First, I tried the extended form of the "print" statement, after
carefully
> reading the 6.6 of Python Reference Manual.
>
> The interpreter replied the following :
>
> print >> indexpage, f1.read
> ^
> SyntaxError: invalid syntax
>
> where :
> "indexpage" was a "true" file opened with "w" parameter, before the
occurrence
> of this statement,
> "f1" was the network object obtained by the urllib.urlopen() function.
You're trying to copy all data from f1 to the file indexpage? If your
Python does not grok the horrid 'print>>' syntax, you may be using
release 1.5.2 or earlier. But, anyway, you don't need that -- simple
method write of fileobject will do; and you do need parentheses
after 'f1.read' to CALL the function, else you're trying to deal with
the function object itself. In short:
indexpage.write(f1.read())
should do what you seem to require.
Alex
More information about the Python-list
mailing list