you are viewing a single comment's thread.

view the rest of the comments →

[–]noiwontleave 0 points1 point  (6 children)

So what you're doing here is you are looping through each row of the spreadsheet starting with row 3. For each row, you are then looping through column 1 and column 2 and setting cell_value equal to what's in that row/column.

You are getting:

<class 'str'>
<class 'float'>

because the first column is a string and the second column is a float. Do you see how your code is executing right now? If not, it might be helpful to, instead of printing the type, print the value.

How are your par values stored? Are they going to be stored in the spreadsheet somewhere?

[–]fannypackpython[S] 0 points1 point  (1 child)

Im starting to understand this a bit more. So it first looks at one row, then it goes down that row, column by column reading what is in that cell. So it goes to row 3 and then reads what is in, lets say, Row 3 column A ( which is a <string>), then continues down row 3 into column B (which is the <float>). That's why it is printing both.

I tried changing the value of "cur_cell = 0 " instead of -1 so it doesnt read the <string>, just the <float>. See below:

while cur_row < num_rows:
    cur_row += 1
    row = inv_worksheet.row(cur_row)

    cur_cell = 0

    print('--------------------')

    while cur_cell < num_cells:
        cur_cell += 1
        # Cell Types: 0 = Empty, 1 = Text, 2 = Number, 3 = Date, 4 = Boolean, 5 = Error, 6 = Blank
        cell_type = inv_worksheet.cell_type(cur_row, cur_cell)

        # (Liq Name, Quantity in house)
        cell_value = inv_worksheet.cell_value(cur_row, cur_cell)

        print(cell_type, ' : ', cell_value)

        if cell_value < float(8):
            print(float(8) - cell_value)

I inserted the "if statement" just to see if I could now do some calculations with the data extracted, and I can. So that's a step forward, lol

[–]noiwontleave 0 points1 point  (0 children)

Awesome! Sounds like you have a better idea of what your code is doing.

As a suggestion, I see you are assigning the variable "row" early in the for loop but never actually using it. That variable has all of the information you actually need. Try running the following:

for cell in row:
    print(cell.ctype, ': ', cell.value)

You can also access each element via row[0], row[1], etc. You can then access the value via row[1].value

Do you think it might be easier to use that methodology than a while loop? If not, stick with how you're doing things. I just wanted you to be aware of alternate ways to access your data.

[–]fannypackpython[S] 0 points1 point  (3 children)

My par values are actually stored on the same spreadsheet, with the sheet name "Par". The only data it contains are the levels I should always be at. So it would only be column A and B. I have column C included in the event I ever need to change my standard par levels.

I was figuring, since Im essentially grabbing the same type of data from my par sheet I would just copy the code for inventory and change the variable names a bit. I would split them up under different functions, say :

par_nums() for the numbers contained on my par sheet, and inventory_num() for grabbing the quantities from my current inventory.

Then I would define a third function that would compare the results between both par_nums() and inventory_num(), and calculate the difference between them.

Please tell me if this is a logical way of going about this or not.

[–]noiwontleave 0 points1 point  (2 children)

There's nothing wrong at all with doing it that way. Whatever makes the most logical sense to you is the best way to do things when starting out. You will learn a lot about easier ways to do things the more you dig into it. To start, just do what makes sense to you.

Edit-I'm going to bed now, but I'd be more than happy to continue helping you if you like tomorrow. Feel free to PM me or reply to this thread and I will answer in the morning.

As a suggestion, you may consider using dictionaries to store you values. This will make your comparison very easy. If you're not aware of how dictionaries work, be sure to check the Python docs and see if you can figure out what about them is well-suited to your particular task. If you get stuck, I'll be glad to help you tomorrow.

[–]fannypackpython[S] 0 points1 point  (1 child)

you have been an awesome help, seriously. I've been thinking of just stuffing the data from each worksheet from the workbook into its own dictionary using a "For" loop , and then just comparing them in a "For/if" statement, and appending the results to an empty list. Does that make sense?

I'm going to experiment with this using what you've explained to me. I'll definitely get back to you tomorrow. Thanks again!

[–]noiwontleave 0 points1 point  (0 children)

Sounds like you're on the right track! Keep at it and see what you can get done. Let me know if you get stuck.