getting a value from a web-page

A

Alberto Vera

Hello:

Is it possible to get a row from a text-file? This text-file is located in a web page.
And a value from an excel located in a web-server? (Sheet1!cell A1)

Regards
 
M

Mark Carter

Is it possible to get a row from a text-file? This text-file is located
in a web page.

I'm not sure exactly what it is you are trying to achieve, but you
might be able to use the urllib() module to download the file. I
recall the existence of a module which can efficiently extract
specified rows from a text file - but, alas, I don't recall its name.
But it wouldn't be strictly necessary, anyway.
And a value from an excel located in a web-server? (Sheet1!cell A1)

Do you mean an excel file located on your server, or somebody else's
server? If it is on your server, you could manipulate the file
directly using Mark Hammond's excellent win32all:
http://starship.python.net/crew/mhammond/

A typical piece of python code to manipulate Excel is:

# this example starts Excel, creates a new workbook,
# puts some text in the first and second cell
# closes the workbook without saving the changes
# and closes Excel. This happens really fast, so
# you may want to comment out some lines and add them
# back in one at a time ... or do the commands interactively


from win32com.client import Dispatch


xlApp = Dispatch("Excel.Application")
xlApp.Visible = 1
xlApp.Workbooks.Add()
xlApp.ActiveSheet.Cells(1,1).Value = 'Python Rules!'
xlApp.ActiveWorkbook.ActiveSheet.Cells(1,2).Value = 'Python Rules 2!'
xlApp.Close(SaveChanges=0)
xlApp.Quit()
del xlApp

# raw_input("press Enter ...")
 
?

=?iso-8859-1?Q?Xavier_Mart=EDnez?=

Is it possible to get a row from a text-file? This text-file is located
I'm not sure exactly what it is you are trying to achieve, but you
might be able to use the urllib() module to download the file. I
recall the existence of a module which can efficiently extract
specified rows from a text file - but, alas, I don't recall its name.
But it wouldn't be strictly necessary, anyway.

Have a look at 'linecache' module. This will only work with a
local file, though, so you need to retrieve the file, see
urllib.urlretrieve() at:

http://www.python.org/doc/current/lib/module-urllib.html

See also:
http://www.python.org/doc/current/lib/module-linecache.html
and:
http://gnosis.cx/TPiP/chap1.txt (a chapter of David Mertz's book
'Text Processing in Python').
 
A

Alex Martelli

Gerrit said:
Is it possible to do so without Windows?

No, win32all only runs on Windows (perhaps it might be ported to
WINE or something, but I know of nothing like that ever being done).
Microsoft Excel can run just fine on Linux thanks to "Crossover
Office" (or, presumably, other versions of Wine, too), but I do
not know how to "programmatically" drive it from Python under
such environments.

One possibility might be to use OpenOffice 1.1 (which is able to
open and read XLS files, and can in turn be driven by Python with
the new "Python-UNO bridge" included in OO release 1.1) -- but I
have, as yet, no practical experience doing that.


Alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top