python

Python not recognising directories os.path.isdir()

I have the following Python code to remove files in a directory. For some reason my .svn directories are not being recognised as directories. And I get the following output: .svn not a dir Any ideas would be appreciated. def rmfiles(path, pattern): pattern = re.compile(pattern) for each in os.listdir(path): if os....

How do you get the process id of a program in python?

I'm writing some monitoring scripts in Python and I'm trying to find the cleanest way to get the process ID of any random running program given the name of that program something like ps -ef | grep MyProgram I could parse the output of that however I thought there might be a better way in python ...

How do you handle timezones for data processing?

curious how people have solved this problem... I have a series of jobs that run overnight that roll up reports based on that day's data for customers. They're now asking for timezone support. One of the reports is.. you had x number of orders last night, however last night could be different depending on timezone. What is the best way ...

Python cProfile: how to filter out specific calls from the profiling data?

I've started profiling a script which has many sleep(n) statements. All in all, I get over 99% of the run time spent sleeping. Nevertheless, it occasionally runs into performance problems during the time that it does real work but the relevant, interesting profiling data becomes very difficult to identify when e.g. using kcachegrind. Is...

How do I find out the Python, Django versions and path that a Django site is running?

I currently have multiple Django sites running from one Apache server through WSGI and each site has their own virtualenv with possibly slight Python and Django version difference. For each site, I want to display the Python and Django version it is using as well as from which path it's pulling the Python binaries from. For each Django...

Wrap std::vector of std::vectors, C++ SWIG Python

I want to wrap a C++ vector of vectors to Python code by using SWIG. Is it possible to wrap this type of vector of vectors? std::vector<std::vector<MyClass*>>; In the interface file MyApplication.i I added these lines: %include "std_vector.i" %{ #include <vector> %} namespace std { %template(VectorOfStructVector) vector<vecto...

Passing data from a virtual printer to python

Hey all, I am trying to make a thing where in other applications you can print to a certain printer and python will get the data. How would I go about making this? It would have to work in all applications, so it would appear as a normal printer, and work on Linux and Windows, even if I have to rewrite it for both. So to recap: One op...

How to add the binary of a int with the binary of a string

Basically i want to be able to get a 32bit int and attach its binary to the binary of a string. E.g. (IM going to use 8bit instead of 32bit) i want 255 + hi 11111111 + 0110100001101001 = 111111110110100001101001 So the int holds its binary value,i dont care how it comes out i just want it to be able to send the data over a socket. (This...

Python vs. C++ for an application that does sparse linear algebra

I'm writing an application where quite a bit of the computational time will be devoted to performing basic linear algebra operations (add, multiply, multiply by vector, multiply by scalar, etc.) on sparse matrices and vectors. Up to this point, we've built a prototype using C++ and the Boost matrix library. I'm considering switching to...

Rhythmbox plugin to access podcast files doesn't see them

I am writing a Rhythmbox plugin to iterate over all podcast files currently known to Rhythmbox (whether downloaded or not) and to do something with them. After some research and testing in the Rhythmbox's Python Shell, I succeeded to get a list of all objects. However, when I coded it into a plugin, I get an error: (rhythmbox:7500): GL...

Understanding python variable scope within class

I am trying to define a variable in a class that then can be accessed/changed from functions within that class. For example: class MyFunctions(): def __init__( self): self.listOfItems = [] def displayList( self): """Prints all items in listOfItems)""" for item in self.listOfItems: print item...

ETL using Python

I am working on a data warehouse and looking for an ETL solution that uses Python. I have played with SnapLogic as an ETL, but I was wondering if there were any other solutions out there. This data warehouse is just getting started. Ihave not brought any data over yet. It will easily be over 100 gigs with the initial subset of data I wa...

Returning all characters before the first underscore

Hello, Using re in Python, I would like to return all of the characters in a string that precede the first appearance of an underscore. In addition, I would like the string that is being returned to be in all uppercase and without any non-alpanumeric characters. For example: AG.av08_binloop_v6 = AGAV08 TL.av1_binloopv2 = TLAV1 I a...

subprocesses with different working directories problem with python.

I am working under the following project directory. work/project/test/a.py then, inside a.py, I have to use the subprocess.POPEN to launch the process from another directory, work/to_launch/file1.pl, file2.py, file3,..., (note: the file1.pl will call file2.py, file3. etc) e.g. inside a.py, I use subprocess.POPEN("usr/bin/perl ....

Occasional ctypes error importing numpy from mod_wsgi django app

Here's the setup: Django (1.2) app on mod_wsgi that imports ctypes Python 2.6.5 Apache 2.2.3 SELinux disabled RedHat EL 5 64bit some of the file system is mounted over nfs Occasionally, when I restart apache I get an import error when it's trying to import ctypes. Every incoming request fails with a 500 error. If I restart apache usu...

Most efficient way to extract PyTables table with stored colnames as variable names

The following code provides my needed functionality; but, takes a bit more than 10 seconds for a table that includes 200 variables with 64000 rows. Is there a more efficient way to create a variable namespace that matches the column names? strExec = "a = table[:]" for colobj in table.description._f_walk(type="Col"): colName = co...

how do i check stdin has some data?

in python,how to check sys.stdin has data or not, i found os.isatty(0) only can check is connect to a tty device,but if some one use code like sys.stdin=cStringIO.StringIO("ddd") after that use os.isatty(0) it's still return True, what i need is check from stdin is have data,any advice is welcome ...

What is the faster ( and slower ) language to do this ?

Possible Duplicate: What is the faster ( and slower ) language to do this ? I want to know what is the faster ( execution time ) language for this simple script ( executed through ajax ): Pseudocode: // start code var str = GET['string'] INSERT SQL SELECT SQL // end code This is a very simple script with 2 simple query. ...

ElementTree element index look up

Just a beginner question. I'm using "xml.etree.ElementTree" module to create an XML document with Python 3.1 from another structured document. However, I cannot seem to locate an ElementTree function that returns the index of an existing subelement. I'm sure it's in there somewhere. Any help would be much appreciated. Thanks, ...

Pexpect - silence ssh connection output

Hi. I'm using a simple pexpect script to ssh to a remote machine and grab a value returned by a command. Is there any way, pexpect or sshwise I can use to ignore the unix greeting? That is, from child = pexpect.spawn('/usr/bin/ssh %s@%s' % (rem_user, host)) child.expect('[pP]assword: ', timeout=5) child.sendline(spass) ...