python

How to update mongodb collections.

My collection structure is: col1 = {'class':'12', 'roll':[1, 2, 3, 4]} Now I want to update the collection col1 to col1 = {'class':'12', 'roll':[1, 2, 3, 4, 5]} I added another roll number here. How to update this in pymongo. ...

Embedding Python in C for configuration files

I'm trying to embed python into c to use it for configuration: If I do it like this: /****************************************************************************** * * Embeding Python Example * * To run: * gcc -c test.c -o test.o -I"C:/Python25/include" * gcc -o test.exe test.o -L"C:/Python25/libs" -lpython25 * test.exe * ****...

SQLite equivalent of Python's "'%s %s' % (first_string, second_string)"

As the title says, what is the equivalent of Python's '%s %s' % (first_string, second_string) in SQLite? I know I can do concatenation like first_string || " " || second_string, but it looks very ugly. ...

Convert JSON to CSV

Hi, In python I have a complex object hierarchy made of lists and dictionaries. I want to spit it all out to CSV or some other kind of database format. Any answers in Python or Javascript very much appreciated. I understand that one CSV file (or table) can only represent one 'level' of object in my hierarchy, so the solution would need...

How to handle multiple forms in google app engine?

Say if I have multiple forms with multiple submit button in a single page, can I somehow make all of these buttons work using webapp as backend handler? If not, what are the alternatives? ...

How many times different letters appear in different words?

Hi everyone. How to know how many times strings s , t and n appear in each of the following words to have an output like this: descriptions: s 2 , t 1 , n 1 statements s 2 , t 3 , n 1 The words are not known in advance.The first thing came to my mind was to make a dictionary, but for dictionaries we can only have two unknowns, so an...

data access object in python

hello , 6 months ago , i was asked to make a database access for our project that has around 30 tables ,( using the Data transfer object pattern ) . we were using Microsoft's sql server back then. so i had to write a script that automatically generates the DAO's and DTO's.( automatically build classes, name them appropriately according...

Python: Executing an application to install a program

I am using a python script to execute an application to install a program. Using os.system('dir\\application.exe') works. However the installer has 2 installation parts and after completing the first one, it will hang there. The second one will only execute when I exit the python script. How can I get the whole installation process to c...

py2exe, sqlalchemy and cx_oracle: ImportError: No module named oracle

Hi, I'm trying to create a binary with py2exe, here are last lines of py2exe output: *** copy dlls *** copying C:\Apps\Python27\python27.dll -> C:\Documents and Settings\nikolay.derka ch\Desktop\UMTScellsChecking\UMTScellsChecking\dist setting sys.winver for 'C:\Documents and Settings\nikolay.derkach\Desktop\UMTSce llsChecking\UMTScell...

Parser generation

hi.. i am doing a project on SOFWARE PLAGIARISM DETECTION..i am intended to do it with language C..for that i am supposed to create a token generator, and a parser..but i dont know where to start..any one can help me out with this.. i created a database of tokens and i separated the tokens from my program.Next thing i wanna do is to...

CSVWriter not saving data to file - WHY?

Python newbie getting a bit frustrated with the csv module. At this rate, it would have been easier if I wrote the file parser myself, but I want to do things the Pythonic way .... I have written a little python script that should save my data into a CSV file. Here is a snippet of my code: import csv wrtr = csv.writer(open('myfile.cs...

App Engine Version, Memcache

I am developing an App Engine App that uses memcache. Since there is only a single memcache shared among all versions of your app I am potentially sending bad data from a new version to the production version memcache. To prevent this, I think I may append the app version to the memcache key string to allow various versions of the app ...

Efficiently computing size of filtered list

I would like to efficiently compute the size of a filtered list, i.e., I don't want to keep the whole filtered list in memory, I just want to get its size. Is there a more "pythonic" way than computing the size using a for-loop? For example: my_list = [1,2,3,4] # this loads the entire **filtered** list in memory size_of_filtered_list ...

Python imports-Need someone to check this please

Ok yes it is a very silly question, but just that I am getting a little confused. I have a file structure which looks like this:- -Mainapplication -models.py -Helpingmodules -Folder1 -module1.py Now I have to import models into module1. So in module1.py I just did:- from Mainapplication import models Now this does work ...

help in vizard (buttons)

Hi, I am developing a GUI in Vizard in witch i am using radio buttons to select correct options, but i have a problem that i cannot solve. In every group of radio buttons the 1st button is appears always select, but actually is not selected, the only way of selecting it is by choosing other button and then choose again the 1st button. ...

Eliminating duplicates - shall I use a set?

I need to read through a log file, extracting all paths, and return a sorted list of the paths containing no duplicates. What's the best way to do it? Using a set? I thought about something like this: def geturls(filename) f = open(filename) s = set() # creates an empty set? for line in f: # see if the line matches some rege...

NameError: global name is not defined

I'm using Python 2.6.1 on OS X. I have two simple python files (below) but when I run: python update_url.py I get on the terminal: Traceback (most recent call last): File "update_urls.py", line 7, in <module> main() File "update_urls.py", line 4, in main db = SqliteDBzz() NameError: global name 'SqliteDBzz' is not define...

Time actions in Python

Hi! I want to run a part of my loop for a certain time: 60 seconds. Afterwards I set a boolean flag and continue at another point. Does Python have something like a stopwatch? Maybe this is OS specific: it's targeted against a Linux env. Sleeping a couple of seconds is easy... no question. ;) I want the opposite. ...

Encryption: simulate SSL in javascript and python

Because of china Great Firewall has blocked google appengine's https port. So I want to simulate a Secure Socket Layer by javascript and python to protect my users information will not be capture by those ISP and GFW. My plan: Shake hands: Browser request server, server generate a encrypt key k1, and decrypt key k2, send k1 to brow...

Sorting a dictionary (with date keys) in Python

I have a dictionary. The keys are dates (datetime). I need to sort the dictionary so that the values in the dictionary are sorted by date - so that by iterating through the dictionary, I am processing items in the desired chronological (i.e. date/time) order. How may I sort such a dictionary by date? Example: mydict = { '2000-01-01': ...