Re: 'open' is not defined

ltc.hotspot at ltc.hotspot at
Fri Jul 31 08:34:34 CEST 2015


Thanks. What about using the append function to remove duplicate outputs entered on or thereafter line no. 9, i.e., 

LIST_APPEND(i) Calls list.append(TOS[-i], TOS). Used to implement list comprehensions. While the appended value is popped off, the list object remains on the stack so that it is available for further iterations of the loop. URL link available at

What is the command line for such an append function?


Sent from Surface

Sent from Surface

From: dieter
Sent: ‎Thursday‎, ‎July‎ ‎30‎, ‎2015 ‎11‎:‎22‎ ‎PM
To: python-list at

<ltc.hotspot at> writes:
> ...
> Why is open not defined in the following code:NameError: name 'open' is not defined
> Code reads as follows:
> fname = raw_input("Enter file name: ")
> if len(fname) < 1 : fname = "mbox-short.txt"
> fh = open(fname)
> count = 0
> for line in fh:
>     if not line.startswith('From'): continue
>     line2 = line.strip()
>     line3 = line2.split()
>     line4 = line3[1]
>     print line4
>     count = count + 1            
> print "There were", count, "lines in the file with From as the first word"

You might execute the code above in a "restricted execution environment"
(one where "__builtins__" is not the typical "__builtin__" module --
that's how "open" (and other builtins) is found).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list