0

I am trying to make a python program, that will help me read notifications log easily. Here's the code:-

location=open("/home/pika/.cache/xfce4/notifyd/log","rt")
data=location.read()
l_data=list(data) #Contents of log file is in string now, in data variable
x=data.count('app_name')
def rm(start,stop,p_name):
    for x in range(start,stop+1):
        print(x)
        n=p_name(x)
        m=l_data.remove(n)
        print(m)        
    data=''
    data=data.join(l_data)
for i in range(0,x):    
    #Time of notification
    t_start=data.index('[')
    t_end=data.index(']')
    t=data[t_start:t_end+1]
    print(t)
    print('\n')
    rm(t_start,t_end,t)
    #Name of the application
    name_start=data.index('app_name')
    name_end=data.index('summary')
    name=data[name_start:name_end-1]
    print(name)
    print('\n')
    rm(name_start,name_end,name)
    #Heading of notification
    head_start=data.index('body')
    head_end=data.index('app_icon')
    head=data[head_start:head_end-1]
    print(head)
    print('\n')
    rm(head_start,head_end,head)
    print('-----------------------------------------------------------')

But, it is giving me the following error:-

[2020-07-23T16:24:43]


0
Traceback (most recent call last):
  File "New File.py", line 20, in <module>
    rm(t_start,t_end,t)
  File "New File.py", line 8, in rm
    n=p_name(x)
TypeError: 'str' object is not callable

Any idea what's the issue? (p.s. i am new to programming, sorry for messy code)

3
  • 1
    In your code, p_name is (partly) data[t_start:t_end+1], that is not a function. What do you mean by calling p_name() ? Commented Jul 23, 2020 at 17:25
  • it appears to me that the issue here is that you're trying to call something as a function which isn't actually a function, like @AdrienKaczmarek says. -- that is, the value of the parameter p_name is a string and not a function, which is because you've passed it the values in an array data from t_start to t_end+1, rather than passing it a function. Commented Jul 23, 2020 at 17:32
  • just realised the issue was the brackets. Thanks for pointing out. Commented Jul 23, 2020 at 17:55

2 Answers 2

1

p_name is a list. So you need to use square brackets:

n=p_name[x]
Sign up to request clarification or add additional context in comments.

Comments

0

You called the function rm() with last parameter p_name as a string.

t=data[t_start:t_end+1] # this is a string
rm(t_start,t_end, t) # t is a string

Inside the function you assign n = p_name(x) which causes the error.

Did you mean n = p_name[x]?

1 Comment

Yeah, it solved the issue. I was scratching my head for the whole day for this. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.