Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 getting first letters of a string
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(" "):

songnames = access_data
There are several things you should take care of:

- if you want to call function then you need to use () i.e songnames = access_data()
- if function body doesn't return (or yield) anything it returns None (and your function does the latter)

So even if you fix your first problem you will run into second.

EDIT: if you fix your code you should also reconsider your approach. It's unclear what is you objective - 'first letter of a string' (as in thread name) or 'first letter of each word' in thread itself.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Select single letters from string based on separate string Jpen10 3 634 Dec-15-2019, 01:21 PM
Last Post: Jpen10
  Counting the number of letters in a string alphabetically TreasureDragon 2 575 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 1,381 Jan-17-2019, 09:29 AM
Last Post: buran
  Replacing letters on a string via location Owenix 2 801 Sep-16-2018, 10:59 AM
Last Post: gruntfutuk
  Amount of letters in a inputted string? CyanSupreme 3 1,702 May-10-2017, 09:40 PM
Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)