linux python ideas

0 views
Skip to first unread message

Rob Andrews

unread,
Sep 18, 2002, 4:38:39 PM9/18/02
to
I'll be giving a presentation on Python to my local LUG
(http://lugoj.org) in a few weeks, and would like to point out at least
a few things that would be of particular interest to linux users.

The idea is not "how to program in Python", which would take more than
one quick presentation, but a one-off demonstration of ways in which
Python is particularly useful for such a group.

Any suggestions would be appreciated, since my notes are pretty generic
so far.

regards,
Rob Andrews

Fernando Pérez

unread,
Sep 18, 2002, 4:59:57 PM9/18/02
to
Rob Andrews wrote:

<blatant plug>
Check out ipython at http://www-hep.colorado.edu/~fperez/ipython

It's not linux-specific, but its best features only work in a linux/unix
environment, and it will appeal very much to command-line junkies. Take a
look at the screenshots to get a feel for its features and feel free to drop
me a line if you have a question.

It allows you to use the python shell almost as a system shell, not so much to
replace the regular shell for day to day stuff, but rather to have the power
of file and directory management when you need to do things with python. For
me it's very useful in processing scientific data, since I have both access
to Python/Numeric/Gnuplot and at the same time have essentially a system
shell.

The introspection features (name? and <tab>) also make it very useful for
regular programming tasks.
</blatant plug>

Well, check for yourself. In general, python+Numeric+Gnuplot/Grace makes a
pretty strong stand against the $$$ likes of Matlab. And in many cases beats
them (in others we're still behind, but catching up quickly).

Cheers,

f.

Sean 'Shaleh' Perry

unread,
Sep 18, 2002, 4:47:39 PM9/18/02
to

obvious ideas are things like zope and mailman as well as cheetah.

Skip Montanaro

unread,
Sep 18, 2002, 5:19:00 PM9/18/02
to
>> I'll be giving a presentation on Python to my local LUG
>> (http://lugoj.org) in a few weeks, and would like to point out at
>> least a few things that would be of particular interest to linux
>> users.

Sean> obvious ideas are things like zope and mailman as well as cheetah.

Also rdiff-backup: <http://rdiff-backup.stanford.edu/>

Skip

Edward C. Jones

unread,
Sep 18, 2002, 6:23:16 PM9/18/02
to

I use Python instead of shell scripts for anything that is not
completely trivial. Here is a small program for finding all the links in
a page of html:

#! /usr/bin/end python

import sys

if len(sys.argv) != 2:
raise Exception, 'program must have exactly one argument.'
infile = sys.argv[1]
page = open(infile, 'r').read()
lowerpage = page.lower()

start = 0
while 1:
start = lowerpage.find('href="', start)
if start == -1:
break
start = start + len('href="')
end = lowerpage.index('"', start)
print page[start : end]

Henrik Motakef

unread,
Sep 18, 2002, 6:36:57 PM9/18/02
to
Rob Andrews <r...@diespammerdieuselesspython.com> writes:

> I'll be giving a presentation on Python to my local LUG
> (http://lugoj.org) in a few weeks, and would like to point out at
> least a few things that would be of particular interest to linux users.

Aren't RedHat's installer and Gentoos "portage" packaging system
written in Python?

Mark Nenadov

unread,
Sep 18, 2002, 6:59:35 PM9/18/02
to
In article <3D88E578...@diespammerdieuselesspython.com>, "Rob
Andrews" <r...@diespammerdieuselesspython.com> wrote:

Since you aren't trying to teach the language, but rather provoke some
interest in Python, it may be a good idea to just show a few specific
libraries and problem domains in which Python can excel.

Here are some topics that might suffice:

1) Overview of open source projects that use Python
2) About GUI libraries available for Python
3) Zope
4) ReportLAB (a Python library for PDF generation)
5) Jython

