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
  Βad Input on line 12 Azdaghost 5 1,140 Apr-19-2025, 10:22 PM
Last Post: Azdaghost
Question [SOLVED] [Beautiful Soup] Move line to top in HTML head? Winfried 0 238 Apr-13-2025, 05:50 AM
Last Post: Winfried
  Insert command line in script lif 4 974 Mar-24-2025, 10:30 PM
Last Post: lif
  Entry field random pull from list, each return own line Bear1981 6 778 Feb-25-2025, 06:09 AM
Last Post: Pedroski55
  How to revert back to a previous line from user input Sharkenn64u 2 915 Dec-28-2024, 08:02 AM
Last Post: Pedroski55
  Pandas - error when running Pycharm, but works on cmd line zxcv101 2 2,416 Sep-09-2024, 08:03 AM
Last Post: pinkang
  Simplest way to run external command line app with parameters? Winfried 2 1,234 Aug-19-2024, 03:11 PM
Last Post: snippsat
  Printing the code line number arbiel 6 1,622 Jun-30-2024, 08:01 AM
Last Post: arbiel
  How to add multi-line comment section? Winfried 2 1,348 Jun-04-2024, 07:24 AM
Last Post: Gribouillis
Information Is it possible to multi line a Basic Function Construct line statement? If so how? BrandonKastning 7 1,866 May-23-2024, 03:02 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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