Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94799 > unrolled thread

Re: 'open' is not defined

Started bydieter <dieter@handshake.de>
First post2015-07-31 08:22 +0200
Last post2015-07-31 08:22 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: 'open' is not defined dieter <dieter@handshake.de> - 2015-07-31 08:22 +0200

#94799 — Re: 'open' is not defined

Fromdieter <dieter@handshake.de>
Date2015-07-31 08:22 +0200
SubjectRe: 'open' is not defined
Message-ID<mailman.1106.1438323776.3674.python-list@python.org>
<ltc.hotspot@gmail.com> 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).

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web