~Mark (http://www.freelance-developer.com)

Fernando Pérez

unread,
Sep 18, 2002, 7:46:37 PM9/18/02
to
Rob Andrews wrote:

> The idea is not "how to program in Python", which would take more than
> one quick presentation, but a one-off demonstration of ways in which
> Python is particularly useful for such a group.
>
> Any suggestions would be appreciated, since my notes are pretty generic
> so far.

Well, here's another one. It's a short script to fetch bibliographic
information from the SPIRES database in BibTex format, from preprints listed
in the XXX Los Alamos server. I use it constantly to update my references
database with zero effort:

$ getbibtex.py NNNNN >> references.bib

and I'm done. Coupled to Pybliographic (also written in python, incidentally)
I have fabulous reference management with perfect coupling to LyX.

It's specific to my needs, but shows how a simple code snippet can fetch very
useful info off the internet, and could easily be modified for other
purposes.

Cheers,

f.

# code follows:

#!/usr/bin/env python
"""Get BibTex references from preprint archives supported by SPIRES.

Usage:

getbibtex preprint1 [preprint2 ....]

The list of preprints can also be fed in from standard input.

Preprint references can be given as:

- name/number, as in hep-lat/0104015.

This sets the archive name to 'name', and subsequent references can be given
only as numbers. That is:

hep-lat/n1 n2 n3 hep-ph/n4 n5

will fetch n1,n2,n3 from hep-lat and n4,n5 from hep-ph.

- numbers only. In this case, a preset default is used (you can change this
value by editing getbibtex.py). The current default is: `%(def_archive)s`.

All archive names supported by SPIRES will work.

Output is given as a list of bibtex references, so you can simply do:

getbibtex .... > mybiblio.bib

and mybiblio.bib will be a valid BibTex file.
"""

__author__ = "Fernando Perez <fpe...@pizero.colorado.edu>"

#---------------------------------------------------------------------------
# Global defaults
def_archive = 'hep-lat'

import re,urllib,sys

#---------------------------------------------------------------------------
# Function definitions
def make_url(archive,number):
"""Make a SPIRES search url given an archive name and preprint number.

make_url(archive,number) -> url string."""

return ('http://www.slac.stanford.edu/spires/find/hep/www?'
'eprint=%s&eprint=%s&format=wwwbriefbibtex'
% (archive,number) )

def build_preprints_list():
"""Build the list of (archive,number) pairs from input parameters."""
if len(sys.argv)>1:
input_list = sys.argv[1:]
else:
input_list = sys.stdin.read().splitlines()
pp_list = []
archive = def_archive
for item in input_list:
if '/' in item:
archive,number = item.split('/')
pp_list.append([archive,number])
else:
pp_list.append([archive,item])
return pp_list

#----------------------------------------------------------------------------
# Main code

# give user help if requested with -h... or --h...
try:
if sys.argv[1].startswith('-h') or sys.argv[1].startswith('--h'):
print __doc__ % globals()
sys.exit()
except IndexError:
pass

bibtex_re = re.compile( r'(@Article{.*})',re.DOTALL)

for archive,number in build_preprints_list():
search_page = urllib.urlopen(make_url(archive,number)).read()
try:
print bibtex_re.search(search_page).group(1)
except:
print >> sys.stderr, 'ERROR: Failed to get results
for:',archive,number

Jeff Davis

unread,
Sep 19, 2002, 12:42:48 AM9/19/02
to

I think python's strength (for me) is in it's versatility and consistency.
That combination is very powerful.

When I say python is consistent, I mean that there are very few special
cases, and few special character sequences to remember. That means you
generally only have to reference the docs for functions, and not language
issues.

It's also versatile, because
(a) it has a good standard library
(b) the library is easily extended with python, C, or Java (if you're into
jython). That gives python access to the vast standard libraries, and
extended libraries (like APIs to virtually anything in existence), of C &
Java.

I use it for:
* simple task automation, kind of like a shell script but easier to write.
* starting to use it for web programming
* practical extraction and report, text/binary data processing or
reformatting, whatever you want to call it.
* methematics, such as statistics, but also really simple stuff when I have
a shell more handy than a calculator :)
* embedded scripting (because it integrates so easily with C)
* small daemons and other small applications

Regards,
Jeff

Paul Boddie

unread,
Sep 19, 2002, 3:29:01 AM9/19/02
to
Fernando Pérez <fper...@yahoo.com> wrote in message news:<amapge$22r$1...@peabody.colorado.edu>...

