python

Finding points on a rectangle at a given angle

I'm trying to draw a gradient in a rectangle object, with a given angle (Theta), where the ends of the gradient are touching the perimeter of the rectangle. I thought that using tangent would work, but I'm having trouble getting the kinks out. Is there an easy algorithm that I am just missing? End Result So, this is going to be a fu...

Python and psycopg detect network error

Hi When connected to a postgresql database using psycopg and I pull the network cable I get no errors. How can I detect this in code to notify the user? ...

Tail Call Optimization in Mono/Ironpython

Hi Everyone, given that CLR supports tail call optimization I was wondering if Mono, and consequently Ironpython running on Mono has support for TCO ? ...

trouble getting pylint to find inherited methods in pylons/SA models

I have a Pylons app that I'm using SqlAlchemy declarative models for. In order to make the code a bit cleaner I add a .query onto the SA Base and inherit all my models from that. So in my app.model.meta I have Base = declarative_base() metadata = Base.metadata Session = scoped_session(sessionmaker()) Base.query = Session.query_proper...

python class attributes not setting?

I am having a weird problem with a chatbot I am writing that supports plugin extensions. The base extension class have attributes and methods predefined that will be inherited and can be overloaded and set. Here is the base class: class Ext: # Info about the extension Name = 'Unnamed' Author = 'Nobody' Version = 0 ...

How Do I Suppress or Disable Warnings in reSTructuredText?

I'm working on a CMS in Python that uses reStructuredText (via docutils) to format content. Alot of my content is imported from other sources and usually comes in the form of unformatted text documents. reST works great for this because it makes everything look pretty sane by default. One problem I am having, however, is that I get warn...

fit mysql db in memory

I am using Redis database where we store the navigational information. These data must be persistent and should be fetched faster. I don't have more than 200 MB data in this data set. I face problem when writing admin modules for redis db and I really missing the sql schema and power of django style admin modules. Now I am thinking of ...

Is there a way to print the elements of a list object in Python?

This is the object: mylist = Rep().all().fetch(10) More information here. Thanks. UPDATE4 The following code displays the lists: Rep().replist = L Rep().put() query = Rep.all() for result in query: self.response.out.write(result.replist) lik...

How do I access part of a list in Jinja2

I'm trying to use the jinja2 templating langauge to return the last n(say, 5) posts in my posts list: {% for recent in site.posts|reverse|slice(5) %} {% for post in recent %} <li> <a href="/{{ post.url }}">{{ post.title }}</a></li> {% endfor %} {% endfor %} This is returning the whole list though. How do you strip the...

Python/Mechanize - Can not select form - ParseError(exc)

Hello, i am getting this error: >>> br = Browser() >>> br.open("http://www.bestforumz.com/forum/") <response_seek_wrapper at 0x21f9fd0 whose wrapped object = <closeable_response at 0x21f9558 whose fp = <socket._fileobject object at 0x021F5F30>>> >>> br.select_form(nr=0) Traceback (most recent call last): File "<pyshell#3>", line 1, i...

Order of numpy orperations is not equal to logic (and also octave)?

Hi Everyone, Maybe this question should be strictly in the scipy-users, but I'll try here too. So here is something which I discovered lately and is making me wonder. I want to define a scalar which I call Net Absolute Mass Balance Error or in short NAMBE. This NAMBE is the absolute difference between a base vector and another vecto...

enumerate in python

Say, term='asdf'; InvertedIndex = {}; InvertedIndex[term] = [1,2,2,2,4,5,6,6,6,6,7]. Now we have this function which counts no. of occurances of any item. This is the function I've having a problem with. def TF(term, doc): idx = InvertedIndex[term].index(doc) return next(i for i, item in enumerate(InvertedIndex[term][idx:]) ...

Read other items in a python list while iterating through it

Possible Duplicate: Python: Looping through all but the last item of a list Is there a better way of iterating through a list when you also need the next item (or any other arbitrary item) in the list? I use this, but maybe someone can do better... values = [1, 3, 6, 7 ,9] diffs = [] for i in range(len(values)): try: diff...

Getting a 'Segmentation Fault' when executing a particular Django query

I've never come across this before, but for some strange reason i am getting a Segmentation Fault when running a specific query in Django. On reading up about Segmentation Faults, it seems it might have something to do with the version of Expat that Apache and Python use (and that they are different), what i am unsure about though, is wh...

Build soap message only, using SUDS

Hello! Currently I'm struggling while trying to generate soap message with SUDS. Things I want to achieve is something like xml_string = client.service.getPercentBodyFat('jeff', 68, 170) instead of calling remote procedure I want to get soap message as xml string or object. Thank You! ...

Fail safe code for cgi python scripts

Coming from mostly C++ I'm relatively new to python and probably far from thinking in pythonic ways. Recently my web hoster activated python as cgi for my web space. I got an email asking me to test any python scripts on a local server (xampp, ...) since my web space is hosted on a productivity server. Now my question is: What would be...

In what structure is a Python object stored in memory?

Possible Duplicate: How do I determine the size of an object in Python? Say I have a class A: class A(object): def __init__(self, x): self.x = x def __str__(self): return self.x And I use sys.getsizeof to see how many bytes instance of A takes: >>> sys.getsizeof(A(1)) 64 >>> sys.getsizeof(A('a')) 6...

Problem with reading file in Python

I have a file: Alus.txt File content: (each name in new line) Margus Mihkel Daniel Mark Juri Victor Marek Nikolai Pavel Kalle Problem: While programm reads this file, there are \n after each name (['Margus\n', 'Mihkel\n', 'Daniel\n', 'Mark\n', 'Juri\n', 'Victor\n', 'Marek\n', 'Nikolai\n...

Amarok 1.4 script: knowing who's running you

Hi all, I've been using Amarok 1.4 for a long time, switching to Bogdan Butnaru's packages when KDE stopped supporting it, and I'm now giving Pana a try. I realised that a script I wrote in Python for Amarok 1.4 will not immediately run without changes under Pana. But instead of converting my script, which basically comes down to repl...

string conversion

Hi there, I’ve got a long string object which has been formatted like this myString = “[name = john, family = candy, age = 72],[ name = jeff, family = Thomson, age = 24]” of course the string is longer than this. Also i have 3 lists with related names: Names = [] Families = [] Ages = [] I want to read that string character b...