AttributeError: 'Images' object has no attribute 'pop' - python

I am working with this code so I have my main code here:
from draw_image import Images
start = Images()
start.display_image()
start.delete_line()
start.display_image()
and this is my draw_image code:
class Images:
def image(jumper_image):
"""This function is to create the list"""
jumper_image = []
def display_image(jumper_image):
"""This is how the user will see the image correctly through the loop"""
jumper_image = [
" ___ ",
" /___\ ",
" \ / ",
" \ / ",
" o ",
" /|\ ",
" / \ ",
" ",
"^^^^^^^^^^^"
]
for image in jumper_image:
print(image)
return jumper_image
def delete_line(jumper_image):
""" This function is supposed to delete the first line of the jumper_image"""
jumper_image.pop(0)
It seems that the delete_line function is not recognizing the list, do you guys have any idea why this is happening? or what would be a solution for this problem?

I would recommend using a python constructor to initialize jumper_image:
class Images:
def __init__(self):
self.jumper_image = [
" ___ ",
" /___\ ",
" \ / ",
" \ / ",
" o ",
" /|\ ",
" / \ ",
" ",
"^^^^^^^^^^^"
]
def display_image(self):
"""This is how the user will see the image correctly through the loop"""
for image in self.jumper_image:
print(image)
def delete_line(self):
""" This function is supposed to delete the first line of the jumper_image"""
self.jumper_image.pop(0)
start = Images()
start.display_image()
start.delete_line()
print('After deleting first value in list\n')
start.display_image()
___
/___\
\ /
\ /
o
/|\
/ \
^^^^^^^^^^^
After deleting first value in list
/___\
\ /
\ /
o
/|\
/ \
^^^^^^^^^^^

Related

I was creating a bot to snipe hypixel api discord bot but its creating a error by channel.send_message ,

done = default_timer() - START_TIME
if op:
winsound.Beep(500, 500) # emits a frequency 500hz, for 500ms
for result in results:
profit = result[1] - result[0][2]
print("/viewauction " + str(result[0][0]) + " | Item Name: " + str(result[0][1]) + " | Item price: {:,}".format(result[0][2]) + " | Profit : {:,}".format(profit) + " | Time to refresh AH: " + str(round(done, 2)))
print('\x1b[6;30;42m' + 'Sniping Auctions :)' + '\x1b[0m')
channel = client.get_channel(954629794224566302)
channel.send_message("/viewauction " + str(result[0][0]) + " | Item Name: " + str(result[0][1]) + " | Item price: {:,}".format(result[0][2]) + " | Profit : {:,}".format(profit) + " | Time to refresh AH: " + str(round(done, 2)))
This code is not very helpful and provide the error message.
btw channel.send_message() is replaced with channel.send()

I am getting an error: "UnboundLocalError: local variable 'text_to_print' referenced before assignment"

def search():
def back():
searchwindow.destroy()
def submit():
inputID = ID.get()
if inputID == "":
messagebox.showerror("Error", "Please Enter An ID")
elif len(inputID) != 6:
messagebox.showerror("Error", "ID Must Be 6 Characters Long")
else:
cursor.execute(("SELECT * FROM tblRoomAllocation WHERE roomID = ?"), (inputID,))
records = cursor.fetchall()
for record in records:
text_to_print = str(record[0]) + " | " + str(record[1]) + " | " + str(record[2]) + " | " + str(record[3]) + " | " + str(record[4])
messagebox.showinfo("Search Results", text_to_print)
I tried to make "text_to_print" global and it is still giving me the same error. I am only a beginner to this so please help out. Thank you for any help.
Put the last line in the else:
for record in records:
text_to_print = str(record[0]) + " | " + str(record[1]) + " | " + str(record[2]) + " | " + str(record[3]) + " | " + str(record[4])
if records:
messagebox.showinfo("Search Results", text_to_print)

TypeError: write() takes exactly one argument (2 given) python

