Someone decided to mess with your code

About time I changed the Twitter password. Hmmm... Interesting code, but it would be great if it printed a message every time it sent a tweet. I think I'll just improve it a little...

One of the Starbuzz coders decided that the password should be set at the start of the program, where it can be easily amended in the future. This is what she added:

About time I changed the Twitter password. Hmmm... Interesting code, but it would be great if it printed a message every time it sent a tweet. I think I'll just improve it a little...

import urllib.request import time def set_password():

password="C8H10N4O2" ^This is the new password.

The dodev wants to set the password at the top of the +ile where it's easy to def send_to_twitter(msg):

password_manager = urllib.request.HTTPPasswordMgr() password_manager.add_password("Twitter API",

"http://twitter.com/statuses", "starbuzzceo set_password()

Mse the value of password" here.

i password)

So, later in the program, the code uses the password variable. That means that next time the password needs to be changed, it will be easier to find it in the code because it is set right near the top of the file.

Was this article helpful?

0 0

Post a comment