I don't understand the error message int not iterable in my code

Thom G
import sqlite3
import math
import Dish_vol

try:
    conn = sqlite3.connect('C:\\Users\\TJgro\\Desktop\\NEW_ATG\\\
Databases\\\Systems.db')
    print("Connection Successful")
except:
    print("Unsuccessful connection")

c=conn.cursor()

c.execute("DROP TABLE IF EXISTS Tanks")

c.execute("CREATE TABLE Tanks \
(ID INT PRIMARY KEY NOT NULL,\
DIR_Tag VARCHAR(255) NOT NULL,\
PRO_Type INT NOT NULL,\
PRO_Shape INT NOT NULL,\
DIR_Radius INT NOT NULL,\
DIR_Dish1 INT NOT NULL,\
DIR_Dish2 INT NOT NULL,\
DIR_Length INT NOT NULL,\
DIR_Capacity INT NOT NULL,\
DIR_HighAlarm INT NOT NULL,\
DIR_LowAlarm INT NOT NULL,\
DIR_WaterAlarm INT NOT NULL,\
DIR_Hysteresis INT NOT NULL,\
DIR_Area VARCHAR(255) NOT NULL,\
DIR_LevelOffset INT NOT NULL,\
DIR_SpecificGravity INT NOT NULL,\
DIR_MoveCount INT NOT NULL,\
DIR_MinMovement INT NOT NULL,\
DIR_MinimumDelivery  INT NOT NULL,\
DIR_MinimumTheft INT NOT NULL,\
DIR_DeliveryGap INT NOT NULL,\
DIR_ProbeRange INT NOT NULL,\
PRO_TCPVolumeEnable INT NOT NULL,\
PRO_TCPUllageEnable INT NOT NULL,\
PRO_TCPTemperatureEnable INT NOT NULL,\
VAR_Pressure INT NOT NULL,\
VAR_LevelReg INT NOT NULL,\
AUX_Ullage INT NOT NULL,\
VAR_HMI_1_Volume INT NOT NULL,\
VAR_HMI_1_Ullage INT NOT NULL,\
VAR_HMI_1_Temperature INT NOT NULL,\
VAR_HMI_2_Volume INT NOT NULL,\
VAR_HMI_2_Ullage INT NOT NULL,\
VAR_HMI_2_Temperature INT NOT NULL,\
VAR_HMI_3_Volume INT NOT NULL,\
VAR_HMI_3_Ullage INT NOT NULL,\
VAR_HMI_3_Temperature INT NOT NULL,\
VAR_AlarmRelayReg INT NOT NULL)")

