python

Convert a R code into Python script

Hi, I got the following R code and I need to convert it to python and run it in python environment, basically I have done this with rpy2 module, but it looks kind of dull with python doing the same things, so could someone find a better way to rewrite the following R code to an equivalent python script with the rpy2 module? mymad <- fun...

How to include python compiler dependencies in maven web project?

I have a simple website that has some related python scripts that I use for maintenance of that website (note, the python code are util scripts that we execute manually for various tasks). I need to be able to share it with other developers who may want to edit it. What Maven dependencies do I need to include so that the python compile...

Issues with time.sleep and Multithreading in Python

I am having an issue with the time.sleep() function in python. I am running a script that needs to wait for another program to generate txt files. Although, this is a terribly old machine, so when I sleep the python script, I run into issues with the other program not generating files. Is there any alternatives to using time.sleep()? I t...

Anyone know a better way do write this login function in django

Hay I was wondering if anyone knew a better way to do this. def login_user(request): username = request.POST.get('username') password = request.POST.get('password') user = User.objects.filter(username=username) if user: user = user[0] if user.password == generate_password(password): return H...

C++ and python simultaneously. Is it doable

Hi, I am totally new to programming as though I have my PhD as a molecular biologist for the last 10 years. Can someone please tell me: Would it be too hard to handle if I enrolled simultaneously in C++ and python? I am a full time employee too. Both courses start and finish on the same dates and is for 3 months. For a variety of compl...

Removing elements from a list containing specific characters

I want to remove all elements in a list which contains (or does not contain) a set of specific characters, however I'm running in to problems iterating over the list and removing elements as I go along. Two pretty much equal examples of this is given below. As you can see, if two elements which should be removed are directly following ea...

How can I create controller routes in Pylons for multi-part IDs?

By default the RESTful controller in Pylons supports single-part IDs for objects. This works for some kinds of objects, but my domain model has a set of objects that have composite identifiers, and I'd like to be able to build good URLs for those as well. This is what is currently supported: GET /advanis/saas/projects/id: Show a specif...

Set connection settings with Pyodbc + UnixODBC + FreeTDS

I have a setup using Pyodbc, UnixODBC and FreeTDS, but somewhere in there some options are being set and I don't know where. According to SQL Server Management Studio, my program is sending some settings when it opens the connection: set quoted_identifier off set ansi_padding off set ansi_nulls off ... But I need a different set of se...

python: function that will call itself

i was wondering if i can get your help with the stucture.logic of a function that will need to call itself def populate_frequency5(d,data,total_compare): freq=[] prev = None for row in d: if prev is None or prev==row[11]: freq.append(row[16]) doctor=row[10] drug=row[11][:row[11].find(' ')].capitalize() el...

Python - threaded pyinotify output. Better to write to file or to a string

Hi all, I have a pyinotify watcher running threaded, called as a separate class, at the moment it just prints its discoveries in a terminal window, if I wanted my script to make an action based on those changes am I better to: A) modify an array with each notification B) write to a file in /tmp and fetch it from my main script? c) gi...

How to step through Python threads independently? (WinPDB)

Hello, I am trying to debug Python using WinPDB and I have multiple threads using threading.Thread. I can never seem to control the threads individually. If I break execution, the entire script breaks. If I step through the source code of one thread, all of the others continue to be interleaved and continue some of their execution. ...

Easy way to delete a shelve .dat file left behind by my Python program?

Hello.... So I have a python program that ends up leaving a .dat file from the shelve function behind after execution. I would like my program to delete or clear that file once it is done. My textbook only mentions how to create a .dat file but not how to clear it. Any good commands out there to take care of this? I don't need the .dat f...

python: can i set a variable to equal a function of itself?

can i do this? var1 = some_function(var1) when i tried to do this i got errors, but perhaps i was doing something wrong thank you ...

python module cx_Oracle in eclipse: undefined variable from import (ubuntu 10.4)

Hi guys, so here it is: I'm trying to use the cx_Oracle to access Oracle10g XE database. everything goes ok if i'm invoking python via the shell terminal then use the cx_Oracle module in a command line manner (import, db access and querying). However,I face some problems with Eclipse. There in no comment in the import line where I im...

python: a shorter way to append values

results_histogram_total=list(numpy.histogram(freq,bins=numpy.arange(0,6.1,.1))[0]) sum_total=sum(results_histogram_total) big_set=[] for i in results_histogram_total: big_set.append(100*(i/sum_total) is there a shorter way i can write the for loop to append the values? ...

How to find all files in current directory with filenames that match a certain pattern in python?

Hi, I am trying to find all the files in the same directory as my script that has a filename matching a certain pattern. Ideally, I would like to store it in an array once I get them. The pattern I need to match is something like: testing.JUNK.08-05.txt. All the filenames have the testing in the front and end with the date (08-05.txt). T...

python: open unfocused tab with webbrowser

I would like to open a new tab in my web browser using python's webbrowser. However, now my browser is brought to the top and I am directly moved to the opened tab. I haven't found any information about this in documentation, but maybe there is some hidden api. Can I open this tab in the possible most unobtrusive way, which means: not ...

How to sort a Python dict by value

I have a dict that looks like this { "keyword1":3 , "keyword2":1 , "keyword3":5 , "keyword4":2 } And I would like to convert it DESC and create a list of just the keywords. Eg, this would return ["keyword3" , "keyword1" , "keyword4" , "keyword2"] All examples I found use lambda and I'm not very strong with that. Is there a way I coul...

Writing only part of a line to a file.

I want to clean up my output and only write part of the line that I need to a new file and not the whole entire line. This is the relevent coding section: counter = 1 for line in completedataset: print counter counter +=1 for t in matchedLines: if t in line[:line.find(',')]: smallerdataset.write(line) ...

How to write a simple server-push implementation in Python using django?

Hello, I would like to write a simple server-push implementation either using long pooling or comet that integrates into the server. I don't want to use a networking framework like twisted because I want to learn how everything is done internally. What exactly should I learn? What specifications should I look at? I prefer something that ...