Nov-15-2018, 12:49 PM
(This post was last modified: Nov-15-2018, 12:49 PM by ganeshsai2912.)
I have multiple text file in my folder.
Every text file contains some data (like empno,name,salary).
Ex : empno:101 name:Rasul
SAL:30000
Like above i have more than 1000 rows in every text file.
I want to fetch the above data in every file and update in SQL table.
my MS-SQL Table column has empno|name|SAL.
Finally i want to fetch all the data from all the text file and update into corresponding table.
I am struggling to read specific text in below code.
output in SQL table as follow.
empno|name|SAL
---------------
101 |Rasul|30000
102 |Raj |50000
------
------
------
can anyone help how to proceed further..?
Every text file contains some data (like empno,name,salary).
Ex : empno:101 name:Rasul
SAL:30000
Like above i have more than 1000 rows in every text file.
I want to fetch the above data in every file and update in SQL table.
my MS-SQL Table column has empno|name|SAL.
Finally i want to fetch all the data from all the text file and update into corresponding table.
I am struggling to read specific text in below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
import sys import glob import errno path = 'C:/Test/Python/Mag/*.txt' files = glob.glob(path) for name in files: # 'file' is a builtin type, 'name' is a less-ambiguous variable name. try : with open (name) as f: # No need to specify 'r': this is the default. #sys.stdout.write(f.read()) str = f.readline() except IOError as exc: if exc.errno ! = errno.EISDIR: # Do not fail if a directory is found, just ignore it. raise # Propagate other kinds of IOError. |
empno|name|SAL
---------------
101 |Rasul|30000
102 |Raj |50000
------
------
------
can anyone help how to proceed further..?