python

how to generate a many-to-many-relationship FORM in web2py?

Do I need a custom validator? Do I need a custom widget? If this helps to clear the problem, the relationship is between member and language where a member can have multiple languages and a language is spoken by multiple members. I would like to add a multi-select box in the "add member" form (that I generate using SQLFORM). Thanks :)...

In Python, how do I index a list with another list?

I would like to index a list with another list like this L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] Idx = [0, 3, 7] T = L[ Idx ] and T should end up being a list containing ['a', 'd', 'h']. Is there a better way than T = [] for i in Idx: T.append(L[i]) print T # Gives result ['a', 'd', 'h'] ...

Will Dict Return Keys and Values in Same Order?

Hi, If i have a dictonary in python, will .keys and .values return the corresponding elements in the same order? E.g. foo = {'foobar' : 1, 'foobar2' : 4, 'kittty' : 34743} For the keys it returns: >>> foo.keys() ['foobar2', 'foobar', 'kittty'] Now will foo.values() return the elements always in the same order as their correspondi...

How to concatenate strings with binary values in python?

What's the easiest way in python to concatenate string with binary values ? sep = 0x1 data = ["abc","def","ghi","jkl"] Looking for result data "abc0x1def0x1ghi0x1jkl" with the 0x1 being binary value not string "0x1". ...

Bash or Python to go backwards?

Hi, I have a text file which a lot of random occurrences of the string @STRING_A, and I would be interested in writing a short script which removes only some of them. Particularly one that scans the file and once it finds a line which starts with this string like @STRING_A then checks if 3 lines backwards there is another occurrence ...

Why does this python code hang on import/compile but work in the shell?

I'm trying to use python to sftp a file, and the code works great in the interactive shell -- even pasting it in all at once. When I try to import the file (just to compile it), the code hangs with no exceptions or obvious errors. How do I get the code to compile, or does someone have working code that accomplishes sftp by some othe...

Call Python From Bat File And Get Return Code

I'm looking for a way to call a python script from a batch file and getting a return code from the python script. Confusing I know, but it's based on a system that's currently in use. I'd re-write it, but this way would be much, much quicker. So: Bat ---------------------> Python * call python file * Bat <----------------------...

What is the purpose of the two colons in this Python string-slicing statement?

For example, str = "hello" str[1::3] And where can I find this in Python documentation? ...

python ORM allowing for table creation and bulk inserting?

I'm looking for an ORM that allows me to do bulk inserts, as well as create code based on python classes. I tried sqlobject, it worked fine for creating the tables but inserting was unacceptibly slow for the amount of data I wanted to insert. If such an ORM doesn't exist any pointers on classes that can help with things like sanitizing i...

Windows error and python

I'm working on a bit of code that is supposed to run an exe file inside a folder on my system and getting an error saying... WindowsError: [Error 3] The system cannot find the path specified. Here's a bit of the code: exepath = os.path.join(EXE file localtion) exepath = '"' + os.path.normpath(exepath) + '"' cmd = [exepath, '-el', str(...

How to link C lib against python for embedding under Windows?

Hi, I am working on an application written in C. One part of the application should embed python and there is my current problem. I try to link my source to the Python library but it does not work. As I use MinGW I have created the python26.a file from python26.lib with dlltool and put the *.a file in C:/Program Files (x86)/python/2.6/...

Combining C and Python functions in a module

I have a C extension module, to which I would like to add some Python utility functions. Is there a recommended way of doing this? For example: import my_module my_module.super_fast_written_in_C() my_module.written_in_Python__easy_to_maintain() I'm primarily interested in Python 2.x. ...

Stealing wheelEvents from a QScrollArea

I wanna put my custom widget in a QScrollArea, but in my custom widget, i reimplemented wheelEvent(e) and it never gets called. Im fine with the scroll area not having its mouse wheel scrolling functionality, I just need those wheelEvents to call my handler. I tried handling the events out at the level of the main window but I only got t...

python file size

I am trying to split up a large xml file into smaller chunks. I write to the output file and then check its size to see if its passed a threshold, but I dont think the getsize() method is working as expected. What would be a good way to get the filesize of a file that is changing in size. Ive done something like this... import string ...

How to write a Perl, Python, or Ruby program to change the memory of another process on Windows?

I wonder if Perl, Python, or Ruby can be used to write a program so that it will look for 0x12345678 in the memory of another process (probably the heap, for both data and code data) and then if it is found, change it to 0x00000000? It is something similar to Cheat Engine, which can do something like that on Windows. ...

What Can A 'TreeDict' (Or Treemap) Be Used For In Practice?

I'm developing a 'TreeDict' class in Python. This is a basically a dict that allows you to retrieve its key-value pairs in sorted order, just like the Treemap collection class in Java. I've implemented some functionality based on the way unique indexes in relational databases can be used, e.g. functions to let you retrieve values corre...

How do I convert a nested tuple of tuples and lists to lists of lists in Python?

I have a tuple containing lists and more tuples. I need to convert it to nested lists with the same structure. For example, I want to convert (1,2,[3,(4,5)]) to [1,2,[3,[4,5]]]. How do I do this (in Python)? ...

What does : TypeError: cannot concatenate 'str' and 'list' objects mean?

What does : TypeError: cannot concatenate 'str' and 'list' objects mean?? I'm getting this error.. and I know it's saying I'm trying to add a string and a number maybe? but I'm not sure how to fix it Here's part of the code: for j in ('90.','52.62263.','26.5651.','10.8123.'): if j == '90.': z = ('0.') elif j == '52.62...

Simple syntax for bringing a list element to the front in python?

Hi folks, I have an array with a set of elements. I'd like to bring a given element to the front but otherwise leave the order unchanged. Do folks have suggestions as to the cleanest syntax for this? This is the best I've been able to come up with, but it seems like bad form to have an N log N operation when an N operation could do. ...

Python Authentication with urllib2

So I'm trying to download a file from a site called vsearch.cisco.com with python [python] #Connects to the Cisco Server and Downloads files at the URL specified import urllib2 #Define Useful Variables url = 'http://vsearch.cisco.com' username = 'xxxxxxxx' password = 'xxxxxxxx' realm = 'CEC' # Begin Making connection # Create a Ha...