What is the exit code -1073740791 (0xC0000409)? - pyqt5

def yetkiligoruntule(self):
self.ui.tableWidgetYetkilileriGoster.setRowCount(0)
query = "SELECT yetkili_id, yetkili_ad, yetkili_soyad, yetkili_num, yetkili_mail, yetkili_poz FROM yetkili"
result = cur.execute(query,).fetchall()
for row in result:
rowNumber = self.ui.tableWidgetYetkilileriGoster.rowCount()
self.ui.tableWidgetYetkilileriGoster.insertRow(rowNumber)
for columnNumber, data in enumerate(row):
self.ui.tableWidgetYetkilileriGoster.setItem(rowNumber, columnNumber, QTableWidgetItem(str(data)))
def yetkiliAra(self):
value = self.ui.lineEditYetkiliAra.text()
if value == "":
QMessageBox.warning(self,"Uyari","Lutfen yetkili adi giriniz!")
self.ui.lineEditYetkiliAra.setText("")
else:
query = "SELECT yetkili_id, yetkili_ad, yetkili_soyad, yetkili_num, yetkili_mail, yetkili_poz FROM yetkili WHERE yetkili_ad LİKE? or yetkili_soyad LİKE?"
result = cur.execute(query,('%' + value + '%','%' + value + '%'))
if result == []:
QMessageBox.warning(self,"Uyari","Kullanici Bulunamadi!")
self.ui.lineEditYetkiliAra.setText("")
return
else:
**self.ui.tableWidgetYetkilileriGoster.setRowCount(0)**
for row in result:
rowNumber = self.ui.tableWidgetYetkilileriGoster.rowCount()
self.ui.tableWidgetYetkilileriGoster.insertRow(rowNumber)
for columnNumber, data in enumerate(row):
self.ui.tableWidgetYetkilileriGoster.setItem(rowNumber, columnNumber, QTableWidgetItem(str(data)))
I think this line (which is bold) is the exact problem. Bu don't know how to solve it. Is there someone for help?
Just try ask here. I try to 'setRowCount()' like this without 0 but it doesn't work.

Related

Dynamic raw query (select clause) Django

I'm trying to execute a raw query in Django where I dynamically want to pick column names.
Eg
def func(all=True){
if all:
query_parameters = {
'col': '*'
}
else:
query_parameters = {
'col': 'a,b,c'
}
with connections["redshift"].cursor() as cursor:
cursor.execute(
"select %(col)s from table limit 2 ;",
query_parameters,
)
val = dictfetchall(cursor)
return val
}
Django is executing it like.
select "*" from table limit 2;
so the output is just like select "*"
*
and in the else case it is executed like
select "a,b,c" from table limit 2;
so the output is a,b,c
How can I run the command so that Django run it like
select a , b , c from table limit 2
so that the output is
a b c
1 2 3
4 5 6
I found a hack myself.
See Here
Explanation
Prepared query step by step
Input data (Columns I need)
self.export_col = “a,b,c”
def calc_col(self):
if self.exp == 'T':
select_col = ""
self.export_col = self.export_col.split(',')
for col in self.export_col:
select_col += col + ","
select_col = select_col[:-1]
self.export_col = select_col
else:
self.export_col += '*'
def prepare_query(self):
query += " SELECT "
query += self.export_col
query += """ from table limit 2;"""

No method matching error when working with Vector{Int64]

