python

Python's version of PHP's time() function

I've looked at the Python Time module and can't find anything that gives the integer of how many seconds since 1970 as PHP does with time(). Am I simply missing something here or is there a common way to do this that's simply not listed there? ...

Django Admin app or roll my own?

I'm just starting to use Django for a personal project. What are the pros and cons of using the built-in Admin application versus integrating my administrative functions into the app itself (by checking request.user.is_staff)? This is a community wiki because it could be considered a poll. ...

Is there any case where len(someObj) does not call someObj's __len__ function?

Is there any case where len(someObj) does not call someObj's __len__ function? I recently replaced the former with the latter in a (sucessful) effort to speed up some code. I want to make sure there's not some edge case somewhere where len(someObj) is not the same as someObj.__len__(). ...

What's a good way to keep track of class instance variables in Python?

I'm a C++ programmer just starting to learn Python. I'd like to know how you keep track of instance variables in large Python classes. I'm used to having a .h file that gives me a neat list (complete with comments) of all the class' members. But since Python allows you to add new instance variables on the fly, how do you keep track of...

Progress bar not updating during operation

in my python program to upload a file to the internet, im using a GTK progress bar to show the upload progress. But the problems that im facing is that the progress bar does not show any activity until the upload is complete, and then it abruptly indicates upload complete. im using pycurl to make the http requests...my question is - do...

Is there a Python equivalent of Perl's x operator?

In Perl, I can replicate strings with the 'x' operator: $str = "x" x 5; Can I do something similar in Python? ...

Python's os.path choking on Hebrew filenames

Hello, I'm writing a script that has to move some file around, but unfortunately it doesn't seem os.path plays with internationalization very well. When I have files named in Hebrew, there are problems. Here's a screenshot of the contents of a directory: Now consider this code that goes over the files in this directory: files = os.l...

Deleting multiple elements from a list

Is it possible to delete multiple elements from a list at the same time? If I want to delete elements at index 0 and 2, and try something like del somelist[0], followed by del somelist[2], the second statement will actually delete somelist[3]. I suppose I could always delete the higher numbered elements first but I'm hoping there is a b...

Django workflow when modifying models frequently?

Hi gents, as I usually don't do the up front design of my models in Django projects I end up modifying the models a lot and thus deleting my test database every time (because "syncdb" won't ever alter the tables automatically for you). Below lies my workflow and I'd like to hear about yours. Any thoughts welcome.. Modify the model. De...

Python 3.0 `wsgiref` server not functioning

Hello, I can't seem to get the wsgiref module to work at all under Python 3.0. It works fine under 2.5 for me, however. Even when I try the example in the docs, it fails. It fails so hard that even if I have a print function above where I do: "from wsgiref.simple_server import make_server", it never gets printed for some reason. It doesn...

IronPython vs. C# for small-scale projects

I currently use Python for most of my programming projects (mainly rapid development of small programs and prototypes). I'd like to invest time in learning a language that gives me the flexibility to use various Microsoft tools and APIs whenever the opportunity arises. I'm trying to decide between IronPython and C#. Since Python is my fa...

Python string.join(list) on object array rather than string array

In Python, I can do: >>> list = ['a', 'b', 'c'] >>> ', '.join(list) 'a, b, c' Is there any easy way to do the same when I have a list of objects? >>> class Obj: ... def __str__(self): ... return 'name' ... >>> list = [Obj(), Obj(), Obj()] >>> ', '.join(list) Traceback (most recent call last): File "<stdin>", line 1, in ...

Python tuple operations

Is there anyway to get tuples operation in python to work like this: >>>a = (1,2,3) >>>b = (3,2,1) >>>a + b (4,4,4) instead of: >>>a = (1,2,3) >>>b = (3,2,1) >>>a + b (1,2,3,3,2,1) I know it works like that because the __add__ and __mul__ methods are defined to work like that. So the only way would be to redefine them? ...

How to make python gracefully fail?

Hi all, I was just wondering how do you make python fail in a user defined way in all possible errors. For example, I'm writing a program that processes a (large) list of items, and some of the items may not be in the format I defined. If python detects an error, it currently just spits out an ugly error message and stop the whole proc...

How do I compile a Visual Studio project from the command-line?

I'm scripting the checkout, build, distribution, test, and commit cycle for a large C++ solution that is using Monotone, CMake, Visual Studio Express 2008, and custom tests. All of the other parts seem pretty straight-forward, but I don't see how to compile the Visual Studio solution without getting the GUI. The script is written i...

Valid use case for django admin?

I want to build a django site where a certain group of trusted users can edit their profile information. Does it make sense to have each trusted user go through the django admin interface? I'd only want them to be able to see and edit their own information (obviously). It doesn't seem like this fits the way the django people define "trus...

Is Django a good choice for a security critical application?

Is Django a good choice for a security critical application? I am asking this because most of the online banking software is built using Java. Is there any real reason for this? ...

Minimal, Standalone, Distributable, cross platform web server.

I've been writing a fair number of smaller wsgi apps lately and am looking to find a web server that can be distributed, preconfigured to run the specific app. I know there are things like twisted and cherrypy which can serve up wsgi apps, but they seem to be missing a key piece of functionality for me, which is the ability to "pseudost...

Regular expression to extract URL from an HTML link

Im newbie in Python, i learning regex, but need help here Heres comes the source <a href="http://www.ptop.se" target="_blank">http://www.ptop.se&lt;/a&gt; I trying to code a tool that only prints out http://ptop.se, Can you help me please? ...

What's the best serialization method for objects in memcached?

My Python application currently uses the python-memcached API to set and get objects in memcached. This API uses Python's native pickle module to serialize and de-serialize Python objects. This API makes it simple and fast to store nested Python lists, dictionaries and tuples in memcached, and reading these objects back into the applic...