Skip to content
Advertisement

Tag: python

Sending mail from Python using SMTP

I’m using the following method to send mail from Python using SMTP. Is it the right method to use or are there gotchas I’m missing ? Answer The script I use is quite similar; I post it here as an example of how to use the email.* modules to generate MIME messages; so this script can be easily modified to

How to retrieve an element from a set without removing it?

Suppose the following: How do I get a value (any value) out of s without doing s.pop()? I want to leave the item in the set until I am sure I can remove it – something I can only be sure of after an asynchronous call to another host. Quick and dirty: But do you know of a better way?

How do I check if a list is empty?

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. For example, if passed the following: How do I check to see if a is empty? Answer Using the implicit booleanness of the empty list is quite Pythonic.

Best way to extract text from a Word doc without using COM/automation?

Is there a reasonable way to extract plain text from a Word file that doesn’t depend on COM automation? (This is a a feature for a web app deployed on a non-Windows platform – that’s non-negotiable in this case.) Antiword seems like it might be a reasonable option, but it seems like it might be abandoned. A Python solution would

Using Django time/date widgets in custom form

How can I use the nifty JavaScript date and time widgets that the default admin uses with my custom view? I have looked through the Django forms documentation, and it briefly mentions django.contrib.admin.widgets, but I don’t know how to use it? Here is my template that I want it applied on. Also, I think it should be noted that I

Validate (X)HTML in Python

What’s the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I’d like to be able to know where the failures occur, as in a web-based validator, except in a native Python app. Answer XHTML is easy, use lxml. HTML is harder, since there’s traditionally not been as much interest

How do you run a Python script as a service in Windows?

I am sketching the architecture for a set of programs that share various interrelated objects stored in a database. I want one of the programs to act as a service which provides a higher level interface for operations on these objects, and the other programs to access the objects through that service. I am currently aiming for Python and the

Advertisement