I have the following code where firstly I add the values for each index from two columns and creating Vector{Int64}
df = CSV.read(joinpath("data", "data.csv"), DataFrame)
adding_columns = df.firstcolumn + df.secondcolumn
Then I will create a function as following:
function fnct(data::Vector{T}; var= 8) where { T <: Number }
V = []
for x in 1:size(data)[1]
strt = x-var
ending = x+var
avg = 0
if strt < 1
for y in 1:x+var
avg = avg+data[y]
end
avg = avg/(x+var-1)
elseif ending > size(data)[1]
for y in x-var:size(data)[1]
avg = avg+data[y]
end
avg = avg/(size(data)-x-var)
else
for y in x-var:x+var
avg = avg+data[y]
end
avg = avg/(2*var)
end
push!(V,avg)
end
return V
end
When trying:
typeof(adding_columns)
I will get:
Vector{Int64}
however when calling
fnct(adding_columns)
I will get:
ERROR: MethodError: no method matching -(::Tuple{Int64}, ::Int64)
I presume that it takes my adding_columns as Tuple but I do not get it why, when the typeof is giving me Vector.
How could I solve this problem?
size(data) is a tuple:
julia> size([1,2,3]::Vector{Int})
(3,)
...but you're subtracting an integer from it in avg = avg/(size(data)-x-var).
Did you mean avg = avg/(length(data)-x-var) or avg = avg/(size(data, 1)-x-var)?

Iterate over an xpath (table row) python

I have xpaths as follow:
/html/body/div[1]/table[3]/tbody/tr[1]/td[3]/a
/html/body/div[1]/table[3]/tbody/tr[2]/td[3]/a
/html/body/div[1]/table[3]/tbody/tr[3]/td[3]/a
/html/body/div[1]/table[3]/tbody/tr[4]/td[3]/a
As you can see, the tr[] values are changing. I want iterate over these values.
Below is the code I have used
search_input = driver.find_elements_by_xpath('/html/body/div[1]/table[3]/tbody/tr[3]/td[3]/a')
Please let me know How can I iterate over them.
This may not be the exact solution you are looking for but this is the idea.
tableRows = driver.find_elements_by_xpath("/html/body/div[1]/table[3]/tbody/tr")
for e in tableRows:
e.find_element_by_xpath(".//td[3]/a")
if you want all third td for every row, use this:
search_input = driver.find_elements_by_xpath('/html/body/div[1]/table[3]/tbody/tr/td[3]/a')
If you want only the first 3 rows use this:
search_input = driver.find_elements_by_xpath('/html/body/div[1]/table[3]/tbody/tr[position() < 4]/td[3]/a')
For looping through tds look I.e. this answer
Another alternative, assuming 4 elements:
for elem in range(1,5):
element = f"/html/body/div[1]/table[3]/tbody/tr[{elem}]/td[3]/a"
#e = driver.find_element_by_xpath(element)
#e.click()
print(element)
Prints:
/html/body/div[1]/table[3]/tbody/tr[1]/td[3]/a
/html/body/div[1]/table[3]/tbody/tr[2]/td[3]/a
/html/body/div[1]/table[3]/tbody/tr[3]/td[3]/a
/html/body/div[1]/table[3]/tbody/tr[4]/td[3]/a
You could do whatever you wanted with the elements in the loop, I just printed to show the value
Option 1: Fixed Column number like 3 needs to be be iterated:
rows = len(self.driver.find_elements_by_xpath("/html/body/div[1]/table[3]/tbody/tr"))
for row in range(1, (rows + 1)):
local_xpath = ""/html/body/div[1]/table[3]/tbody/tr[" + str(row) + "]/td[3]"
# do something with element
# cell_text = self.driver.find_element_by_xpath(local_xpath ).text
Option 2: Both Row and Col needs to be iterated:
rows = len(self.driver.find_elements_by_xpath("/html/body/div[1]/table[3]/tbody/tr"))
columns = len(self.driver.find_elements_by_xpath("/html/body/div[1]/table[3]/tbody/tr/td"))
for row in range(1, (rows + 1)):
for column in range(1, (columns + 1)):
local_xpath = ""/html/body/div[1]/table[3]/tbody/tr[" + str(row) + "]/td[" + str(column) + "]"
# do something with element
# cell_text = self.driver.find_element_by_xpath(local_xpath ).text

if elif(conditions) in Jython FDMEE keeps giving wrong result

