This loop checks if a record is in the sqlite database and builds a list of dictionaries for those records that are missing and then executes a multiple insert statement with the list. This works but it is very slow (at least i think it is slow) as it takes 5 minutes to loop over 3500 queries. I am a complete newbie in python, sqlite and sqlalchemy so I wonder if there is a faster way of doing this.
list_dict = []
session = Session()
for data in data_list:
if session.query(Class_object).filter(Class_object.column_name_01 == data[2]).filter(Class_object.column_name_00 == an_id).count() == 0:
list_dict.append({'column_name_00':a_id,
'column_name_01':data[2]})
conn = engine.connect()
conn.execute(prices.insert(),list_dict)
conn.close()
session.close()
edit: I moved session = Session() outside the loop. Did not make a difference.
Hi,
I was looking at some of the examples from the Deitel and Deitel's book for Programming in Java, and one of the first examples is a very simple Swing display. Hence this snippet of code :
import javax.swing.*;
public class cdea {
public static void main(String args[]){
JOptionPane.showMessageDialog(null,"\"Welcome to Java Programming!\"");
System.exit(0);
//end method main
}
}
I read some stuff regarding how one can get native UI look and feel by using
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
to the program. However, when I just add this to my main method, it gives me a host of errors. Specifically :
Multiple markers at this line
- Unhandled exception type IllegalAccessException
- Unhandled exception type InstantiationException
- Unhandled exception type ClassNotFoundException
- Unhandled exception type UnsupportedLookAndFeelException
However when I use it as part of a try/catch exception loop (is that what it is called?) as detailed on http://stackoverflow.com/questions/1590863/getting-java-applications-to-look-native-on-windows-how , I get the program running properly.
Could anyone tell me in simple language why this is so? As in, why can't I directly get the System look and feel; why do I have to use it with exception handling? I'm new to Java, and OOP in general, so I'm sorry if I'm being too simplistic.
I'm trying to write my first iPhone app, and I'm using a date picker object for the user to enter their date of birth. Part of my app requires the year in int format. I've added the code as below. What's odd is that 'month' gets the right value. But day and year seem to be stuck at MAX_INT (2147483647). Can anyone tell me what I'm doing wrong?
-(IBAction)dateOfBirthChanged:(id)sender {
NSCalendar* calender = [NSCalendar currentCalendar];
NSDateComponents* dateComponents = [calender components:NSMonthCalendarUnit fromDate:[datepicker date]];
NSInteger day = [dateComponents day];
NSInteger month = [dateComponents month];
NSInteger year = [dateComponents year];
label.text = [NSString stringWithFormat:@"Your year of birth is %d", year];
}
i have a string like following:
Assigned to ram on 2010-04-22 12:30:13.0
i need to extract the third word (ram). I tried the below regex, its not working.
/\s[a-zA-Z]*\s/
any help to fix this would be greatly appreciated.
Hello.
I'm writing some script, that works with web-servers.
So, I have the following code:
client = suds.client.Client(WSDLfile)
client.service.Login('mylogin', 'mypass')
print client.options.transport.cookiejar
#######
sessnum = str(client.options.transport.cookiejar).split(' ')[1]
client = suds.client.Client( WSDLfile, headers= { 'Set-Cookie' : sessnum } )
When running in FreeBSD, it returns
<cookielib.CookieJar[<Cookie sessnum=9WAXQ25D37XY535F6SZ3GXKSCTZG8CVJ for .IP.IP.IP.IP/>]>
but in Windows it returns
<cookielib.CookieJar[]>
How can I fix it?
This is a module named XYZ.
def func(x)
.....
.....
if __name__=="__main__":
print func(sys.argv[1])
Now I have imported this module in another code and want to use the func. How can i use it?
import XYZ
After this, where to give the argument, and syntax on how to call it, please?
In Chapter 3 of Programming Scala, the author gives two examples of for loops / for comprehensions, but switches between using ()'s and {}'s. Why is this the case, as these inherently look like they're doing the same thing? Is there a reason breed <- dogBreeds is on the 2nd line in example #2?
// #1 ()'s
for (breed <- dogBreeds
if breed.contains("Terrier");
if !breed.startsWith("Yorkshire")
) println(breed)
// #2 {}'s
for {
breed <- dogBreeds
upcasedBreed = breed.toUpperCase()
} println(upcasedBreed)
Hi.
I want to retrieve all hashtags from a tweet using a PHP function.
I know someone asked a similar question here, but there is no hint how exactly to implement this in PHP. Since I'm not very familiar with regular expressions, don't know how to write a function that returns an array of all hashtags in a tweet.
So how do I do this, using the following regular expression:
#\S*\w
as we know java is not pure oop because primitive type.
is there any else cause for it
please share..
think static variable and multiple inheritence also have same resp...
Pleas correct me..
I have this code:
a=[['a','b','c'],['a','f','c'],['a','c','d']]
for x in a:
for y in x:
if 'a' in x:
x.replace('a','*')`
but the result is:
a=[['a','b','c'],['a','f','c'],['a','c','d']]
and bot a=[['b','c'],['f','c'],['c','d']]
What should I do so the changes will last?
this and super are keywords isn't it, then how can we use them for passing arguments to constructors the same way as with a method??
In short how is it that these can show such distinct behaviours??
I have the following usecase:
A div with some buttons
When the user
clicks on a button, a popup is shown
and the background div is faded out
to 0.5 opacity
The problem is that when the popup comes in, the user is still able to click on the background buttons. At this point, I can remove the entire DIV temporarily but I don't want to do that. Is there anyway I can disable all the previously attached events and then add event handlers ONLY to the current popup? (I mean something like a close button should still work on a popup) Any suggestions?
HI. I know this is simple question but when I use
FirstPersonTestImage.Save(IIdComboBox.Text + "-" + i + ".jpg");
it works and saves file to folder where is the .exe file . But I want to save it to specific folder like /photo/IO-66/ and tryed to use
String StudentPath = PhotoPath + IGroupNoComboBox.Text + "/" + IIdComboBox.Text + "/" + IIdComboBox.Text + "-" + i + ".jpg";
FirstPersonTestImage.Save(StudentPath);
BUt it gives
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
How can I solve this problem? Is is about folder path ? or using "/" ?
EDIT
Here My code for creating and checking existing or not folder
if (!System.IO.Directory.Exists(PhotoPath + "/" + IGroupNoComboBox.Text.ToString().Trim()))
{
Directory.CreateDirectory(PhotoPath + "/" + IGroupNoComboBox.Text.ToString().Trim());
}
if (!System.IO.Directory.Exists(PhotoPath + "/" + IGroupNoComboBox.Text.ToString().Trim()+ "/" + IIdComboBox.Text.ToString().Trim() + "/"))
{
Directory.CreateDirectory(PhotoPath + "/" + IGroupNoComboBox.Text.ToString().Trim()+"/" + IIdComboBox.Text.ToString().Trim() + "/");
}
Hello, everyone.
I am having some trouble on a project I'm working on.
Here's the header file for the calor class:
#ifndef _CALOR_
#define _CALOR_
#include "gradiente.h"
using namespace std;
class Calor : public Gradiente
{
public:
Calor();
Calor(int a);
~Calor();
int getTemp();
int getMinTemp();
void setTemp(int a);
void setMinTemp(int a);
void mostraSensor();
};
#endif
When I try to compile it:
calor.h|6|error: expected unqualified-id before ‘using’|
Why does this happen? I've been searching online and learned this error occurs mostly due to corrupted included files.
Makes no sense to me, though. This class inherits from gradiente:
#ifndef _GRADIENTE_
#define _GRADIENTE_
#include "sensor.h"
using namespace std;
class Gradiente : public Sensor
{
protected:
int vActual, vMin;
public:
Gradiente();
~Gradiente();
}
#endif
Which in turn inherits from sensor
#ifndef _SENSOR_
#define _SENSOR_
#include <iostream>
#include <fstream>
#include <string>
#include "definicoes.h"
using namespace std;
class Sensor
{
protected:
int tipo;
int IDsensor;
bool estadoAlerta;
bool estadoActivo;
static int numSensores;
public:
Sensor(/*PARAMETROS*/);
Sensor(ifstream &);
~Sensor();
int getIDsensor();
bool getEstadoAlerta();
bool getEstadoActivo();
void setEstadoAlerta(int a);
void setEstadoActivo(int a);
virtual void guardaSensor(ofstream &);
virtual void mostraSensor();
// FUNÇÃO COMUM
/* virtual int funcaoComum() = 0;
virtual int funcaoComum(){return 0;};*/
};
#endif
For completeness' sake, here's definicoes.h
#ifndef _DEFINICOES_
#define _DEFINICOES_
const unsigned int SENSOR_MOVIMENTO = 0;
const unsigned int SENSOR_SOM = 1;
const unsigned int SENSOR_PRESSAO = 2;
const unsigned int SENSOR_CALOR = 3;
const unsigned int SENSOR_CONTACTO = 4;
const unsigned int MIN_MOVIMENTO = 10;
const unsigned int MIN_SOM = 10;
const unsigned int MIN_PRESSAO = 10;
const unsigned int MIN_CALOR = 35;
#endif
Any help'd be much appreciated.
Thank you for your time.
Thanks for your time!
hello,
I would like to start developing for macosx. I need to create a small native application to help me do some stuff. I never developed in Objective-C, have no idea about cocoa, Xcode, NIB and similar stuff.
I don't want to learn by slapping examples together though. This would probably make things done, but I would not learn anything. I'd prefer a guided tutorial (or book) to go from zero to release on the web of the application. Do you have anything to suggest ?
Hello,
When sending data from a form to a second page, the value of the session is always with the name "Array" insteed of the expected number.
The data should get displayed in a table, but insteed of example 1, 2, 3 , 4 i get : Array, Array, Array.
(A 2-Dimensional Table is used)
Is the following code below a proper way to "call" upon the stored values on the 2nd page from the array ?
$test1 = $_SESSION["table"][0];
$test2 = $_SESSION["table"][1];
$test3 = $_SESSION["table"][2];
$test4 = $_SESSION["table"][3];
$test5 = $_SESSION["table"][4];
What exactly is this, and how can i fix this?
Is it some sort of override that needs to happen?
Best Regards.
I am writing this little Lottery application.
Now the plan is, to count how often each number has been drawn during each iteration of the Lottery, and store this somewhere.
My guess is that I would need to use a HashMap, that has 6 keys and increments the value by one everytime the respective keys number is drawn.
But how would I accomplish this?
My code so far:
public void numberCreator()
{
// creating and initializing a Random generator
Random rand = new Random();
// A HashMap to store the numbers picked.
HashMap hashMap = new HashMap();
// A TreeMap to sort the numbers picked.
TreeMap treeMap = new TreeMap();
// creating an ArrayList which will store the pool of availbale Numbers
List<Integer>numPool = new ArrayList<Integer>();
for (int i=1; i<50; i++){
// add the available Numbers to the pool
numPool.add(i);
hashMap.put(nums[i], 0);
}
// array to store the lotto numbers
int [] nums = new int [6];
for (int i =0; i < nums.length; i++){
int numPoolIndex = rand.nextInt(numPool.size());
nums[i] = numPool.get(numPoolIndex);
// check how often a number has been called and store the new amount in the Map
int counter = hashMap.get
numPool.remove(numPoolIndex);
}
System.out.println(Arrays.toString(nums));
}
Maybe someone can tell me if I have the right idea, or even how I would implement the map properly?
Hi, I basically started today with WPF, and I'm astounded by how difficult it is to do binding. I have an array of Textboxes, in an ObservableCollection, and just want to bind that in my Listbox, so that they arrange themselves vertically.
I have fiddled around with this for 3 already, can you help?
I'm working in a Wpf "UserControl", not a window as so many tutorials seem to rely on.
I want to apply a function f to a list of values, however function f might randomly fail (it is in effect making a call out to a service in the cloud).
I thought I'd want to use something like map, but I want to apply the function to all elements in the list and afterwards, I want to know which ones failed and which were successful.
Currently I am wrapping the response objects of the function f with an error pair which I could then effectively unzip afterwards
i.e. something like
g : (a->b) -> a -> [ b, errorBoolean]
f : a-> b
and then to run the code ... map g (xs)
Is there a better way to do this? The other alternative approach was to iterate over the values in the array and then return a pair of arrays, one which listed the successful values and one which listed the failures. To me, this seems to be something that ought to be fairly common. Alternatively I could return some special value. What's the best practice in dealing with this??
hi,
I have stored instances of class A in a std:vector, vec_A as vec_A.push_back(A(i)). The code is shown below.
Now, I want to store references some of the instances of class A (in vec_A) in another vector or another array. For example, if the A.getNumber() returns 4, 7, 2 , I want to put a reference to that instance of A in another vector, say std:vector<A*> filtered_A or an array.
Can someone sow me how to do this?? Thanks!
class A {
public:
int getNumber();
A(int val);
~A(){};
private:
int num;
};
A::A(int val){
num = val;
};
int A::getNumber(){
return num;
};
int main(){
int i =0;
int num;
std::vector<A> vec_A;
for ( i = 0; i < 10; i++){
vec_A.push_back(A(i));
}
std::cout << "\nPress RETURN to continue...";
std::cin.get();
return 0;
}