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
  How to input & output parameters from command line argument shantanu97 1 101 Apr-13-2021, 02:12 PM
Last Post: Larz60+
  Time.sleep: stop appending item to the list if time is early quest 0 80 Apr-13-2021, 11:44 AM
Last Post: quest
  How to make input come after input if certain line inserted and if not runs OtherCode Adrian_L 6 328 Apr-04-2021, 06:10 PM
Last Post: Adrian_L
Exclamation Why there's a 'blank line' on CSV file? brunolelli 4 237 Mar-25-2021, 03:43 AM
Last Post: buran
  how to connect mysql from txt 1 line goes good but not all lines in text kingceasarr 4 250 Mar-24-2021, 05:45 AM
Last Post: buran
  Printing a specific line from a JSON serpiente 4 397 Mar-14-2021, 07:27 PM
Last Post: buran
  Syntax error on line 29 manwithjeans 3 258 Feb-27-2021, 08:28 AM
Last Post: perfringo
  Function to count words in a list up to and including Sam Oldman45 13 608 Feb-18-2021, 10:22 AM
Last Post: perfringo
  Why not getting return on line #16? jahuja73 12 666 Feb-12-2021, 02:48 PM
Last Post: deanhystad
  How to skip to a different line while importing a different script kat_gamer 2 220 Feb-03-2021, 04:10 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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