it shall be a simple if elif(conditions) in jython, but it seems like Jython in FDMEE keeps checking for wrong result in the condition.
def Timetest(strField, strRecord):
import java.util.Date as date
import java.text.SimpleDateFormat as Sdf
import java.lang.Exception as Ex
import java.sql as sql
import java.util.concurrent.TimeUnit as TimeUnit
PerKey = fdmContext["PERIODKEY"]
strDate = strRecord.split(",")[11]
#get maturity date
strMM = strDate.split("/")[0]
strDD = strDate.split("/")[1]
strYYYY = strDate.split("/")[2]
strDate = ("%s.%s.%s" % (strMM,strDD, strYYYY))
#converting Maturity date
sdf = Sdf("MM.dd.yyyy")
strMRD = sdf.parse(strDate)
#calc date diff
diff = (strMRD.getTime()- PerKey.getTime())/86400000
diff = ("%d" % diff)
if diff>="0":
if diff <= "30":
return "Mat_Up1m " + diff
elif diff <= "90":
return "Mat_1to3m " + diff #the result goes here all the time although my diff is 367
elif diff <= "360":
return "Mat_3to12m " + diff
elif diff <= "1800":
return "Mat_1to5y " + diff #the result supposed to go here
else:
return "Mat_Over5y "+ diff
Not sure why it keeps going to the second elif instead of the fourth elif.
My calculation result of diff = 367
any idea on how to make sure that my code read the correct if elif condition?
Hope you have already figured it out, If not then check the mistakes you have made in your script.
In your script you're comparing string "367" with string values "0","90" etc., its not integer comparison, string "367" is always less than string "90" so its going into that elif condition.
Now you have to do integer comparison instead of string comparison and also move your all elif conditions inside the main if condition.
In the return statement you have to convert the interger to string to concatinate diff to a string.
Check the following code, with all the changes.
if diff>=0:
if diff <= 30:
return "Mat_Up1m " + str(diff)
elif diff <= 90:
return "Mat_1to3m " + str(diff)
elif diff <= 360:
return "Mat_3to12m " + str(diff)
elif diff <= 1800:
return "Mat_1to5y " + str(diff)
else:
return "Mat_Over5y "+ str(diff)

Console VB.NET: File Processing - Search file for a specific number and output record

Hello I am building a console application in VB.NET that reads a record file and outputs it to the user. I have gotten the program to output all of the records to the console but I cannot seem to get the search function working.
I want the user to input the record number and for the program to search the text file for that specific record and then output it to the console.
I will leave the read record function here for reference.
Read Records function:
Public Function Read_Records()
File_Name = "drecords.txt"
File_num = FreeFile()
Record_Counter = 0
record_no = 999
If File_Name <> "" Then
Try
FileOpen(File_num, File_Name, OpenMode.Input)
Do Until EOF(File_num)
Record_Counter = Record_Counter + 1
record_no = record_no + 1
records(Record_Counter, 0) = record_no
records(Record_Counter, 1) = LineInput(File_num)
records(Record_Counter, 2) = LineInput(File_num)
records(Record_Counter, 3) = LineInput(File_num)
records(Record_Counter, 4) = LineInput(File_num)
records(Record_Counter, 5) = LineInput(File_num)
Loop
record_ID = Record_Counter
Catch ex As Exception
MsgBox("ERROR OPENING FILE")
Finally
FileClose(File_num)
End Try
End If
Last_Record = Record_Counter
Return records
End Function
I'm not sure exactly what you want, but here are a few examples.
To read a record number from the console and output that record, do something like this:
dim i, k as integer
k = val(console.readline())
for i = 1 to 5
console.writeline(records(k, i))
next i
I'm not sure how else you would identify the record, but, for example, you can search the records for a value of "abc" in the first field like this:
For i = 1 to Last_Record
if records(i, 1) = "abc" then
' output the record to the user
end if
next i
Replace records(i, 1) with records(i, 0) to search for a record number.
If you want to search each field, you can add a nested loop:
For i = 1 to Last_Record
for k = 1 to 5
if records(i, k) = "abc" then
' output the record to the user
end if
next k
next i