python

libxml2-p25 on OS X 10.5 needs sudo?

When trying to use libxml2 as myself I get an error saying the package cannot be found. If I run as as super user I am able to import fine. I have installed python25 and all libxml2 and libxml2-py25 related libraries via fink and own the entire path including the library. Any ideas why I'd still need to sudo? ...

Are tuples more efficient than lists in Python?

Is there any performance difference between tuples and lists when it comes to instantiation and retrieval of elements? ...

Static class variables in Python

Is it possible to have static class variables or methods in python? What syntax is required to do this? ...

Best way to open a socket in Python

I want to open a TCP client socket in Python. Do I have to go through all the low-level BSD create-socket-handle / connect-socket stuff or is there a simpler one-line way ? What I'm looking for is something similar to fsockopen in PHP. ...

What's a good lightweight Python MVC framework?

I know there are a ton of Python frameworks out there. Can you guys point me in the right direction? My primary concern is simplicity, I don't need a lot of extraneous features. Here are a couple of other things that I'd want (or don't want): don't care for ORM, just want it to work with MySQL has configurable routes has support for la...

Take a screenshot via a python script. [Linux]

I want to take a screenshot via a python script and unobtrusively save it. I'm only interested in the Linux solution, and should support any X based environment. ...

Is it better to write new code/software for Python 3.0 or Python 2.6?

The question pertains to starting new projects using Python. Furthermore, I am referring to developing for the final releases of Python 2.6 and 3.0 (as oppose to Betas and RCs) which I imagine will be out in a few months. ...

Can I implement a web user authentication system in python without POST?

My university doesn't support the POST cgi method (I know, it's crazy), and I was hoping to be able to have a system where a user can have a username and password and log in securely. Is this even possible? If it's not, how would you do it with POST? Just out of curiosity. Cheers! ...

Why are Python's 'private' methods not actually private?

Python gives us the ability to create 'private' methods and variables within a class by prepending double underscores to the name, like so: *__myPrivateMethod()*. How, then, can one explain this >>> class MyClass: ... def myPublicMethod(self): ... print 'public method' ... def __myPrivateMethod(self): ... ...

Best online resource to learn Python?

I am new to any scripting language. But, Still I worked on scripting a bit like tailoring other scripts to work for my purpose. For me, What is the best online resource to learn Python? Some Online Resources: http://docs.python.org/tut/tut.html - Beginners http://diveintopython.org/ - Intermediate http://www.pythonchallenge....

Python Authentication API

I'm looking for a python library that will help me to create an authentication method for a desktop app I'm writing. I have found several method in web framework such as django or turbogears. I just want a kind of username-password association stored into a local file. I can write it by myself, but I'm really it already exists and will ...

Python Psycopg error and connection handling (v MySQLdb)

Another crack at this: I have a frequent problem with python's psycopg2, perhaps in 2 parts. First, I consistently screw up string assignment, if anyone can lobotomize line 5 below for me, much appreciated (The first answer does work with 1 value.) Second, when I try to add a long sequence to a table, something like string-number pair i...

Python and User input

How do I have a Python script that can accept user input (assuming this is possible) and how do I make it read in arguments if run from the command line? ...

Which python framework is best for web development in google app engine?

Which python framework is best for web development in google app engine? ...

HTML parser in Python

Using the Python Documentation I found the HTML parser but I have no idea which library to import to use it, how do I find this out (bearing in mind it doesn't say on the page). ...

OCSP command-line test tool?

Hi! Does anybody know of a tool to test OCSP responses? Preferably, something that can be used from a Windows Command-line and/or can be included (easily) in a Java/python program ...

Using the docstring from one method to automatically overwrite that of another method.

The problem: I have a class which contains a template method "execute" which calls another method "_execute". Subclasses are supposed to overwrite "_execute" to implement some specific functionality. This functionality should naturally be documented in the docstring of "_execute". I also expect users to create their own subclasses to ex...

Python and "re"

A tutorial I have on Regex in python explains how to use the re module in python, I wanted to grab the URL out of an A tag so knowing Regex I wrote the correct expression and tested it in my regex testing app of choice and ensured it worked. When placed into python it failed. After much head scratching I found out the issue, it automati...

Python's unittest logic

Can someone explain this result to me. The first test succeeds but the second fails, although the variable tested is changed in the first test. >>> class MyTest(unittest.TestCase): def setUp(self): self.i = 1 def testA(self): self.i = 3 self.assertEqual(self.i, 3) def testB(self): self.assertEqual(self.i,...

How to do relative imports in Python?

Imagine this directory structure: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py I'm coding mod1, and I need to import something from mod2. How should I do it? I tried from ..sub2 import mod2 but I'm getting an "Attempted relative import in non-package". I googled around but f...