Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I have generated a simple python script to post data on a website.

#Imports

url_to_short = sys.argv[1]

post_url = 'https://www.googleapis.com/urlshortener/v1/url'

headers = {'Content-Type': 'application/json'}

data = {'longUrl': url_to_short}

post_data = json.dumps(data)

req = urllib2.Request(post_url, post_data, headers)

resp = urllib2.urlopen(req)

if resp.getcode() == 200:  

    content = json.loads(resp.read())

#Other stuff

My pylint output is as follows:

************* Module post

C:  1,0: Missing docstring

C:  6,0: Invalid name "url_to_short" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)

C:  8,0: Invalid name "post_url" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)

C:  9,0: Invalid name "headers" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)

# Other stuff

Now, my question is why pylint is displaying my variable names as an Invalid name?

1 Answer

0 votes
by (107k points)

As your code is not included in a class or method it is expecting those variables to be constants and as such, they should be uppercase.

You can read PEP8 for further information.

Want to become a Python Developer? Check out this insightful Python Certification course.

Related questions

0 votes
4 answers
+1 vote
3 answers
0 votes
1 answer
asked Jul 29, 2019 in Python by Rajesh Malhotra (19.9k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...