it inserts same value every time.
import re
import MySQLdb
db = MySQLdb.connect("localhost","root","123","tc" )
cursor = db.cursor()
for x in range(1,2):
file = '/tmp/tc/'
file +=`x`
file +=".txt"
f = open(file, 'r')
print x
listTC = re.findall(r'[1-9]{1}[0-9]{10}', f.read())
for item in listTC:
print item
sql = "INSERT INTO TCNO (tcno) VALUES(%s);"
cursor.execute(sql % (item))
OUTPUT in MYSQL SERVER:
| 94006 | 2147483647 | NULL |
| 94007 | 2147483647 | NULL |
| 94008 | 2147483647 | NULL |
| 94009 | 2147483647 | NULL |
| 94010 | 2147483647 | NULL |
| 94011 | 2147483647 | NULL |
| 94012 | 2147483647 | NULL |
| 94013 | 2147483647 | NULL |
| 94014 | 2147483647 | NULL |
| 94015 | 2147483647 | NULL |
| 94016 | 2147483647 | NULL |
| 94017 | 2147483647 | NULL |
| 94018 | 2147483647 | NULL |
| 94019 | 2147483647 | NULL |
| 94020 | 2147483647 | NULL |
| 94021 | 2147483647 | NULL |
| 94022 | 2147483647 | NULL |
| 94023 | 2147483647 | NULL |
+-------+------------+------+
94023 rows in set (0.11 sec)
However, in the console when I am printing the item:
69619195972
32386362700
70930135288
20371250224
25069684954
32414357302
55660438298
12352807312
18566819172
53425735712
19622042220
34060374108
49126586180
13184124554
18772590346
38074262024
37765310686
15491265104
16139670014
16799684314
22231833554
22231833554
213开发者_开发百科89016246
44923993452
50902266134
30742937128
34071994144
35011994174
2147483647
is 0x7fffffff
, so probably you hit max signed int value.
Take a look on data type on the field at database designers, and probably use Big Integer or something bigger one.
ref: http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html#id603844
It's because of range(1,2):
for x in range(1,2):
... print x
...
1
for x in range(0,2):
... print x
...
0
1
精彩评论