Python Forum
Python code suddenly not working anymore
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python code suddenly not working anymore
#1
I have a not too complicated python code that I have used pretty much every day until last week. It just reads an Excel file and lets me pick items and calculate a total (plus some other things). It sat in a folder on my desktop, and double clicking would bring up the application window every time.
Then I had to go on a trip and I moved the folder it was in temporarily off the desktop (last week). Today I restored the code tot he desktop, but double clicking it does not do anything. So I opened the code in Pythin IDLE and when I run it from there it suddenly generates error messages.

In 3.7 I receive the following error message:

File "C:\Users\Mike_b\Desktop\ProductSearch\Product_search.py", line 439, in <module>
App()
File "C:\Users\Mike_b\Desktop\ProductSearch\Product_search.py", line 152, in __init__
self.Types = sorted(tuple(self.productTypes))
TypeError: '<' not supported between instances of 'int' and 'str'

Again, the only thing I did was move the code to a different folder, then back to where it was before.

What could be the reason the code does not run anymore?

Thanks for your help.
Reply
#2
Without seeing any code, it's hard to say. My first guess would be that the Excel spreadsheet has some string values in it where it didn't before (or integer values, it's not clear which it is supposed to be). I would look carefully at tuple(self.productTypes) to make sure it is what your program is expecting.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Thanks for responding. Here is the code immediately preceeding line 152. I understand that you still cannot tell which are string values and which are not, but #Loop through the excel file to create data structure of all desired values, but the error message says: '<' not supported between instances of 'int' and 'str', and I don't see a "<" operator in the code...
        self.CORPproducts = []
        self.productTypes = set()
            #Checks all values in the spreadsheet after the headers
        for row in tuple(self.ws.rows)[2:]:
            if row[0].value != None:
                    #if is a product type not inputted, create a new option for it
                if row[0].value not in self.productTypes:
                    self.productTypes.add(row[0].value)
                    newType = CORPProductList(row[0].value)
                    self.CORPproducts.append(newType)
                    
                    #Loop through the data structure to add entry to correct list
                for product in self.CORPproducts:
                        #For each line/product in the sheet add the entry into data structure
                    if product.Type == row[0].value:
                            #use fuction from data structre to add data to correct storage
                        self.CORPproducts[self.CORPproducts.index(product)].addProduct(
                                productType=row[0].value, productItem=str(row[1].value)+" - 
                                "+str(row[3].value),price1=row[5].value, price3=row[7].value, 
                                price4=row[8].value, country=row[19].value)
            #Sort the values alphabetically and set equal to the possible Types
        self.Types = sorted(tuple(self.productTypes))
I will check if anything in the structure of the sheet was changed.
Reply
#4
Python uses < in the background when sorting things.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
Thanks. I did find the issue:

There is a column in the sheet that is supposed to be string data. Someone made a mistake and entered a number, so the first element of the tuple was always type str, except one row, where it was int. That then threw the "sorted" function.

I tried to set this line:

productType=row[0].value, productItem=str(row[1].value)+" -

to

productType=str(row[0].value), productItem=str(row[1].value)+" -

(specifically typecast the productType to string, but that did not work. Why wouldn't that work?

But...Problem solved.

Thanks for the help.
Reply
#6
I'm not sure why forcing it to string wouldn't help, if that's the column you are having the problem with. On the other hand, if they made a mistake in one column, the could make a mistake in another one.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Information subprocess.Popen() suddenly giving me grief? davecotter 3 607 Dec-13-2023, 10:49 PM
Last Post: davecotter
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 954 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 878 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  print(data) is suddenly invalid syntax db042190 6 1,183 Jun-14-2023, 02:55 PM
Last Post: deanhystad
  New to python/coding Need help on Understanding why this code isn't working. Thanks! mat3372 8 1,740 May-09-2023, 08:47 AM
Last Post: buran
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,003 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,072 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  Python debug suddenly got bad ben1122 3 1,087 Sep-03-2022, 06:20 AM
Last Post: ben1122
  My Code isn't working... End3r 4 1,922 Mar-21-2022, 10:12 AM
Last Post: End3r
  string.format() suddenly causing errors with google drive API zwitrader 0 1,760 Jun-28-2021, 11:38 PM
Last Post: zwitrader

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020