Python Forum
Why can't it extract the data from .txt well?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why can't it extract the data from .txt well?
#4
What is going on here? You already answered these questions here:

https://python-forum.io/thread-40556.html

What am I missing? Is the problem that the words are separated by commas and whitespace? This is actually a much simpler problem than you had in the other thread. You can use the same mechanism as before, but use a different regex pattern. You could also treat the file as a csv, and split the file on commas (Comma Separated Values). If going the CSV route you'll probably have to set some parameter in the csv read function to remove the extra spaces.
import csv
from io import StringIO

dictionar_2 = StringIO("Fiind, inteleasa, identitate, dintre, planul, Eului, cel, misterului")

reader = csv.reader(dictionar_2, skipinitialspace=True)
print(*reader)
Output:
['Fiind', 'inteleasa', 'identitate', 'dintre', 'planul', 'Eului', 'cel', 'misterului']
Be aware that "not whitespace" may not be what you expect:
import re

print(re.split("\W+", "This doesn't handle contractions or punctuation well."))
Output:
['This', 'doesn', 't', 'handle', 'contractions', 'or', 'punctuation', 'well', '']
Reply


Messages In This Thread
RE: Why can't it extract the data from .txt well? - by deanhystad - Aug-20-2023, 10:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is it possible to extract 1 or 2 bits of data from MS project files? cubangt 8 1,234 Feb-16-2024, 12:02 AM
Last Post: deanhystad
  python Extract sql data by combining below code. mg24 1 1,022 Oct-03-2022, 10:25 AM
Last Post: mg24
  SQL Alchemy help to extract sql data into csv files mg24 1 1,911 Sep-30-2022, 04:43 PM
Last Post: Larz60+
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,348 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  Build a matrix by pressing buttons of an interface in Tkinter which extract data from juandiegopulla 1 2,038 Sep-13-2021, 07:28 PM
Last Post: deanhystad
  Python Pandas: How do I extract all the >1000 data from a certain column? JaneTan 0 1,612 Jul-17-2021, 09:09 AM
Last Post: JaneTan
  Need help on extract dynamic table data Dr_Strange 0 2,541 Apr-30-2021, 07:03 AM
Last Post: Dr_Strange
  Python modules to extract data from a graph? bigmit37 5 22,762 Apr-09-2021, 02:15 PM
Last Post: TysonL
  Pandas Extract data from two dataframe nio74maz 1 2,251 Dec-26-2020, 09:52 PM
Last Post: nio74maz
  Extract data from PDF page to Excel nathan_nz 1 2,786 Oct-29-2020, 08:04 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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