473,386 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Database has many "decimal"s which may be null and I need "float"s

bartonc
6,596 Expert 4TB
Most of the lines in this fuction deal with null data and default data:

Expand|Select|Wrap|Line Numbers
  1.     def FillFromDB(self):
  2.         gradeSense = None
  3.         slopeSense = None
  4.         gradeOffset = None
  5.         slopeOffset = None
  6.         varList = (gradeSense, slopeSense, gradeOffset, slopeOffset)
  7.         cursor = self.dbServer.Execute("SELECT * FROM `HETAP_Setup`.`setup`")
  8.         if cursor.rowcount:
  9.             rows = cursor.fetchall()
  10.             for i, var in enumerate(varList):
  11.                 try:
  12.                     var = float(rows[0][i+2])
  13.                 except TypeError:
  14.                     pass
  15.             for row in rows:
  16.                 self.sernumComboBox.Append(row[1])
  17.         self.gradeSense = gradeSense or Multiply.DefaultTiltSense
  18.         self.slopeSense = slopeSense or Multiply.DefaultTiltSense
  19.         self.gradeOffset = gradeOffset or Multiply.DefaultOffset
  20.         self.slopeOffset = slopeOffset or Multiply.DefaultOffset
Nov 28 '06 #1
3 1155
bartonc
6,596 Expert 4TB
Did anybody notice that this doesn't work? Apparently, in dereferences var...
Dec 1 '06 #2
bartonc
6,596 Expert 4TB
Did anybody notice that this doesn't work? Apparently, in dereferences var...
I just got too cute. I guess this might be even cleaner:


Expand|Select|Wrap|Line Numbers
  1.     def FillFromDB(self):
  2.         varList = []
  3.         cursor = self.dbServer.Execute("SELECT * FROM `HETAP_Setup`.`setup`")
  4.         if cursor.rowcount:
  5.             rows = cursor.fetchall()
  6.             for i in range(4):
  7.                 try:
  8.                     varList.append(float(rows[0][i+2]))
  9.                 except TypeError:
  10.                     varList.append(None)
  11.             for row in rows:
  12.                 self.sernumComboBox.Append(row[1])
  13.         self.gradeSense = varList[0] or Multiply.DefaultTiltSense
  14.         self.slopeSense = varList[1] or Multiply.DefaultTiltSense
  15.         self.gradeOffset = varList[2] or Multiply.DefaultOffset
  16.         self.slopeOffset = varList[3] or Multiply.DefaultOffset
  17.         self.ShowOffsets()
Dec 1 '06 #3
bartonc
6,596 Expert 4TB
Actually, there is a way to initialize a list of variables and have access to them outside the list. This is what I was shooting for in the original post:


>>> [a,b,c,d] = [i for i in range(4)]
>>> print a
0
>>> print d
3
>>>
Dec 2 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: geskerrett | last post by:
We are working on a project to decipher a record structure of an old accounting system that originates from the late80's mid-90's. We have come across a number format that appears to be a "float"...
22
by: bq | last post by:
Hello, Two questions related to floating point support: What C compilers for the wintel (MS Windows + x86) platform are C99 compliant as far as <math.h> and <tgmath.h> are concerned? What...
60
by: K. G. Suarez | last post by:
Hello everyone. I am new to programming and my uncle gave me a copy of "C For Dummies 2nd Edition". I am up to chapter 9 right now. He probably saw me struggling with "The C Programming...
3
by: Cybertof | last post by:
Hello, I would like to return the good single value from a string value in these cases : Convert.ToSingle("23,30"); Convert.ToSingle("23.30"); // Conversion Error !!! The result should be...
16
by: John Kelsey | last post by:
Back in the "old" days with C, I used to do something like... struct { char Description; float price; } Items = { {"Apple", 1.99}, {"Banana", 2.04}
5
by: Bob | last post by:
Hello Folks, I am bring backa data reader dr from the database/ So I have a number of fields such as dr To put this in a table I use "<td>" + dr.ToString() + "</td>" But I want to...
3
by: nineoo | last post by:
To all, Ok , now this may sound a little crazy, but does any one know if there is a way to increase the maximum value of a unsigned long int? I'm aware of the the max value of an...
29
by: candy_init | last post by:
Hi all, I just came across the following program: #include <stdio.h> int main() { float a = 12.5; printf("%d\n", a); printf("%d\n", *(int *)&a); return 0;
7
by: Ahmedhussain | last post by:
Hi, My application creates a thread for the conversion of several strings. I have an eventhandler called app.finished, but unfortunately, it is never called. Can any one tell me why? The code is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.