Jump to content

Fetching text in intrologin


Recommended Posts

Hi guys

i am trying to fetch a text from a text file online into my login screen.

I was successful but the text is not taking any of its original format, all that matters is the paragraph lines. on the output all lines are merged into one line.

This is the code i am using:


urltxt =urllib2.urlopen("http://www.whatever.com/News.txt")
        msj = urltxt.read()

And i am setting the text the output of msg

self.msg.SetText(msj)

How can i fetch the file with the line breaks and paragraphs and get the same format as an output ?

Thanks

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

30 minutes ago, נσνα said:

Hi guys

i am trying to fetch a text from a text file online into my login screen.

I was successful but the text is not taking any of its original format, all that matters is the paragraph lines. on the output all lines are merged into one line.

This is the code i am using:


urltxt =urllib2.urlopen("http://www.whatever.com/News.txt")
        msj = urltxt.read()

And i am setting the text the output of msg

self.msg.SetText(msj)

How can i fetch the file with the line breaks and paragraphs and get the same format as an output ?

Thanks

First way :

import urllib2
for line in urllib2.urlopen("http://www.localhost.com/SomeFile.txt"):
    print line

Second way with line beak after \n

from urllib2 import urlopen
url = urlopen("url")
file = open("filename", "w")
for line in url:
    file.write(line + '\n')
file.close()

 

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.