> Rob Andrews wrote:
>
> > I'll be giving a presentation on Python to my local LUG
> > (http://lugoj.org) in a few weeks, and would like to point out at least
> > a few things that would be of particular interest to linux users.
>
> <blatant plug>
> Check out ipython at http://www-hep.colorado.edu/~fperez/ipython

I'd very much recommend a demonstration which uses the interactive
mode of Python. That was one of the things that impressed me about
Python in the beginning: the ability to do things like connecting to
servers interactively and with barely any effort, and I amused myself
by perusing the Python newsgroups at the Python prompt and thinking
how straightforward it would be to write a newsreader in Python
instead of C, for example.

Of course, stuff like "network programming" is fairly easy with other
languages, but unless Perl has spawned an interactive mode, for
example, you'll be showing people things they haven't seen before if
you show some experimentation at the command prompt. You might also
get bonus points by then demonstrating the same things again in
Jython. :-)

Paul

Cameron Laird

unread,
Sep 19, 2002, 8:44:50 AM9/19/02
to
In article <23891c90.02091...@posting.google.com>,
Paul Boddie <pa...@boddie.net> wrote:
.
[several apt and
accurate points]
.

.
>Of course, stuff like "network programming" is fairly easy with other
>languages, but unless Perl has spawned an interactive mode, for
>example, you'll be showing people things they haven't seen before if
>you show some experimentation at the command prompt. You might also
.
.
.
Has Perl spawned an interactive mode? Read
<URL: http://phaseit.net/claird/comp.lang.perl.misc/perl_interactive.html >
--

Cameron Laird <Cam...@Lairds.com>
Business: http://www.Phaseit.net
Personal: http://phaseit.net/claird/home.html

Markus Schaber

unread,
Sep 19, 2002, 9:32:05 AM9/19/02
to
Hallo,

Rob Andrews <r...@diespammerdieuselesspython.com> schrieb:

> Any suggestions would be appreciated, since my notes are pretty
> generic so far.

I held such a presentation here in Ulm (Germany), you can see the German
data at http://ulm.ccc.de/~schabi/python/index.html - this file is
identical to the presentation, just use Opera 6 or later and press F11
(or use any other CSS presentation mode capable browser)

Gruß,
Markus

James T. Dennis

unread,
Oct 4, 2002, 9:44:58 PM10/4/02
to

RedHat's installer is named Anaconda. It is written in Python.
Their "kickstart" feature is part of Anaconda.


I did a presentation like this to BayLISA (SF Bay Area Large
Installation Systems Administration) which is mostly comprised of
UNIX sysadmins.

I followed the following basic format:

General Intro and Comparisons to Shell and Perl
(Everyone in that crowd has used Perl and sh)
Representative Sample of Applications/Uses and Demos
(I had a few Pygame programs running in virtual
consoles, and Pysol, pytris (ncurses) and a few others
running under X. This was good for showing off the
GUI and multimedia features; and I mentioned and/or
showed websites like LWN which use Python based CMF
and dynamic content systems).
Whirlwind Tutorial
(I showed some sample bits of code, like simple fibonacci
functions and generators. a Jython applet, a version of wc
that implements all of the GNU command line arguments
emulating its output almost exactly, a "word frequency"
(histogram) program that demonstrated how I could add
database support, for posting the results of a frequency
counting session to a DBMS table with only four additional
lines of code, some code showing unittest and doctest
examples, etc. I dropped into the interpreter to
show the interactive features, including the readline
vi-mode support and the rlcompleter features and to
show off some ad hoc programming and the use of Python as
a 'bc' replacement).

Then I finished up with a list of pet peeves about Python and a slide
full of URLs for web resources. I invited lots of audience participation
at this point. I had a (fairly extensive) collection of Python books
arrayed on a table, for people to browse through. I'd offer to send
you my MagicPoint slides, but they aren't very good. I'd only had a
couple hours to spend on them so there's only about 10 slides there.
I relied very heavily on the interactive and external parts of the
presentation.

Reply all
Reply to author
Forward
0 new messages