i can`t get python working on the command line (linux)

Sells, Fred fred at adventistcare.org
Tue Mar 13 17:46:57 CET 2007

looks like it is expecting command line agrs that are not there.

put this at the top of your code to see what's going on

import sys
print sys.argv

remembering that the first element printed is sys.argv[0]

-----Original Message-----
From: python-list-bounces+frsells=adventistcare.org at python.org
[mailto:python-list-bounces+frsells=adventistcare.org at python.org]On
Behalf Of Mark
Sent: Tuesday, March 13, 2007 10:04 AM
To: python-list at python.org
Subject: i can`t get python working on the command line (linux)


first of all: sorry for the 100% n00b question
i`m brand new to python and i seem to start off with the biggest problem of
all.. not even getting python to work.
i`m running Fedora core 7 test 2 and all the python based applications are
working fine (like pirut, pipet, and some other yum related tools)

but when i try to run this script:

# python script tel.py
# gevonden door Jan Mooij 24 september 2000
from sys import *
from string import *

     # Create an empty dictionary.
count = {}

for line in open(argv[1], 'r').readlines():
    for word in split(line):
        if count.has_key(word):
            count[word] = count[word] + 1
            count[word] = 1
words = count.keys()
for word in words:
    print "%15s\t%10d" % (word, count[word])

and i`ve put it in tel.py (just the same as in the sample) than chmod
it to 777 (just to make sure it isn`t a permission issue) and than i
run it with: ./tel.py
now this is the error that i get:

Traceback (most recent call last):
  File "./tel.py", line 12, in <module>
    for line in open(argv[1], 'r').readlines():
IndexError: list index out of range

also i`m not even getting the most simple sample code to work.. "Hello
everything works fine when i first enter the python console by typing
python. than i have the  >>> things
than print "Hello World" gives me the expected result but that`s not
what i want.. i want to do it from a file..

the solution is probable extremely simple but i have no idea as a
complete n00b in python. i do have alot php experience.
hope someone could help me out with this.

o and any function that i use in python gives me "command not found:
print/whatever function i use"
(probable just a simple yum install command that i need to do to get
this working.. just try to figure that out with no python knowledge)

Thanx alot in favor.

More information about the Python-list mailing list