Skip to content

Commit 1321cde

Browse files
authored
Fix TabError for Python 3
Python 3 treats TabErrors as syntax errors. [flake8](http://flake8.pycqa.org) testing of https://github.com/geekcomputers/Python on Python 3.7.1 $ __flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics__ ``` ./Google_News.py:14:46: E999 TabError: inconsistent use of tabs and spaces in indentation Client=urlopen(xml_news_url, context=context) ^ 1 E999 SyntaxError: invalid syntax 1 ``` __E901,E999,F821,F822,F823__ are the "_showstopper_" [flake8](http://flake8.pycqa.org) issues that can halt the runtime with a SyntaxError, NameError, etc. Most other flake8 issues are merely "style violations" -- useful for readability but they do not effect runtime safety. * F821: undefined name `name` * F822: undefined name `name` in `__all__` * F823: local variable name referenced before assignment * E901: SyntaxError or IndentationError * E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree
1 parent 30af8d0 commit 1321cde

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

Google_News.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@
55
from urllib.request import urlopen
66

77
def news(xml_news_url):
8-
9-
'''Print select details from a html response containing xml
10-
@param xml_news_url: url to parse
11-
'''
12-
13-
context = ssl._create_unverified_context()
14-
Client=urlopen(xml_news_url, context=context)
15-
xml_page=Client.read()
16-
Client.close()
17-
18-
soup_page=soup(xml_page,"xml")
19-
20-
news_list=soup_page.findAll("item")
21-
22-
for news in news_list:
23-
print(f'news title: {news.title.text}')
24-
print(f'news link: {news.link.text}')
25-
print(f'news pubDate: {news.pubDate.text}')
26-
print("+-"*20,"\n\n")
27-
28-
#you can add google news 'xml' URL here for any country/category
8+
9+
'''Print select details from a html response containing xml
10+
@param xml_news_url: url to parse
11+
'''
12+
13+
context = ssl._create_unverified_context()
14+
Client=urlopen(xml_news_url, context=context)
15+
xml_page=Client.read()
16+
Client.close()
17+
18+
soup_page=soup(xml_page,"xml")
19+
20+
news_list=soup_page.findAll("item")
21+
22+
for news in news_list:
23+
print(f'news title: {news.title.text}')
24+
print(f'news link: {news.link.text}')
25+
print(f'news pubDate: {news.pubDate.text}')
26+
print("+-"*20,"\n\n")
27+
28+
#you can add google news 'xml' URL here for any country/category
2929
news_url="https://news.google.com/news/rss/?ned=us&gl=US&hl=en"
3030
sports_url="https://news.google.com/news/rss/headlines/section/topic/SPORTS.en_in/Sports?ned=in&hl=en-IN&gl=IN"
3131

3232
#now call news function with any of these url or BOTH
33-
news(news_url)
33+
news(news_url)
3434
news(sports_url)

0 commit comments

Comments
 (0)