elif choice == "A":
def add_task(count):
with open ( 'user.txt' ) as fin:
usernames = [ i.split ( ',' ) [ 0 ] for i in fin.readlines ( ) if len ( i ) > 3 ]
task = input ( "Please enter the username of the person the task is assigned to.\n" )
while task not in usernames:
task = input ( "Username not registered. Please enter a valid username.\n" )
else:
task_title = input ( "Please enter the title of the task.\n" )
task_description = input ( "Please enter the task description.\n" )
task_due = input ( "Please input the due date of the task. (yyyy-mm-dd)\n" )
date = datetime.date.today ( )
task_completed = False
if task_completed == False:
task_completed = "No"
else:
task_completed = ("Yes")
with open ( 'tasks.txt' , 'a+' ) as task1:
count = count + 1
task1.write ( "\n User assigned to task: " , str (
count ) + "\n" + task + "\nTask Title :" + "\n" + task_title + "\n" + "Task Description:\n" + task_description + "\n" + "Task Due Date:\n" + str (
task_due ) + "\n" + "Date Assigned:\n" + str (
date ) + "\n" + "Task Completed:\n" + task_completed + "\n" )
file.close ( )
print ( "The new assigned task has been saved" )
count = 0
add_task ( count )
Replace
task1.write ( "\n User assigned to task: " , str (
count ) + "\n" + task + "\nTask Title :" + "\n" + task_title + "\n" + "Task Description:\n" + task_description + "\n" + "Task Due Date:\n" + str (
task_due ) + "\n" + "Date Assigned:\n" + str (
date ) + "\n" + "Task Completed:\n" + task_completed + "\n" )
With
task1.write ( "\n User assigned to task: " + str (
count ) + "\n" + task + "\nTask Title :" + "\n" + task_title + "\n" + "Task Description:\n" + task_description + "\n" + "Task Due Date:\n" + str (
task_due ) + "\n" + "Date Assigned:\n" + str (
date ) + "\n" + "Task Completed:\n" + task_completed + "\n" )
You concatenate the first two strings with a comma, while all other strings are concatenated by a + sign.
You have to change the task1.write line:
It should be:
task1.write ( "\n User assigned to task: " + str (count) + "\n" + task + "\nTask Title :" + "\n" + task_title + "\n" + "Task Description:\n" + task_description + "\n" + "Task Due Date:\n" + str (task_due) + "\n" + "Date Assigned:\n" + str (date ) + "\n" + "Task Completed:\n" + task_completed + "\n" )

How to fix stopping loop in following code

I'm working at parser. Loop breaks after exception. Need ur help
def requestBarter():
response = requests.get(api url)
return response.json();
def responsePrint(id, json_data):
title = json_data[id]["title"]
tradable = json_data[id]["tradable"]
wishlist = json_data[id]["wishlist"]
library = json_data[id]["library"]
bundles = json_data[id]["bundles"]
cards = json_data[id]["cards"]
userreviews = json_data[id]["userreviews"]
print("ID: " + id + " | Titile: " + title + " | Tradable: " + str(tradable) + " | Wishlist: " + str(
wishlist) + " | Library: " + str(
library) + " | Bundles: " + str(bundles) + " | Cards: " + str(cards) + " | Userreviews: " + str(userreviews))
def responsePrintOnException(id, json_data):
title = json_data[id]["title"]
tradable = json_data[id]["tradable"]
wishlist = json_data[id]["wishlist"]
library = json_data[id]["library"]
bundles = json_data[id]["bundles"]
cards = json_data[id]["cards"]
print("ID: " + id + " | Titile: " + title + " | Tradable: " + str(tradable) + " | Wishlist: " + str(
wishlist) + " | Library: " + str(
library) + " | Bundles: " + str(bundles) + " | Cards: " + str(cards))
def getAll():
try:
json_data = requestBarter()
for id in json_data:
responsePrint(id, json_data)
except KeyError:
responsePrintOnException(id, json_data)
pass
if __name__ == '__main__':
getAll()
After KeyError getting out of loop so need help in the following code
Expected over 90000 lines. actual output - 30

Get field name from an object retrieved by orm query

I have a small Django app, and when I query my DB with django orm I get my objects list.
What I want is the name of the db column where the query has matched.
Is possible?
Thanks in advance!
results = Verbs.objects.filter(
Q(fps__icontains = " " + word_name + " ") | Q(fps__endswith = " " + word_name) | Q(fps__startswith = word_name + " ") |
Q(sps__icontains = " " + word_name + " ") | Q(sps__endswith = " " + word_name) | Q(sps__startswith = word_name + " ") |
Q(tps__icontains = " " + word_name + " ") | Q(tps__endswith = " " + word_name) | Q(tps__startswith = word_name + " ") |
Q(fpp__icontains = " " + word_name + " ") | Q(fpp__endswith = " " + word_name) | Q(fpp__startswith = word_name + " ") |
Q(spp__icontains = " " + word_name + " ") | Q(spp__endswith = " " + word_name) | Q(spp__startswith = word_name + " ") |
Q(tpp__icontains = " " + word_name + " ") | Q(tpp__endswith = " " + word_name) | Q(tpp__startswith = word_name + " ")
).all()
What I want is the name of field where the query as matched. For example: fps or fpp ...
I think this is what you want--for each returned row it will print the matched fields, indented:
fields = ('fps', 'sps', 'tps', 'fpp', 'spp', 'tpp')
for r in results.values():
print 'Row with id=%s:' % r['id']
for f in fields:
if word_name in str(r[f]):
print ' Field %s matches' % f
Edited to account for non-string values and to look only at the desired fields.

Categories

Resources