Python Forum
item from a line to list however when i print the line instead of words i get letters
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
item from a line to list however when i print the line instead of words i get letters
#1
Hey Everyone,

After some brainstorming and help from anbu23 i was able to make it work. However instead of words i get letters seperated like this . I tought of using rstrip on line however that didint solve the problem. I get results like this :

['A', 'd', 'r', 'e', 's', '\t', '\t', ':', ' ', 'S', 'U', 'L', 'T', 'A', 'N', ' ', 'M', 'U', 'R', 'A', 'T', ' ', 'M', 'A', 'H', '.', ' ', '2', '.', 'Å', 'ž', 'E', 'N', ' ', 'S', 'K', '.', ' ', 'N', 'O', ':', '4', ' ', 'Ä', '°', 'Ã', '‡', ' ', 'K', 'A', 'P', 'I', ' ', 'N', 'O', ':', '3', ' ', ' ', ' ', 'K', 'Ã', 'œ', 'Ã', '‡', 'Ã', 'œ', 'K', 'Ã', '‡', 'E', 'K', 'M', 'E', 'C', 'E', '/', 'Ä', '°', 'S', 'T', 'A', 'N', 'B', 'U', 'L']

From this code my aim as of now is getting info from a text file than find the columns that start with adres(or name) , than get each word from this line to a list.

Later also not included in this code i aim to paste this info to pre written word documents so when user gives raw info , program will find the reqired info like adres etc than paste word documents filled with info automatically saving lots of time for me. Any direction or suggestions for this is also vey appreciated.




fhand2=open("arb1.txt")
adressatırı=[]
for line2 in fhand2:
    satırsayısı2=satırsayısı2+1
    if satırsayısı2==isimsatırlistesi[0]:
        line2=line2.rstrip()#[b]thatdoesnt disappear the gaps also why does the list takes  letters instead[/b]
        for word in line2:
            adressatırı.append(word)
            satırdakikelimesayısı=len(adressatırı)
print(adressatırı[:satırdakikelimesayısı])
print(isimsatırlistesi[0])
print("isimlerin bulunduğu satırlar ",isimsatırlistesi)
print("toplam satırsayısı ise ",satırsayısı)
Reply
#2
Check the spelling of your python (/phyton) tags. The editor has buttons for making tags.
Reply
#3
(Apr-22-2020, 01:24 PM)deanhystad Wrote: Check the spelling of your python (/phyton) tags. The editor has buttons for making tags.
Thanks didnt know about the buttons :)
Reply
#4
if satırsayısı2==isimsatırlistesi[0]:
        line2=line2.rstrip()
        for word in line2.split():
            adressatırı.append(word)
            satırdakikelimesayısı=len(adressatırı)
Reply
#5
Looks like i found the solution, using "strip" instead of "split".

 line2=line2.rstrip()
this should be,

 line2=line2.rsplit()
.

I can still take input about creating word document inside python tough :).

(Apr-22-2020, 02:03 PM)anbu23 Wrote:
if satırsayısı2==isimsatırlistesi[0]:
        line2=line2.rstrip()
        for word in line2.split():
            adressatırı.append(word)
            satırdakikelimesayısı=len(adressatırı)

Hah ok looks like you beat me :).
Reply
#6
I may be really missing something, but isn't this all you need?
fhand=open("arb1.txt")

adressatiri=[]
for line in fhand:
    if line.startswith("Adres"):
        adressatiri += line.split()
fhand.close()

print(adressatiri)
This program finds lines that start with "Adres", splits the line into words, and appends the words to the list adressatiri.

Are you expecting multiple lines to "Adres"? If so do you want all the words in one list, or do you want each a list of words for each matching line? If the second, replace "adressatiri += line.split()" with "adressatiri.append(line.split())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove an item from a list contained in another item in python CompleteNewb 19 886 Nov-11-2021, 06:43 AM
Last Post: Gribouillis
  How to do next line output from CSV column? atomxkai 2 565 Oct-02-2021, 01:00 AM
Last Post: Pedroski55
  How to do line continuation in Jupyter Notebook? Mark17 4 500 Sep-22-2021, 04:22 PM
Last Post: ibreeden
  append a string to a modified line Mr_Blue 10 834 Sep-16-2021, 07:24 PM
Last Post: Mr_Blue
Lightbulb Multiple inputs on the same line (beginner) dementshuk 9 668 Sep-03-2021, 02:21 PM
Last Post: dementshuk
  Line 42 syntax error..Help!!1 patpython 4 586 Sep-01-2021, 03:22 PM
Last Post: deanhystad
  [SOLVED] Why does regex fail cleaning line? Winfried 5 700 Aug-22-2021, 06:59 PM
Last Post: Winfried
  count item in list korenron 8 923 Aug-18-2021, 06:40 AM
Last Post: naughtyCat
  Generate a string of words for multiple lists of words in txt files in order. AnicraftPlayz 2 550 Aug-11-2021, 03:45 PM
Last Post: jamesaarr
  Presenting multiline data into single line aaronbuhu 1 484 Aug-05-2021, 10:57 AM
Last Post: jamesaarr

Forum Jump:

User Panel Messages

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