Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
python single and multiple onclick button operations

How do i trigger an operation if a button is clicked for the first time , but if pressed again do extra thing.

if request.method == 'POST':   # if i press a button on the client side, (obj_list) return something like this [0.3, 2.32, 1.22] passed here through ajax (no problem here)
    x = 1
    obj_db = []
    for obj_items in obj_list:     
         should_sum  = False
         while not should_sum:
             x *= obj_items
             #return only two decimal numbers after float number  
             new_obj_num  = round(obj_total, 2)
             obj_db.append(new_obj_num)
             print('stored value  : ', obj_db)
            if object_selected:
              obj_db += obj_items
            else:
              should_sum = True

now, when i click a button i need the obj_list data to get multiplied, and store the results in obj_db(which i've done). But when i click again (from client side), i need to multiply but sum with the previous stored results. Any Suggestions ??!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As we talked in the comments you need to save your counter to know how many times anyone clicked.

# try to read the counter stored in a file 
try:
    f = open("counter.txt", "r")
    data_returned_as_str = f.read()
    counter = int(data_returned_as_str)
except FileNotFoundError as e:
     counter = 0 

# do your stuff

counter += 1
f = open("counter.txt", "w") # use write to overwrite the last content
f.write(str(counter))
f.close()

print(counter)

If you also need the previous data write another file to read that.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!