Python Forum
How do i read particular text from text file and update those values in MS SQL table
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do i read particular text from text file and update those values in MS SQL table
#21
Line that is processed is specified in this row
1
line = my_file.split('\n')[6]
That is line 7 from the text file (index is 0-based).
That said you should really start doing your work and not asking us to do/explain every single step of it. the code I provided is more or less self explanatory.
I merged your other thread into this one and it's original post disappeared. I hope there was no important info that is missing now?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#22
Thanks for your information.

The code is perfectly working except specific text in different line.
if i get that specific portion code, my problem solved and i will close the issue.
like that, i have many requirements which i will do it myself further.

Note : merging other thread is entirely different.
Reply
#23
OK, I show you how to read specific line, do the same (with some changes) with the other line you want
I split again the other thread - https://python-forum.io/Thread-split-How...-documents
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#24
not clear..
Reply
#25
(Nov-16-2018, 07:26 AM)ganeshsai2912 Wrote: not clear..
what is not clear? I showed how to access line by index. I showed how to parse a line (of course other approaches are possible too). I just have to do it for another line.
If it's not up to you skills, then maybe you should not take work for clients that you cannot deliver
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#26
can you give me clue..?..how to access line by index
Reply
#27
(Nov-16-2018, 05:34 AM)buran Wrote: Line that is processed is specified in this row
1
line = my_file.split('\n')[6]
That is line 7 from the text file (index is 0-based).
That said you should really start doing your work and not asking us to do/explain every single step of it. the code I provided is more or less self explanatory.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#28
I writing python program which read specific text from text file.

The program is working fine if it is static line index.

if it is dynamic search in the whole document, i am unable to read..

particularly, i want to get "Join Date","Relieve Date",etc. along with 3 main parameter(EmpNo,Name,Salary).

How to change the below code..?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import glob
 
 
def parse_line(line):
    for item in ['Emp No', 'Name', 'SAL', 'Join Date']:
        line = line.replace(item, '')
    return [item.strip() for item in line.split(':') if item.strip()]
  
def process_file(file_name):
    with open(file_name) as f:
        line = f.readlines()[6]
    print(line)
    return parse_line(line)
 
pattern = 'C:/Test/Python/Project/*.txt'  
files = glob.glob(pattern)
all_data = [process_file(file_name) for file_name in files]
sample text file attached in the below link.

final out put would be

EmpNo: 101 Name: RASUL L SAL: 30000 JoinDate :XXXXX

Sample file attached.

Sample file attached
Reply
#29
Please, don't start new threads. Keep the discussion in this thread.
It's really frustrating when people don't want to put any effort and expect others to do their work.
I showed several times how to access line by index. The EmpNo, Name, and SAL are on line 7 (i.e. index = 6).
Join date is on line 9, i.e. index=8.
I also showed you how to parse the line and get separate elements.
Just amend the code to do the same for line 9
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#30
I tried some code's. but, no luck and i am struggling.

I have no idea how to proceed further..?

Note : Mention index which we need to hard code or loop it...?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  subprocess check_output text cut off Axel_Erfurt 5 723 Feb-20-2025, 02:15 PM
Last Post: DeaD_EyE
  How can I write formatted (i.e. bold, italic, change font size, etc.) text to a file? JohnJSal 12 27,891 Feb-13-2025, 04:48 AM
Last Post: tomhansky
  Python - Hidden Text / Html Mail python1337 1 2,285 Feb-08-2025, 10:47 AM
Last Post: python1337
  Problems writing a large text file in python Vilius 4 959 Dec-21-2024, 09:20 AM
Last Post: Pedroski55
  How to read a file as binary or hex "string" so that I can do regex search? tatahuft 3 1,008 Dec-19-2024, 11:57 AM
Last Post: snippsat
  Get an FFMpeg pass to subprocess.PIPE to treat list as text file? haihal 2 993 Nov-21-2024, 11:48 PM
Last Post: haihal
  parsing a tree of text first the right most aligned blocks of text and so on arvindikchari 2 759 Nov-21-2024, 01:42 AM
Last Post: BashBedlam
  Paste text with caret already positioned inside a placeholder; Wehaveall 1 818 Oct-15-2024, 10:28 AM
Last Post: menator01
Photo image generation with text style Belialhun 0 634 Oct-08-2024, 01:53 PM
Last Post: Belialhun
  Read TXT file in Pandas and save to Parquet zinho 2 1,210 Sep-15-2024, 06:14 PM
Last Post: zinho

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020