for t in [(0, 'xyz', 'abc', 5, 15, 1371, 1500, 1500, 9144, 0, 0, 0, \
       0, 0, 10, 1, 1, 0, 0, 0, 0, 0, 2500, 0, 0, 0,\
       1000, 1000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      (1, 'xyz', 'abc', 5, 10, 1371, 1500, 1500, 9144, 0, 0, 0, \
       0, 0, 10, 1, 1, 0, 0, 0, 0, 0, 2500, 0, 0, 0,\
       1000, 1000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      (2, 'xyz', 'abc', 5, 12, 1371, 1500, 1500, 9144, 0, 0, 0, \
       0, 0, 10, 1, 1, 0, 0, 0, 0, 0, 2500, 0, 0, 0,\
       1000, 1000, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
      ]:

c.execute("INSERT INTO Tanks VALUES\
(?,?,?,?,?,?,?,?,\
?,?,?,?,?,?,?,?,\
?,?,?,?,?,?,?,?,\
?,?,?,?,?,?,?,?,\
?,?,?,?,?,?,?)",t)

After creating the table and populating it, I have some calculations i need to perform, so I select the required fields form the database:

c.execute("SELECT DIR_Dish1 FROM Tanks")
DIR_Dish1 = c.fetchall()
print (DIR_Dish1)
c.execute("SELECT DIR_Radius FROM Tanks")
DIR_Radius = c.fetchall()
print (DIR_Radius)
c.execute("SELECT VAR_LevelReg FROM Tanks")
VAR_LevelReg = c.fetchall()
print (VAR_LevelReg)
c.execute("SELECT DIR_Length FROM Tanks")
DIR_Length = c.fetchall()
print (DIR_Length)

Now I have the variables, I have some calculations:

dish1Volume = Dish_vol.Dish_Vol(DIR_Radius, DIR_Dish1, VAR_LevelReg)

for row in c.execute("SELECT DIR_Radius, VAR_LevelReg, DIR_Length FROM Tanks"):
for [DIR_Radius, VAR_LevelReg, DIR_Length] in row:
    cylinderVolume = ((( DIR_Radius * DIR_Radius) * math.acos((DIR_Radius - VAR_LevelReg ) / DIR_Radius)) - \
               ((DIR_Radius - VAR_LevelReg) * math.sqrt((DIR_Radius * DIR_Radius) - \
               ((DIR_Radius - VAR_LevelReg) * (DIR_Radius - VAR_LevelReg))))) * (DIR_Length / 1000.0)

    volume = cylinderVolume / 1000.0

    Total = volume + dish1Volume + dish1Volume 
    print (Total)

I get the error message:

 Traceback (most recent call last):
 File "C:\Users\TJgro\workspace\SQLite Practise\Dish_Vol\Cylinder_Vol    \__init__.py", line 91, in <module>
 for [DIR_Radius, VAR_LevelReg, DIR_Length] in row:
TypeError: 'int' object is not iterable

I understand that the variables DIR_Dish1 etc are integers but in another part of the code the same syntax produces the desired results:

for row in c.execute("SELECT DIR_Dish1 FROM Tanks"): 
for DIR_Dish1 in row:
    if DIR_Dish1 > 0.001:
        int1 = math.pi * DIR_Dish1
        int3 = 4 * DIR_Dish1 * DIR_Dish1

How do I make the loop in a way that I can iterate through the database using the three variables I need?

Martijn Pieters

Each row is a tuple with column values. You try to loop over a row and unpack each column value into 3 separate names:

for [DIR_Radius, VAR_LevelReg, DIR_Length] in row:

This has the following effect on the first column value in any given row:

>>> [DIR_Radius, VAR_LevelReg, DIR_Length] = 42
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not iterable

Simply use assigment of the row, directly, without a for loop:

DIR_Radius, VAR_LevelReg, DIR_Length = row

The square brackets are not really needed here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Don't understand error message

From Dev

Error: $injector:modulerr Module Error seems there is an injection error in my directive but I don't understand whats wrong in my code

From Dev

My Selenium Webdriver script is returning an error that I don't understand

From Dev

My Selenium Webdriver script is returning an error that I don't understand

From Dev

I don't understand a JavaScript code snippet

From Dev

I don't understand the decimal to binary code

From Dev

I don't understand a JavaScript code snippet

From Dev

I don't understand how this code works?

From Dev

Node require - i don't understand this code

From Dev

Error 2025 that I absolutely don't understand

From Dev

Error with method arguments that I don't understand

From Dev

I don't understand why my code for bubble sort does not work

From Dev

Infinite loop in my code and I don't understand where it comes from

From Dev

I don't understand why my code for bubble sort does not work

From Dev

Haskell parse error in my xmonad.hs config that i don't understand?

From Dev

Don't understand the error message : Invalid syntax in for statement

From Dev

Don;t understand error

From Dev

SQL DB Power Shell Connection Code error I don't understand

From Dev

I don't understand the NewNotImplementedException runtime error I'm getting

From Dev

I don't understand why I get this valgrind error

From Dev

I don't understand a valgrind error I'm getting

From Dev

C++ I don't understand my exceptions what() behavior

From Dev

Next is not defined, but I don't understand how to define it in my function

From Dev

C++ I don't understand my exceptions what() behavior

From Dev

i dont understand why my "if" command don't work as it should

From Dev

htaccess rewrite ?p= (I don't understand the code)

From Dev

A code I don't understand about switching scenes in JavaFX and SceneBuilder

From Dev

I don't understand the significance of the following javascript code:

From Dev

C# I don't understand the code after the constructor

Related Related

  1. 1

    Don't understand error message

  2. 2

    Error: $injector:modulerr Module Error seems there is an injection error in my directive but I don't understand whats wrong in my code

  3. 3

    My Selenium Webdriver script is returning an error that I don't understand

  4. 4

    My Selenium Webdriver script is returning an error that I don't understand

  5. 5

    I don't understand a JavaScript code snippet

  6. 6

    I don't understand the decimal to binary code

  7. 7

    I don't understand a JavaScript code snippet

  8. 8

    I don't understand how this code works?

  9. 9

    Node require - i don't understand this code

  10. 10

    Error 2025 that I absolutely don't understand

  11. 11

    Error with method arguments that I don't understand

  12. 12

    I don't understand why my code for bubble sort does not work

  13. 13

    Infinite loop in my code and I don't understand where it comes from

  14. 14

    I don't understand why my code for bubble sort does not work

  15. 15

    Haskell parse error in my xmonad.hs config that i don't understand?

  16. 16

    Don't understand the error message : Invalid syntax in for statement

  17. 17

    Don;t understand error

  18. 18

    SQL DB Power Shell Connection Code error I don't understand

  19. 19

    I don't understand the NewNotImplementedException runtime error I'm getting

  20. 20

    I don't understand why I get this valgrind error

  21. 21

    I don't understand a valgrind error I'm getting

  22. 22

    C++ I don't understand my exceptions what() behavior

  23. 23

    Next is not defined, but I don't understand how to define it in my function

  24. 24

    C++ I don't understand my exceptions what() behavior

  25. 25

    i dont understand why my "if" command don't work as it should

  26. 26

    htaccess rewrite ?p= (I don't understand the code)

  27. 27

    A code I don't understand about switching scenes in JavaFX and SceneBuilder

  28. 28

    I don't understand the significance of the following javascript code:

  29. 29

    C# I don't understand the code after the constructor

HotTag

Archive