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


Groups > comp.lang.python > #40807

Re: Unhelpful traceback

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail
From John Nagle <nagle@animats.com>
Newsgroups comp.lang.python
Subject Re: Unhelpful traceback
Date Thu, 07 Mar 2013 10:42:56 -0800
Organization A noiseless patient Spider
Lines 101
Message-ID <khan0m$ud6$1@dont-email.me> (permalink)
References <kh9c95$t68$1@dont-email.me> <mailman.3016.1362661824.2939.python-list@python.org>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
Injection-Date Thu, 7 Mar 2013 18:41:26 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="9357aff9dc287a4774c734240519a392"; logging-data="31142"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18z0tEyI14MKRLT1mAAR0yR"
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1
In-Reply-To <mailman.3016.1362661824.2939.python-list@python.org>
Cancel-Lock sha1:CHuryh+pyimhceK26pms6mNCsr4=
Xref csiph.com comp.lang.python:40807

Show key headers only | View raw


On 3/7/2013 5:10 AM, Dave Angel wrote:
> On 03/07/2013 01:33 AM, John Nagle wrote:
>> Here's a traceback that's not helping:
>>
> 
> A bit more context would be helpful.  Starting with Python version.

    Sorry, Python 2.7.

> 
> If that isn't enough, then please give the whole context, such as where
> zipelt and filename came from.  And don't forget to specify Python
> version.  Version 3.x treats nonbinary files very differently than 2.x

     Here it is, with some email wrap problems.

				John Nagle


    def dofilecsv(self, infilename, infdraw) :
        """
        Loader for Companies House company data, with files already open.
        """
        self.logger.info('Converting "%s"' % (infilename, ))        # log
        (pathpart, filepart) = os.path.split(infilename)            #
split off file part to construct outputfile)
        (outfile, ext) = os.path.splitext(filepart)                 #
remove extension
        outfile += ".sql"                                           #
add SQL suffix
        outfilename = os.path.abspath(os.path.join(self.options.destdir,
outfile))
        #   ***NEED TO INSURE UNIQUE OUTFILENAME EVEN IF DUPLICATED IN
ZIP FILES***
        decoder = codecs.getreader('utf-8')                         #
UTF-8 reader
        with decoder(infdraw,errors="replace") as infd :
            with codecs.open(outfilename, encoding='utf-8', mode='w') as
outfd :
                headerline = infd.readline()                        #
read header line
                self.doheaderline(headerline)                       #
process header line
                reader = csv.reader(infd, delimiter=',', quotechar='"')
# CSV file
                for fields in reader :                              #
read entire CSV file
                    self.doline(outfd, fields)                      #
copy fields
        self.logstats(infilename)                                   #
log statistics of this file

    def dofilezip(self, infilename) :
        """
        Do a ZIP file containing CSV files.
        """
        try :
            inzip = zipfile.ZipFile(infilename, "r", allowZip64=True)
# try to open
            zipdir = inzip.infolist()                       # get
objects in file
            for zipelt in zipdir :                          # for all
objects in file
                self.logger.debug('ZIP file "%s" contains "%s".' %
(infilename, zipelt.filename))
                (infile, ext) = os.path.splitext(zipelt.filename) #
remove extension
                if ext.lower() == ".csv" :                   # if a CSV file
                    with inzip.open(zipelt.filename,"r") as infd :
      # do this file
                        self.dofilecsv(infile, infd)        # as a CSV file
                else :
                    self.logger.error('Non-CSV file in ZIP file: "%s"' %
(zipelt.filename,))
                    self.errorcount += 1                    # tally

        except zipfile.BadZipfile as message :              # if trouble
            self.logger.error('Bad ZIP file: "%s"' % (infilename,))  #
note trouble
            self.errorcount += 1                            # tally

    def dofile(self, infilename) :
        """
        Loader for Companies House company data
        """
        (sink, ext) = os.path.splitext(infilename) # get extension
        if ext == ".zip" :   # if .ZIP file
            self.dofilezip(infilename)                  # do ZIP file
        elif ext == ".csv" :
            self.logger.info('Converting "%s"' % (infilename,))# log
            with open(infilename, "rb") as infd :
                self.dofilecsv(infilename, infd)        # do
            self.logstats(infilename)                   # log statistics
of this file
        else :
            self.logger.error('File of unexpected type (not .csv or
.zip): %s ' % (infilename,))
            self.errorcount += 1


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


Thread

Unhelpful traceback John Nagle <nagle@animats.com> - 2013-03-06 22:33 -0800
  Re: Unhelpful traceback Andrew Berg <bahamutzero8825@gmail.com> - 2013-03-07 00:57 -0600
  Re: Unhelpful traceback Chris Rebert <clp2@rebertia.com> - 2013-03-06 23:04 -0800
  Re: Unhelpful traceback Dave Angel <davea@davea.name> - 2013-03-07 08:10 -0500
    Re: Unhelpful traceback John Nagle <nagle@animats.com> - 2013-03-07 10:42 -0800
      Re: Unhelpful traceback John Nagle <nagle@animats.com> - 2013-03-07 14:13 -0800
        Re: Unhelpful traceback Ian Kelly <ian.g.kelly@gmail.com> - 2013-03-07 15:32 -0700
    Re: Unhelpful traceback John Nagle <nagle@animats.com> - 2013-03-07 13:23 -0800
      Re: Unhelpful traceback Dave Angel <davea@davea.name> - 2013-03-07 19:23 -0500

csiph-web