python

When to choose R vs. SciPy?

What are some advantages and disadvantages to doing statistical analyses in SciPy vs. R? They seem to have been designed with opposite philosophies (plain old library vs. DSL). What are some rules of thumb about which is the right tool for the job? ...

Sqlalchemy query not commiting

Hi, I'm trying to create a simple unique username function for use in a Formencode schema. Here is the function: class UniqueUsername(formencode.FancyValidator): def _to_python(self, value, state): user = DBSession.query(User.user_name).filter(User.username==value) if user is not None: raise form...

How do I write good/correct __init__.py files

My package have the following structure: mobilescouter/ __init__.py #1 mapper/ __init__.py #2 lxml/ __init__.py #3 vehiclemapper.py vehiclefeaturemapper.py vehiclefeaturesetmapper.py ... basemapper.py vehicle/ __init__.py #4 vehic...

What is the relationship between __getattr__ and getattr .

i know this code is right class A: def __init__(self): self.a = 'a' def method(self): print "method print" a = A() print getattr(a, 'a', 'default') print getattr(a, 'b', 'default') print getattr(a, 'method', 'default') getattr(a, 'method', 'default')() but the next is wrong, dose __getattr...

Having trouble with Python's telnetlib module

I have a basic chat server which I can easily connect to with telnet. I simply enter the host and port and, without any further authentication, can begin entering commands that the server can interpret. In an effort to simulate user traffic, I would like to create a script that will open telnet, connect to the server, and immediately beg...

Python Format string "}" fill

Python 2.6 defines str.format(…), which, from Python 3.0, is preferred to the old % style of string formatting. Looking at the "mini-language", however, it seems that it is impossible to use the } character as a fill character. This seems like a strange omission to me. Is it possible to somehow escape that character and use it as a fill...

Format for DateTimeField

In Django I get this error "Enter a valid date/time in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format." when I try to assign a string "22-DEC-2009" to a DateTimeField in a model. How is it possible to make DateTimeField accept a date string in format "22-DEC-2009"? ...

Why does the following code always output 16?

def makeActions(): acts=[] for i in range(5): print len(acts) acts.append(lambda x: i ** x) print acts[i] return acts acts=makeActions() for i in range(5): print acts[i](2) Output: 16 16 16 16 16 Expected output: 0 1 4 9 16 ...

How can I copy a remote image over HTTP to gtk.gdk.pixbuf by Python?

Hello, this is first post here and I am a noob programmer. This may be a stupid question. I'd like to create a personal Twitter notifier on GNOE Desktop. And I've decided to use pynotify and Tweepy. Now I just want to make pynotify show Twitter user's icon, and there seems to be 2 ways using pynotify; setting URI to local image file, or...

python add a new div every 3rd iteration

Hello, I have a product list that put 3 products on a row and clears the row and adds another 3, this works fine everywhere but IE6, i know that adding <div> around each group of 3 products will solve this is the template file at the moment {% for product in category.products.all %} <div class="{% cycle 'clear' '' '' %}"> <a ...

Which is a more functional programming language, Haskell or Python?

Had learned Haskell during a Functional Programming course in school. Had found Haskell a bit difficult to work with. Have now worked a lot on Python. Python is quite easy to work with. Python does support some functional programming constructs. Was thinking of revisiting Functional Programming. What would be a better language to code?...

converting a zcml based python script to a standalone script in zope/plone

I have a python class working in zope 3 zcml kind of way, but i want to move the python into a standalone script that a could access via something along the lines of tal:content='context/get_tags'. This is the code as it stands: class TagListView(BrowserView): def getCategories(self): categories = set() for cat in self.portal_c...

os.path.join python

Hello, The below code will not join, when debugged the command does not store the whole path but just the last entry. os.path.join('/home/build/test/sandboxes/', todaystr, '/new_sandbox/') When I test this it only stores the '/new_sandbox/' part of the code. Can anyone help. Thanks ...

Variable referenced instead of copied

When I run the code below it removes deleted_partner from B. But as it removes it from B it also removes it from A. So that when I try to remove it from A the program crashes. What is the problem? for deleted_partner in self.list_of_trading_partners: B = A[:] print("t", deleted_partner) print(B[self.ID].list_of_trading_part...

How to control keyboard and mouse with Python?

Hello, How can I control the mouse and the keyboard in python? The idea is to do the same as the Robot() class in java. Be able to say : move the mouse from here to here, clic there, write that whatever is on the screen. For windows there is win32api but I'm using mainly linux For linux there is Xlib but does it works for keyboard as...

How to create an internationalized Google App Engine application

I would like to provide my Python GAE website in the user's own language, using only the tools available directly in App Engine. For that, I would like to use GNU gettext files (.po and .mo files). Has someone successfully combined Python Google App Engine and gettext files? If so, could you please provide the steps you used? I had st...

Best way to serialize a range of hours to meaningful data

A part of my web app involves creating 'appointments' (shifts) using a drag-and-drop selector for each day. Currently, this data is serialized to something like this: 9,10,11,12,13,14,15,16,76,77,78,298,299,300,301,302,303,304, Where each number represents the nth half-hour of the week (so 304 is the 300th half-hour of the week, or 8a...

In Django, How do I get escaped html in HttpResponse ?

The following code in one of my views returns unescaped html string which cannot be parsed in frontend since it is an Ajax request. return render_to_response(template_name, { 'form': form, redirect_field_name: redirect_to, 'site': current_site, 'site_name': current_site.name, }, context_instance=Reque...

Making Python code Pythonic

How would you make the give code more Pythonic? I want to get Paths out of the sample like /usr/local/sources/devel/algebra.py: def _alg(...) without the character :. My code import os FunctionPath = "/usr/local/sources/devel/sage-main/build/sage/" cmd = "grep -R 'def ' %s | cut -d' ' -f1" % (FunctionPath) cmd += ' &' raw_path = os.sy...

Python: How to change hex string int integer?

Possible Duplicate: Convert hex string to int in Python Hello, I want to use some string like "0xFF123456" as a 32-bit unsigned integer. Please give me some advice. Thanks. ...