Advertisement
dbarrera

Untitled

Jan 22nd, 2020
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.09 KB | None | 0 0
  1. articulos = db.Table('inmart', meta, autoload=True, autoload_with=engine)
  2. query = db.select(
  3.     [articulos]
  4. ).where(
  5.     db.and_(
  6.         articulos.c.ciacodigo == '01',
  7.         articulos.c.marcodigo == 'VG'
  8.     )
  9. )
  10.  
  11. rp = engine.execute(query)
  12. resultado = rp.fetchall()
  13.  
  14. with open('temp.csv', 'w') as file:
  15.     for row in resultado:
  16.         s = ''
  17.         for element in row:
  18.             if element == '' or element == None:
  19.                 s += ','
  20.             else:
  21.                 try:
  22.                     if '.' in str(element):
  23.                         value = float(element)
  24.                     else:
  25.                         value = int(element)
  26.                     s += '{},'.format(element)
  27.                 except ValueError:
  28.                     s += '\"{}\",'.format(str(element))
  29.         file.write('{}\n'.format(s[:-1]))
  30.  
  31.  
  32. """
  33.            elif type(element) == int or type(element) == float:
  34.                value = str(element).rstrip('0').rstrip('.')
  35.                element = float(value) if '.' in value else int(value)
  36.                s += '{},'.format(element)
  37. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement