python

Can I store a python dictionary in google's BigTable datastore without serializing it explicitly?

I have a python dictionary that I would like to store in Google's BigTable datastore (it is an attribute in a db.Model class). Is there an easy way to do this? i.e. using a db.DictionaryProperty? Or do I have to use pickle to serialize my dictionary? My dictionary is relatively straight forward. It consists of strings as keys, but it m...

deleting old folders with datetime function

Hello, I am trying to delete old folders and I am asking does anyone know how to set up a variable that allows me to check the variable 'todaystr' which is today's date and minus 7 days of this string and store it another variable. I am wanting to automatically delete old files after a week. Below shows the variable 'todaystr' being set...

Are CPython, IronPython, Jython scripts compatible with each other?

I am pretty sure that python scripts will work in all three, but I want to make sure. I have read here and there about editors that can write CPython, Jython, IronPython and I am hoping that I am looking to much into the distinction. My situation is I have 3 different api's that I want to test. Each api performs the same functionality...

Python instance method in C

Consider the following Python (3.x) code: class Foo(object): def bar(self): pass foo = Foo() How to write the same functionality in C? I mean, how do I create an object with a method in C? And then create an instance from it? Edit: Oh, sorry! I meant the same functionality via Python C API. How to create a Python method ...

How can I run 2 servers at once in Python?

Hello, I need to run 2 servers at once in Python using the threading module, but to call the function run(), the first server is running, but the second server does not run until the end of the first server. This is the source code: import os import sys import threading n_server = 0 n_server_lock = threading.Lock() class ServersThread...

Django: writing a manager to filter query set results

Hello all, I have the following code: class GroupDepartmentManager(models.Manager): def get_query_set(self): return super(GroupDepartmentManager, self).get_query_set().filter(group='1') class Department(models.Model): name = models.CharField(max_length=128) group = models.ForeignKey(Group) def __str__(self): return self.n...

What's the point of a main function and/or __name__ == "__main__" check in Python?

Possible Duplicate: What does <if __name__==__main__:> do? I occasionally notice something like the following in Python scripts: if __name__ == "__main__": # do stuff like call main() What's the point of this? ...

Basics of SymPy

I am just starting to play with SymPy and I am a bit surprised by some of its behavior, for instance this is not the results I would expect: >>> import sympy as s >>> (-1)**s.I == s.E**(-1* s.pi) False >>> s.I**s.I == s.exp(-s.pi/2) False Why are these returning False and is there a way to get it to convert from one way of writing a c...

How do I access a object's method when the method's name is in a variable?

Say I have a class object named test. test has various methods, one of them is whatever() . I have a variable named method = "whatever" How can I access the method using the variable with test? Thanks! ...

call python modules from java classes?

Hi is it possible, by using jython to call jython classes from java code? If yes, how please? ...

Python: which XML parsing library will work out-of-the-box for Python 2.4 and up?

How can I make sure that my Python script, which will be doing some XML parsing, will Just Work with Python 2.4, 2.5 and 2.6? Specifically, which (if any) XML parsing library is present in, and compatible between, all those versions? Edit: the working-out-of-the-box requirement is in place because the XML parsing I'm going to need to d...

Deploying Django at alwaysdata.com

i new on django i tried this but i cant deploy. how can i do #!/usr/bin/python import sys import os base = os.path.dirname(os.path.abspath(__file__)) + '/..' sys.path.append(base) os.environ['DJANGO_SETTINGS_MODULE'] = 'myfirstapp.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler() A...

python foreign character in csv

I have a little csv which contains foreign characters, like Chinese. How can I display them in Chinese instead of those \xa5\\xa4\ string??? Thanks ...

__getattr__ keeps returning None even when I attempt to return values

Try running the following code: class Test(object): def func_accepting_args(self,prop,*args): msg = "%s getter/setter got called with args %s" % (prop,args) print msg #this is prented return msg #Why is None returned? def __getattr__(self,name): if name.startswith("get_") or name.startswith("set_"): prop = name[...

Why is this a python syntax error during an initialisation?

This code: class Todo: def addto(self, list_name="", text=""): """ Adds an item to the specified list. """ if list_name == "": list_name = sys.argv[2] text = ''.join(sys.argv[3:] todo_list = TodoList(getListFilename(list_name)) produces a syntax error with the little arrow pointing to todo_list on the last line. The...

How to redirect stderr in Python?

I would like to log all the output of a Python script. I tried: import sys log = [] class writer(object): def write(self, data): log.append(data) sys.stdout = writer() sys.stderr = writer() Now, if I "print 'something' " it gets logged. But if I make for instance some syntax error, say "print 'something# ", it wont get ...

Python - Idiom to check if string is empty, print default

heya, I'm just wondering, is there a Python idiom to check if a string is empty, and then print a default if it's is? (The context is Django, for the __unicode__(self) function for UserProfile - basically, I want to print the first name and last name, if it exists, and then the username if they don't both exist). Cheers, Victor ...

How to redirect stderr in Python? Via Python C API?

This is a combination of my two recent questions: [1] http://stackoverflow.com/questions/1954494/python-instance-method-in-c [2] http://stackoverflow.com/questions/1956142/how-to-redirect-stderr-in-python I would like to log the output of both stdout and stderr from a python script. The thing I want to ask is, to create a new type acco...

i don't know __iter__ in python,who can give me a good code example.

my code run wrong class a(object): def __iter(self): return 33 b={'a':'aaa','b':'bbb'} c=a() print b.itervalues() print c.itervalues() Please try to use the code, rather than text, because my English is not very good, thank you ...

Determining version of easy_install/setuptools

I'm trying to install couchapp, which uses easy_install - and is quite explicit in stating a particular version of easy_install/setuptools is needed: 0.6c6. I seem to have easy_install already on my Mac, but there's no command-line arguments to check the version. Instead of just installing a new version over the top, I'd like to see whet...