python

calculate user inputed time with Python

I need to calculate (using python) how much time a user has inputed, whether they input something like 3:30 or 3.5. I'm not really sure what the best way to go about this is and I thought I'd ask for advice from the experts. === Edit ================== To specify more clearly, I want the user to input hours and minutes or just minut...

Porting from Python to C#

I´m trying to learn C#, coming from a Python/PHP background, and I´m trying to port a script from Python to getting started. The script reads a text file line by line (about 150K lines), apply a list of regex until one is matched, get the named groups results and add the values as properties of a class. Here´s how the data looks like (...

How do you deal with missing data using numpy/scipy?

One of the things I deal with most in data cleaning is missing values. R deals with this well using its "NA" missing data label. In python, it appears that I'll have to deal with masked arrays which seem to be a major pain to set up and don't seem to be well documented. Any suggestions on making this process easier in Python? This is bec...

How to make this code handle big inputs more efficiently?

Hey. I know this is not a 'refactor my code' site but I made this little piece of code which works perfectly fine with moderately sized input but it's problematic with string of size, say, over 2000. What it does - it takes a string of numbers as a parameter, and it returns the number of ways it can be interpreted as a string of letters...

What is faster in Python, "while" or "for xrange"

We can do numeric iteration like: for i in xrange(10): print i, and in C-style: i = 0 while i < 10: print i, i = i + 1 Yes, I know, the first one is less error-prone, more pythonic but is it fast enough as C-style version? PS. I'm from C++ planet and pretty new on Python one. ...

html to pdf for a Django site

For my django powered site, I am looking for an easy solution to convert dynamic html pages (generated using django views and templates datas generated using GET forms) which also contains some graph charts from google visualisation api(it is javascript, yet including these graphs is a must for me) to pdf. Cheers ...

Python multiprocessing with twisted's reactor

Dear everyone I am working on a xmlrpc server which has to perform certain tasks cyclically. I am using twisted as the core of the xmlrpc service but I am running into a little problem: class cemeteryRPC(xmlrpc.XMLRPC): def __init__(self, dic): xmlrpc.XMLRPC.__init__(self) def xmlrpc_foo(self): return 1 ...

What kind of setup (IDE et al) do I need to run IronPython unit tests of C#.NET developed assemblies?

I'm attempting to learn IronPython, to broaden my .NET horizons. I want to be able to use Python to write the unit-tests for my next personal project. So being able to access C#.NET assemblies from my Python code is necessary. I also wanted an IDE with auto-complete and smart indenting. PyScripter seemed like a good option, but can I ru...

Python dictionary to store socket objects

Can we store socket objects in a Python dictionary. I want to create a socket, store socket object, do some stuff and then read from the socket(search from dictionary to get socketobject). ...

Python dicts in sqlalchemy

I would like to load/save a dict to/from my sqlite DB, but am having some problems figuring out a simple way to do it. I don't really need to be able to filter, etc., based on the contents so a simple conversion to/from string is fine. The next-best thing would be foreign keys. Please don't post links to huge examples, my head would exp...

How to get/set data of(into) visual components (of winodws programs) programmatically?

Let me clarify the question a bit. I am talking about windows GUI programs. Say a program-window has a dialog box (or a confirm button) asking user input. How can I provide input to that program using my program (written in say C#, Java or Python). Or say, a program window is showing some image in one of its panels. How can I grab that f...

Python: how to format traceback objects

I have a traceback object that I want to show in the nice format I get when calling traceback.format_exc() Is there a builtin function for that, or a few lines of code? ...

list of methods for python shell?

You'd have already found out by my usage of terminology that I'm a python n00b. straight forward question: How can i see a list of methods for a particular object in an interactive python shell like i can in ruby (you can do that in ruby irb with a '.methods' after the object)? ...

is there a way to start/stop linux processes with python?

I want to be able to start a process and then be able to kill it afterwards ...

Are there any cpython libraries that work with jsr168 and/or jsr286?

On a Java portal you can have portlets that include data provided by other applications. We want to replace our existing Java portal with a Django application, which means duplicating the Java portal's ability to display portlets. The two Sun specifications in question that we want to duplicate are JSR168 and JSR286. I need a cPython so...

pytz localize vs datetime replace

I'm having some weird issues with pytz's .localize() function. Sometimes it wouldn't make adjustments to the localized datetime: .localize behaviour: >>> tz <DstTzInfo 'Africa/Abidjan' LMT-1 day, 23:44:00 STD> >>> d datetime.datetime(2009, 9, 2, 14, 45, 42, 91421) >>> tz.localize(d) datetime.datetime(2009, 9, 2, 14, 45, 42, 91421, ...

Django and weird legacy database tables

Hi, I'm trying to integrate a legacy database in Django. I'm running into problems with some weird tables that result from horribly bad database design, but I'm not free to change it. The problem is that there are tables that dont have a primarykey ID, but a product ID and, here comes the problem, a lot of them are multiple in case of...

web2py in the future?

Given the size of web2py and the lack of resources and corporate support, do you think it would be advisable to learn web2py as the only web development frame work I know. I'm considersing learning ror or web2py for a website i need to create for as a school project. this is not the 'ruby vs python' question. I just want to know what dis...

Splitting up a list into parts of balanced lengths

Hi I need an algorithm which given a list L and a number N, returns a list of N smaller lists where the sublists are "balanced". Examples: algo(range(1, 8), 3) -> [[1,2,3], [4,5], [6,7]] algo(range(1, 6), 4) -> [[1,2], [3], [4], [5]] algo(range(1, 12), 5) -> [[1,2,3], [4,5], [6,7], [8,9], [10, 11]] As you can see, the algorithm sh...

Set Snow Leopard to use python 2.5 rather than 2.6

I just upgraded to Snow Leopard and I'm trying to get it to use the old python 2.5 install. I had with all my modules in it. Does anyone know how to set the default python install to 2.5? ...