I have a file that I've made executable. It has a function in it that I would like to return its results to the command line but, I keep getting NameError messages. To break things down, I'm using LinuxMint Lisa and so far I have:
#! /usr/bin/env python
import mechanize
from BeautifulSoup import BeautifulSoup
import sys
def dictionary(word):
br = mechanize.Browser()
response = br.open('http://www.dictionary.reference.com')
br.select_form(nr=0)
br.form['q'] = word
br.submit()
definition = BeautifulSoup(br.response().read())
trans = definition.findAll('td',{'class':'td3n2'})
fin = [i.text for i in trans]
query = {}
for i in fin:
query[fin.index(i)] = i
return query
print dictionary(sys.argv)
Then I chmod from my terminal:
sudo chmod +x this_file.py
When I call this file from the command-line, I'll enter:
./this_file.py 'pass'(or any other string argument)
Which will return:
TypeError: Must assign a string
So I know I'm obviously not using sys.argv correctly but, I have a feeling like I'm mucking something else up when attempting to return this functions results to the command-line.
print dictionary(agrv)argv is misspelled. Also, usesys.argv