I need help with the following
When you run it like the following:
python3 decorator.py CrocodileLikesStrawberries
The token "CrocodileLikesStrawberries" allows you to interact with
the functions.
This code is OK, but there is repetition with the checks for auth_token. We could pull this out into it's own function, but what is even better design is to use a decorator. Create an authorise decorator and use it with the refactored code given below.
import sys
MESSAGE_LIST = []
@authorise
def get_messages():
return MESSAGE_LIST
@authorise
def add_messages(msg):
global MESSAGE_LIST
MESSAGE_LIST.append(msg)
if __name__ == '__main__':
auth_token = ""
if len(sys.argv) == 2:
auth_token = sys.argv[1]
add_messages(auth_token, "Hello")
add_messages(auth_token, "How")
add_messages(auth_token, "Are")
add_messages(auth_token, "You?")
print(get_messages(auth_token))
import sys
MESSAGE_LIST = []
auth_token = ""
def authorise(func):
def validate_token():
global auth_token
"""
Here you can write validation code for token
if(auth_token!="CrocodileLikesStrawberries"):
"""
validate_token()
return func
def get_messages():
return MESSAGE_LIST
def add_messages(msg):
global MESSAGE_LIST
MESSAGE_LIST.append(msg)
if __name__ == '__main__':
if len(sys.argv) == 2:
global auth_token
auth_token = sys.argv[1]
authorise(add_messages( "Hello"))
authorise(add_messages("How"))
authorise(add_messages("Are"))
authorise(add_messages("You?"))
print(authorise(get_messages()))
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
authorise here acts as the required decorator. func calls the method passed as the argument (like add_messages). return func helps in using get_messages calls using authorise. For every call using authorise, validate_token will be called which can be used for token identification. This validation can be put out of decorator and called once using the func reference similar to add_messages.
I need help with the following When you run it like the following: python3 decorator.py CrocodileLikesStrawberries...
Hi, I am current using flask to run a python web application that currently just allows users to access a video camera on a localhost. As of now, I need to type python main.py to actually run the project and turn on the localhost. What I want to do is, be able to click a button in HTML, through google chrome, and just run the webcam like that. To sum it up, I want to click a simple button and...
I need help with the adding the following to my python code (also provided below) M5A6Part2 ⦁ When a user successfully votes, add the user’s voterID to the _voterIDsVoted list ⦁ When a user successfully votes, increment the value of the variable that counts the votes for the candidate the user voted for. This would be either _candidateAVotes or _candidateBVotes Hint: run your original test code again. If you reused a valid voter ID in your tests it should cause...
%%%%Python Question%%% Work from the template acrostic.py, which you can find on the ELMS page for this assignment. • In the Generator class, write an __init__() method with two parameters: self and the path to a text file containing one word per line. This method should read the words from the file, strip off leading and trailing whitespace, and store them in a dictionary where each key is a lower-case letter and each corresponding value is a list of words...
I need help ASAP on this, this is due at midnight PST. This is the current code I have. How can I allow the user to quit. My counting while loop works fine, but I would like it to not keep outputting username if a file was successfully opened. This is what is required. Prompt You have assumed the role of managing the technology infrastructure at a zoo. You will develop a working program (either an authentication system or a...
need help to complete the task: app.py is the Python server-side application. It includes a class for representing the list of albums. You need to complete the missing parts such that it loads data from the data/albums.txt and data/tracks.txt files. You can decide what internal data structure you want to use for storing the data. It is already implemented that a single instance of the Albums class is used, so that loading from the files happens only once (and not...
12p
I need help this is Python
EXCEPTIONS: It's easier to ask forgiveness than permission. Try the code and catch the errors. The other paradigm is 'Look before you leap' which means test conditions to avoid errors. This can cause race conditions. 1.Write the output of the code here: class MyError(Exception): pass def notZero(num): if num == 0: raise MyError def run(f): try: exec(f) except TypeError: print("Wrong type, Programmer error") except ValueError: print("We value only integers.") except Zero Division Error:...
Please answer this question using python programming only and provide a screen short for this code. Homework 3 - Multiples not less than a number Question 1 (out of 3) This homework is a SOLO assignment. While generally I encourage you to help one another to learn the material, you may only submit code that you have composed and that you understand. Use this template to write a Python 3 program that calculates the nearest multiple of a number that...
Hey I have a task which consists of two part. Part A asks for
writing a program of WORD & LINE CONCORDANCE
APPLICATION in python which I have completed it.
Now the second part has given 5 dictionary implementation codes
namely as: (ChainingDict, OpenAddrHashDict with linear probing,
OpenAddrHashDict with quadratic probing, and 2 tree-based
dictionaries from lab 12 (BST-based dictionary implementation) and
asks for my above program WORD & LINE CONCORDANCE
APPLICATION to use these implemented code and
show the time...
I need help with my code when I run my code running the wrong thing like this After downSize() words.length=60003 wordCount=60003 vowelCount=206728 this is my code here import java.io.*; import java.util.*; public class Project02 { static final int INITIAL_CAPACITY = 10; public static void main (String[] args) throws Exception { // ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) ...
My Python file will not work below and I am not sure why, please help me debug! ********************************* Instructions for program: You’ll use these functions to put together a program that does the following: Gives the user sentences to type, until they type DONE and then the test is over. Counts the number of seconds from when the user begins to when the test is over. Counts and reports: The total number of words the user typed, and how many...