Python Forum
how to convert list to string after append !!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to convert list to string after append !!
#1
hello
my code :
import requests 
from bs4 import BeautifulSoup as lo

def openwebsite(url):

    qan = requests.get(url)
    dev = qan.content
    return dev
    #print(qan.content)
#print(openwebsite("http://google.com"))

def findnames(dev):
    q = lo(dev , 'html.parser')
    names = q.find_all('td', id='name')
    output = []
    for name in names:
        
        output.append(name.text)
       
        
    return output

print(findnames(openwebsite("http://172.16.120.120/")))
Output:
[u'Zack', u'Candie', u'Eulah', u'Earle', u'Abdul', u'Sook', u'Harris', u'Joycelyn', u'Antonina', u'John', u'Kristie']
i need them like this ..
Output:
Zack Candie Eulah Earle Abdul Sook Harris Joycelyn Antonina John Kristie
Reply
#2
Not sure if i understood question correctly, Try this to see if it helps,

#print(findnames(openwebsite("http://172.16.120.120/")))

for i in findnames(openwebsite("http://172.16.120.120/")):
	print(i, type(i))
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Reply
#3
Are we talking about output?

>>> lst = [u'Zack', u'Candie', u'Eulah', u'Earle', u'Abdul', u'Sook', u'Harris', u'Joycelyn', u'Antonina', u'John', u'Kristie']       
>>> print(*lst, sep='\n')                                            
Zack
Candie
Eulah
Earle
Abdul
Sook
Harris
Joycelyn
Antonina
John
Kristie
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.
Reply
#4
foo = [u'Zack', u'Candie', u'Eulah', u'Earle', u'Abdul', u'Sook', u'Harris', u'Joycelyn', u'Antonina', u'John', u'Kristie']
print('\n'.join(foo))
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  append str to list in dataclass flash77 6 344 Mar-14-2024, 06:26 PM
Last Post: flash77
Question How to append integers from file to list? Milan 8 1,364 Mar-11-2023, 10:59 PM
Last Post: DeaD_EyE
  convert string to float in list jacklee26 6 1,818 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  convert a list to links Pir8Radio 3 1,043 Nov-28-2022, 01:52 PM
Last Post: Pir8Radio
  convert this List Comprehensions to loop jacklee26 8 1,418 Oct-21-2022, 04:25 PM
Last Post: deanhystad
  how to convert tuple value into string mg24 2 2,237 Oct-06-2022, 08:13 AM
Last Post: DeaD_EyE
  read a text file, find all integers, append to list oldtrafford 12 3,372 Aug-11-2022, 08:23 AM
Last Post: Pedroski55
  Using .append() with list vs dataframe Mark17 7 9,903 Jun-12-2022, 06:54 PM
Last Post: Mark17
  Convert string to float problem vasik006 8 3,270 Jun-03-2022, 06:41 PM
Last Post: deanhystad
  Convert a string to a function mikepy 8 2,422 May-13-2022, 07:28 PM
Last Post: mikepy

Forum Jump:

User Panel Messages

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