By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,078 Members | 1,846 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,078 IT Pros & Developers. It's quick & easy.

Downloading Python files

P: n/a
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

--
Luke St.Clair | "Ask and it will be given to you; seek and you
cl*****@uiuc.edu | will find; knock and the door will be opened
---------------------| to you." - Matthew 7:7
---
Posted via news://freenews.netfront.net
Complaints to ne**@netfront.net
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Fri, 25 Jul 2003 15:26:49 +0000 (UTC), Luke StClair <lu**@stclair.homelinux.net> wrote:
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
Jul 18 '05 #2

P: n/a

"Luke StClair" <lu**@stclair.homelinux.net> wrote in message
news:slrnbi2j1n.ra.lu**@stclair.homelinux.net...
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
Jul 18 '05 #3

P: n/a
Luke StClair wrote:
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

Jul 18 '05 #4

P: n/a
Terry Reedy <tj*****@udel.edu> wrote:

"Luke StClair" <lu**@stclair.homelinux.net> wrote in message
news:slrnbi2j1n.ra.lu**@stclair.homelinux.net...
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.


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.

--
Robin Munn <rm***@pobox.com> | http://www.rmunn.com/ | PGP key 0x6AFB6838
-----------------------------+-----------------------+----------------------
"Remember, when it comes to commercial TV, the program is not the product.
YOU are the product, and the advertiser is the customer." - Mark W. Schumann
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.