J'ai petit code comme ci-dessous:psycopg2 vs sys.stdin.read()
#!/usr/bin/python
import psycopg2, sys
try:
conn = psycopg2.connect("dbname='smdr' user='bino'");
except:
print "I am unable to connect to the database"
cur = conn.cursor()
v_num = '1'
cur.execute("SELECT * from genctr WHERE code = %(num)s", dict(num=v_num))
rows = cur.fetchall()
print "\nShow me the databases:\n"
ctrnum =0
for row in rows:
print row[0]+","+row[1]
quand je le lance, je me suis
[email protected]:~/mydoc/openerp/smdr$ ./genctr.py
Show me the databases:
1,Bahamas
1,Barbados
1,Canada
1,Cayman Islands
1,United States
1,Virgin Islands U.S.
J'essaie de remplacer « v_num = '1' "avec "v_num = sys.stdin.read()"
#!/usr/bin/python
import psycopg2, sys
try:
conn = psycopg2.connect("dbname='smdr' user='bino'");
except:
print "I am unable to connect to the database"
cur = conn.cursor()
#v_num = '1'
v_num = sys.stdin.read()
cur.execute("SELECT * from genctr WHERE code = %(num)s", dict(num=v_num))
rows = cur.fetchall()
print "\nShow me the databases:\n"
ctrnum =0
for row in rows:
print row[0]+","+row[1]
Mais quand je le lance, je ne suis arrivé ceci:
[email protected]:~/mydoc/openerp/smdr$ echo 1 |./genctr.py
Show me the databases:
Veuillez s'il vous plaît donnez-moi votre enlightment sur la façon de le fixer
Sincèrement
-bino-
Cher Zach Hirsch Merci pour votre enlightment Il fonctionne comme un charme Sincèrement -bino- –