[Tutor] New to list & first steps in Python
Chris F Waigl
cwaigl at free.fr
Wed Jun 2 21:51:05 EDT 2004
I am thrilled to find that there is a list where beginners can find
guidance. Thanks for taking the time to help!
I'm interested in natural language processing, and chose Python as a
programming language. I'm working my way through various tutorials
right now, but I've only just begun. I've also changed over from W98 to
Debian GNU/Linux and am not yet familiar with the modules installed on
my box with Python 2.3. I use Idle, which I find very convenient.
Right now I'm mostly interested in not adopting bad habits -- learning
"good" style from the very beginning. In a different life, I used C for
number-crunching type programming (solving equations and the like), but
I never particularly enjoyed it.
Here's my first script not copied from a tutorial. It works, so the only
question is, should I have done something differently? (Well, it's so
short, there's not much to _do_.)
from random import * # or "... import choice" ?
adj1 = 
adj2 = 
nouns = 
file = open("ElisabethInsults", "r")
for line in file.readlines():
words = line.split()
print "Thou", choice(adj1), choice (adj2), choice(nouns) + "!"
ElisabethInsults is a file containing three rows, 2 x adjectives, 1 x
nouns, of derogatory words taken from Shakespeare. (If you're
interested, it's here: http://kastalia.free.fr/misc/ElisabethInsults )
The script creates a random insult, e.g.
"Thou clouted onion-eyed pigeon-egg!"
I'm planning to put together something like a very simple tokenizer,
something that reads in a text, counts sentences and words, handles all
the punctuation correctly, tells me something about word frequencies
and the presence or absence of grammatical structures I might be
interested in. I'm certainly going to run into a lot of problems soon.
Any comments and recommendations are warmly encouraged.
More information about the Tutor