Downloading Python files

L

Luke StClair

Only marginally belonging in this newsgroup... but oh well.

I've just started writing in python, and I want to make the files
available on the web. So I did the standard <a
href="mypath/myfile.py"> and not surprisingly, it displays like a
webpage, but just the code. If I gzip it, and then link to the new
file, it will download, but its so small I don't want it zipped.
How can I make this into a downloadable
file SIMPLY? The other thread seems a bit complicated...

Thanks
 
B

Bengt Richter

Only marginally belonging in this newsgroup... but oh well.

I've just started writing in python, and I want to make the files
available on the web. So I did the standard <a
href="mypath/myfile.py"> and not surprisingly, it displays like a
webpage, but just the code. If I gzip it, and then link to the new
file, it will download, but its so small I don't want it zipped.
How can I make this into a downloadable
file SIMPLY? The other thread seems a bit complicated...

Thanks
If the user has .py set up for automatic shell execution of .py files, the browser
should warn of security risk and provide an option to save to disk. If the user doesn't,
then it may show as text as you describe. If that's already happened, s/he should be
able to do file>save as ... and save as a .py file somewhere. If the user is still
looking at your page with the highlighted link, s/he should be able to right-click the link
and get an option to "save link as ..." You could just tell the user about that
in association with your link(s), e.g., with the following (untested!) HTML:

Right-click <a href="mypath/myfile.py">this</a> to save myfile.py to disk.<br>
Left-click <a href="mypath/myfile.py">this</a> to open myfile.py according to your browser settings.

Note that it's really the same link, just different instructions.
I guess for different browsers YMMV.

Regards,
Bengt Richter
 
T

Terry Reedy

Luke StClair said:
Only marginally belonging in this newsgroup... but oh well.

I've just started writing in python, and I want to make the files
available on the web. So I did the standard <a
href="mypath/myfile.py"> and not surprisingly, it displays like a
webpage, but just the code.

What browser on what system? As I remember, with IE6/Win98 with
python installed, even left clicking brings up 'Downloading... open or
save' box. And there is always right click 'Download as..' option.

TJR
 
A

Adam

Luke said:
Only marginally belonging in this newsgroup... but oh well.

I've just started writing in python, and I want to make the files
available on the web. So I did the standard <a
href="mypath/myfile.py"> and not surprisingly, it displays like a
webpage, but just the code. If I gzip it, and then link to the new
file, it will download, but its so small I don't want it zipped.
How can I make this into a downloadable
file SIMPLY? The other thread seems a bit complicated...

Thanks
In order to assure that the file is downloaded and not displayed, you
need a certain amount of control either at the client agent or the server:

1. Server: you need to be able to send the client a header which is
intended for download rather than display (content-type not set to
text/html)
2. Client: you need to be able to tell the client agent to download the
data and save it as file on the disk ("Save targer as...") rather than
display it.

Adam
 
R

Robin Munn

Terry Reedy said:
What browser on what system? As I remember, with IE6/Win98 with
python installed, even left clicking brings up 'Downloading... open or
save' box. And there is always right click 'Download as..' option.

That's because Microsoft is a standard unto themsleves. IE will ignore
the Content-Type header being sent by the server; instead, it will look
at the user's file type settings for the extension of the file. In this
case, the system you were testing on had no entry for the .py extension,
so downloading was the default option. But get this: if you had *wanted*
to show the code (instead of downloading), the way to do it in a
cross-platform way, compatible with every browser *except IE* would be
to set "Content-Type: text/plain" on the file. But <DWS>Microsoft knows
best, dear</DWS>, so IE would override that and make the user download
the file instead of displaying it.

BTW, for those not familiar with DWS, it means Dripping With Sarcasm.

Sorry for the vitriol against IE and Microsoft, but this has been a
*very* annoying issue for me from time to time.
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top