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


Groups > comp.lang.python > #44237

Re: AttributeError Problem

References <4dfb3ca3-a539-48ec-aae8-0be22471cea4@googlegroups.com>
Date 2013-04-23 19:02 -0500
Subject Re: AttributeError Problem
From Skip Montanaro <skip@pobox.com>
Newsgroups comp.lang.python
Message-ID <mailman.1008.1366761732.3114.python-list@python.org> (permalink)

Show all headers | View raw


> numberOfVertices = int(infile.readline().decode()) # Read the first line from the file
> AttributeError: 'str' object has no attribute 'readline'
...
>     infile = filedialog.askopenfilename()

This is just returning a filename.  You need to open it to get a file
object.  For example:

    infile = filedialog.askopenfilename()
    fd = open(infile)
    ...
    numberOfVertices = int(fd.readline().decode())

Skip

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

AttributeError Problem animemaiden <animemaiden21@gmail.com> - 2013-04-23 16:41 -0700
  Re: AttributeError Problem animemaiden <animemaiden21@gmail.com> - 2013-04-23 16:42 -0700
  Re: AttributeError Problem Skip Montanaro <skip@pobox.com> - 2013-04-23 19:02 -0500
    Re: AttributeError Problem animemaiden <animemaiden21@gmail.com> - 2013-04-23 17:28 -0700
      Re: AttributeError Problem MRAB <python@mrabarnett.plus.com> - 2013-04-24 02:17 +0100

csiph-web