python

can Bisect be applied using Dict instead of lists?

i have a file with information in the pattern of: .343423 1 .434322 1 .453434 1 .534342 1 Equal size each line and row in sorted order..I have a variable "a" with a value and need to get the row number which it closest to "a" comparing with the values in the 1st column.. Till now i was coping the 1st column element into list and then...

Any smarter/faster/ligher replacement for this line of code?

file = [float(line.partition(' ')[0]) for line in file] the file is object of open file... thnq ...

set user session in django

<?php session_start(); $_SESSION['username'] = "johndoe" // Must be already set ?> How to write equivalent code for the above in django ...

generating permutations with repetitions in python

I know about itertools, but it seems it can only generate permutations without repetitions. for example, I'd like to generate all possible dice rolls for 2 dice. So I need all permutations of size 2 of [1, 2, 3, 4, 5, 6] including repetitions: (1, 1), (1, 2), (2, 1)... etc If possible I don't want to implement this from scratch ...

Command is getting hanged on execution via fabric

When i am running the below command on one of the remote machine via fabric it is getting hanged. def execute_lmo_scripts(): print "preparing to execute lmo scripts................" output = run("sudo suwww ; ") # or this command sudo("suwww",shell=False) If i manually run the command on the remote server it is being exe...

using link grammar parser

Hey guys, Is it adequate to use the link grammar parser to do POS tagging? How is the performance when it comes to informal english with a little of my country's lingo? Does the link grammar parser also performs a subject-object relationship identification? Doing POS tagging is the first step towards NER right? ...

How to reset a Datastore model's property-type, with remote API

I have a Model in an existing Datastore. Which looks like this: class SomeKind(db.Model): name = db.StringProperty(required=True) someField = db.BlobProperty(required=True) There are about 20000+ entities, of this kind, in the datastore Now I want to restructure the kind and make it this way: class SomeKind(db.Model): name = db...

Boost-Python raw pointers constructors

I am trying to expose a C++ library to python using boost-python. The library actually wraps an underlying C api, so uses raw pointers a lot. // implementation of function that creates a Request object inline Request Service::createRequest(const char* operation) const { blpapi_Request_t *request; ExceptionUtil::throwOnError( ...

Wrapping C++ dynamic array with Python+ctypes, segfault

Hi! I wanted to wrap a small C++ code allocating an array with ctypes and there is something wrong with storing the address in a c_void_p object. (Note: the pointers are intentionally cast to void*, 'cause later I want to do the allocation the same way for arrays of C++ objects, too.) The C(++) functions to be wrapped: void* test_all...

issue while matching special char '\' in regular expression using '\\'

I have very simple python script to match some special characters like -,+,-,. But Im not getting expected result while using regex \ to match a single '\' char. import re pat = r'[-+*\\]' text = 'fdkjdfk\sdsdd' if re.search(pat,text): print re.search(pat,text).group() else: print "not found" On running above code , it prints 'n...

Datetime.now() abnormality - Python

Hi folks, I'm serving a Python app through Django. Within the app I'm storing the classic "created" field within a few tables. This is how the field looks like within the Django form: created = models.DateTimeField(blank=True, default=datetime.now()) Unfortunately, datetime.now() is not accurate. In fact in the database I have set...

Does ctypes provide anything for enums and flags?

I have an API I'd like to use from python. That API contains flags and enums implemented with #define. // it's just almost C so don't bother adding the typedef and parenthesis diarrhea here. routine(API_SOMETHING | API_OTHERTHING) stuff = getflags() ? stuff & API_SOMETHING action(API_INTERESTING) mode = getaction() ? mode == INTERESTIN...

Java equivalent of python's String partition

Java's string split(regex) function splits at all instances of the regex. Python's partition function only splits at the first instance of the given separator, and returns a tuple of {left,separator,right}. How do I achieve what partition does in Java? e.g. "foo bar hello world".partition(" ") should become "foo", " ", "bar hello ...

running command in background

hi, I am using python subprocess module to run some command and store its output in background. The command is deployed on my machine. Now whenever i run the command from shell prompt it works fine. But when I try to run the same command using subprocess module it gives following error The command to be executed is vxswadm listswitch a...

How to add abilities to strings in Python

This is more of a curiosity question than anything else. I'm new with Python and playing around with it. I've just looked at the base64 module. What if instead of doing: import base64 string = 'Foo Bar' encoded = base664.b64encode I wanted to do something like: >>> class b64string(): >>> <something> >>> >>> string = b64string('Foo ...

RegExp - extract value a tag for [python]

How to get value a tag <a> and <b>? Use regular expressions. <a href="/model.xml?hid=90971&amp;modelid=4636873&amp;show-uid=678650012772883921" class="b-offers__name"><b>LG</b> X110</a> Ie I want get LG X110 ...

Controlling Music and Video in Python

I'm trying to write a karaoke program in python. Every karaoke software has basic functionality like seeking in the video as well as modulating the pitch of music by half steps. What are some modules that I can use to permit this functionality? I'm going to use wxPython to write the gui portion if that makes a difference! ...

plot with custom text for x axis points

Hi All I am drawing a plot using matplotlib and pyhon like the sample code below. x = array([0,1,2,3]) y = array([20,21,22,23]) plot(x,y) show() As it is the code above on the x axis I will see drawn values 0.0, 0.5, 1.0, 1.5 i.e. the same values of my reference x values. Is there anyway to map each point of x to a different string...

python: trouble printing short utf-encoded strings

(The following is using Python 2.6.1) I have 2 strings: >>> a = u'\u05e8\u05db\u05e1' >>> b = u'\u05e8\u05db\u05e1 \u05d4\u05d9\u05d0 \u05de\u05d0\u05d9\u05e8\u05d4 \u05d1\u05e4\u05e0\u05e1' I encode them: >>> ua = a.encode('utf-8') >>> ub = b.encode('utf-8') >>> ua '\xd7\xa8\xd7\x9b\xd7\xa1' >>> ub '\xd7\xa8\xd7\x9b\xd7\xa1 \xd7\x9...

ide code information

I've been annoyed lately by the fact that PyDev doesn't information about classes and function when it code completes wxPython code. Can anybody tell me FOSS IDE's or extensions that offer code information (function params, returns etc.) when it code completes for C/C++ and Python. I am a fan of CodeLite, Eclipse CDT and CodeBlocks in ...