Python Forum
getting first letters of a string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
getting first letters of a string
#1
im new to python and im trying to split a string so it prints the first letter of each word.
Below is the error i keep getting

line 8, in split_song
for letter in songnames.split(" "):
AttributeError: 'function' object has no attribute 'split'

def access_data():
    with open("Songnames.txt", "r") as f:
        songnames = [line.strip("\n") for line in f]


def split_song(songnames):
    for letter in songnames.split(" "):
        print(letter[0])

songnames = access_data
split_song(songnames)
Reply


Messages In This Thread
getting first letters of a string - by Unknown_Relic - Nov-12-2019, 10:42 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replacing a words' letters in a string cananb 2 3,449 Dec-01-2020, 06:33 PM
Last Post: perfringo
  Select single letters from string based on separate string Jpen10 3 2,652 Dec-15-2019, 01:21 PM
Last Post: Jpen10
  Counting the number of letters in a string alphabetically TreasureDragon 2 2,883 Mar-07-2019, 01:03 AM
Last Post: TreasureDragon
  Replacing all letters in a string apart from the first letter in each word Carbonix 9 4,919 Jan-17-2019, 09:29 AM
Last Post: buran
  Replacing letters on a string via location Owenix 2 2,463 Sep-16-2018, 10:59 AM
Last Post: gruntfutuk
  Amount of letters in a inputted string? CyanSupreme 3 3,612 May-10-2017, 09:40 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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