Python Sybase slow compared to Perl?

Dennis Lee Bieber wlfraed at ix.netcom.com
Sat Sep 21 00:10:30 CEST 2002


Chuck May fed this fish to the penguins on Friday 20 September 2002 
01:30 pm:

        I'm just a neophyte at this but...

> and here is the Python code snippet:
> 
>    # output the actual data
>    c = db.cursor()
>    c.execute( "SELECT %s FROM %s" % ( select, table ) )
>    num_recs = 0
>    if os.path.isfile( "%s.gz" % dumpfile ):
>        os.remove( "%s.gz" % dumpfile )
>    file = os.popen( "gzip -c > %s.gz" % dumpfile, "w" )
>    while 1:
>        row = c.fetchone()

        How many rows do you expect? fetchall() or fetchmany() followed by 
looping over rows returned may be a noticeable increase (fetchall() if 
you have the memory).

>        if not row : break
>     
>        line = []
>        for i in range( len( row ) ):
>            line.append( "%-*s" % ( lengths[i], row[i] ) )
> 
>        print >> file, "".join( line )
>        num_recs += 1
> 
>    file.close()
>    c.close()
> 
--
 > ============================================================== <
 >   wlfraed at ix.netcom.com  | Wulfraed  Dennis Lee Bieber  KD6MOG <
 >      wulfraed at dm.net     |       Bestiaria Support Staff       <
 > ============================================================== <
 >        Bestiaria Home Page: http://www.beastie.dm.net/         <
 >            Home Page: http://www.dm.net/~wulfraed/             <



More information about the Python-list mailing list