python

How can I connect to a mail server using SMTP over SSL using Python?

Hello, So I have been having a hard time sending email from my school's email address. It is SSL and I could only find this code online by Matt Butcher that works with SSL: import smtplib, socket __version__ = "1.00" __all__ = ['SMTPSSLException', 'SMTP_SSL'] SSMTP_PORT = 465 class SMTPSSLException(smtplib.SMTPException): """Ba...

python class attribute

Hi, i have a question about class attribute in python. class base : def __init__ (self): pass derived_val = 1 t1 = base() t2 = base () t2.derived_val +=1 t2.__class__.derived_val +=2 print t2.derived_val # its value is 2 print t2.__class__.derived_val # its value is 3 The results are different. I also u...

Why can't I get Python's urlopen() method to work?

Why isn't this simple Python code working? import urllib file = urllib.urlopen('http://www.google.com') print file.read() This is the error that I get: Traceback (most recent call last): File "C:\workspace\GarchUpdate\src\Practice.py", line 26, in <module> file = urllib.urlopen('http://www.google.com') File "C:\Python26\lib\u...

Having a Python package install itself under a different name

I'm developing a package called garlicsim. (Website.) The package is intended for Python 2.X, but I am also offerring Python 3 support on a different fork called garlicsim_py3.(1) So both of these packages live side by side on PyPI, and Python 3 users install garlicsim_py3, and Python 2 users install garlicsim. The problem is: When thi...

how to create plots (non-flash) with mouse-over info boxes on the fly for the web?

Hi, I'm thinking about creating a tool to visualize scientific data on a website. For this, the user enters some query string and out comes a simple (x,y)-plot (similar to this) I know that using Matplotlib, one can generate graphics on the fly for python. However, this doesn't solve the need for some custom java-script code to display...

Python/Sqlite program, write as browser app or desktop app?

I am in the planning stages of rewriting an Access db I wrote several years ago in a full fledged program. I have very slight experience coding, but not enough to call myself a programmer by far. I'll definitely be learning as I go, so I'd like to keep everything as simple as possible. I've decided on Python and SQLite for my program,...

Calling python script from crontab with activate

how do i call a python script from crontab that requires using activate (source env/bin/active)? ...

What's a good equivalent to python's subprocess.check_call that returns the contents of stdout?

I'd like a good method that matches the interface of subprocess.check_call -- ie, it throws CalledProcessError when it fails, is synchronous, &c -- but instead of returning the return code of the command (if it even does that) returns the program's output, either only stdout, or a tuple of (stdout, stderr). Does somebody have a method t...

Building a survey to put in a WordPress website using Python/Django

So I've been given a task to build a survey to get data regarding time slot preferences of prospective students for a particular course. I know there are really quick solutions to this like Google Forms, SurveyMonkey, but since it's not unusually hard, I want to implement the survey myself in a totally new language as an opportunity to g...

Inspiration and influence of the else clause of loop statements?

Python loop statements may have an else clause which is executed if and only if the loop is not terminated by a break. In other words, when the condition becomes False (with while) or when the iterator is exhausted (with for). Does this loop-else construct originate from another language (either theoretical or actually implemented)? Ha...

Are there libraries or techniques for collecting and weighing keywords from a block of text?

I have a field in my database that can contain large blocks of text. I need to make this searchable but don't have the ability to use full text searching. Instead, on update, I want my business layer to process the block of text and extract keywords from it which I can save as searchable metadata. Ideally, these keywords could then be...

IP address of domain on shared host

I have domain on a shared hosting provider. How do I find the direct IP address of my domain using Python? Is it possible to post to a script on my domain using the IP address and not the website itself? Thanks. ...

Images not loading in QWebview in PyQt4 in py2exe

I have an application that displays some HTML in a QWebview, which references images on the local file system. This works fine directly running the python. When compiling via py2exe, the images no longer load. Google doesn't seem to know the answer, any ideas? ...

Python unicode problem

I'm receiving some data from a ZODB (Zope Object Database). I receive a mybrains object. Then I do: o = mybrains.getObject() and I receive a "Person" object in my project. Then, I can do b = o.name and doing print b on my class I get: José Carlos and print b.name.__class__ <type 'unicode'> I have a lot of "Person" objects. T...

numpy array C api

I have a C++ function returning a std::vector and I want to use it in python, so I'm using the C numpy api: static PyObject * py_integrate(PyObject *self, PyObject *args){ ... std::vector<double> integral; cpp_function(integral); // this change integral npy_intp size = {integral.size()}; PyObject *out = PyArray_SimpleNewFromData(1, &...

Type-aware rendering (and editing) of tabular data in pyqt4

I would like to have a very short / minimal example of how to create some tabular widget with different types of item in it. In the first round let's say I'd like to render [["Hello", 12, True], ["World", 13, False]] (Hello as string, 12 as number (right-align), True as a checkbox for eg.), but it would be nice to have Dates, Colors, an...

Is there a way to convert code to a string and vice versa in Python?

The original question was: Is there a way to declare macros in Python as they are declared in C: #define OBJWITHSIZE(_x) (sizeof _x)/(sizeof _x[0]) Here's what I'm trying to find out: Is there a way to avoid code duplication in Python? In one part of a program I'm writing, I have a function: def replaceProgramFilesPath(filenameBr):...

Get "2:35pm" instead of "02:35PM" from Python date/time?

I'm still a bit slow with Python, so I haven't got this figured out beyond what's obviously in the docs, etc. I've worked with Django a bit, where they've added some datetime formatting options via template tags, but in regular python code how can I get the 12-hour hour without a leading zero? Is there a straightforward way to do thi...

Python matching some characters into a string

Hi All I'm trying to extract/match data from a string using regular expression but I don't seem to get it. I wan't to extract from the following string the i386 (The text between the last - and .iso): /xubuntu/daily/current/lucid-alternate-i386.iso This should also work in case of: /xubuntu/daily/current/lucid-alternate-amd64.iso ...

Place image over PDF

How can I place an image over an existing PDF file at an specific coordinate location. The pdf represents a drawing sheet with one page. The image will be scaled. I'm checking ReportLab but can't find the answer. Thanks. ...