python

SQL Alchemy - How to Delete from a model instance?

Say I get a model instance like this: instance = session.query(MyModel).filter_by(id=1).first() How can I delete that row? Is there a special method to call? ...

Python Regex Question

I have an end tag followed by a carriage return line feed (x0Dx0A) followd by one or more tabs (x09) followed by a new start tag . Something like this: </tag1>x0Dx0Ax09x09x09<tag2> or </tag1>x0Dx0Ax09x09x09x09x09<tag2> What Python regex should I use to replace it with something like this: </tag1><tag3>content</tag3><tag2> Than...

Iterate across lines in two files simultaneously in Python

I have two files, and I want to perform some line-wise operation across both of them. (In other words, the first lines of each file correspond, as do the second, etc.) Now, I can think of a number of slightly cumbersome ways to iterate across both files simultaneously; however, this is Python, so I imagine that there is some syntactic sh...

Simple Python Vairable Scope

Hey all again. It appears to me that functions can reference variables outside of their scope but cannot set them. Is this correct? Am I understanding this right. I also included the gloals usage,. I KNOW they are bad - ju-ju and will avoid. I know how to get around this but just want to be clear. My example program: import foo # b...

Cross-Platform Bonjour

Is it possible to write a program using Bonjour or a Bonjour-compatible library in a cross-platform language such as Java or Python? If so, where can I find the files needed for this? ...

Java <-> Python localhost stream, Java does not continue

Problem Summary I've got an application which combines both Java and Python, the two languages communicating across a localhost socket. (I cannot use Jython, I can't throw out Java for PyGame, and I can't throw out Python for pure Java.) The application opens the socket between Python and Java and a socket from Java to a central server...

Help on Regular Expression problem

Hi, i wonder if it's possible to make a RegEx for the following data pattern: '152: Ashkenazi A, Benlifer A, Korenblit J, Silberstein SD.' string = '152: Ashkenazi A, Benlifer A, Korenblit J, Silberstein SD.' I am using this Regular Expression (Using Python's re module) to extract these names: re.findall(r'(\d+): (.+), (.+), (.+), (...

How to set fixed depth levels in DOT graphs

I'm creating a DOT graph visualization from a tree-like data structure but am having difficulties setting fixed level depths based upon data type. For example, if I had 4 nodes in a tree and A denotes a specific data type and B represents another it would like Graph_1: ROOT ...

How do I connect to a UDP port in Python?

Like everyone else, I can say "I've tried everything!" I kind of did. I looked all over StackOverflow, and tried all the answers, but got nothing. Anyways, I am jetting to at least get some code printed by Python before I get even further in developing this. I want to receive UDP packets from my Garry's Mod server (logaddress_add MyIP:7...

Maximum recursion depth?

I have this tail recursive function here: def fib(n, sum): if n < 1: return sum else: return fib(n-1, sum+n) c = 998 print(fib(c, 0)) It works up to n=997, then it just breaks and spits a "maximum recursion depth exceeded in comparison" RuntimeError. Is this just a stack overflow? Is there a way to get around ...

celery-django can't find settings

I have a Django project that uses Celery for running asynchronous tasks. I'm doing my development on a Windows XP machine. Starting my Django server (python manage.py runserver 80) works fine, but attempting to start the Celery Daemon (python manage.py celeryd start) fails with the following error: ImportError: Could not import settin...

Am I supposed to directly modify User models in auth modules in frameworks?

I am new to using Frameworks for web development and I have noticed that frameworks like django, turbogears etc come with auth packages which contains user models. Am I supposed to directly modify these and use them as my User models or am I supposed to associate my own user models to these and use them just for authentication? ...

python matplotlib will only plot integers

Hi, I'm very new to python. two days. trying to get a plot working with matplotlib. I'm getting this error: cannot perform reduce with flexible type the line with the error is: ax.scatter(x,y,z,marker='o') Variables: ax is defined as: ax = Axes3D(fig) fig is defined as: fig = plt.figure() x, y, z are lists Any python expert...

Start ipython running a script

My use case is I want to initialize some functions in a file and then start up ipython with those functions defined. Is there any way to do something like ipython --run_script=myscript.py? ...

Merging a list of lists in python

Possible Duplicate: join list of lists in python Is there in Python a built-in or a particular syntax to accomplish the following on the fly? def merge(listOfLists): result = [] for l in listOfLists: result.extend(l) return result print merge( [[1,2,3,4], [5,6], [7,8,9]] ) # [1, 2, 3, 4, 5, 6, 7, 8, 9] ...

How to use same cookies in multiple request in python?

I am using this code: def req(url, postfields): proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"}) opener = urllib2.build_opener(proxy_support) opener.addheaders = [('User-agent', 'Mozilla/5.0')] return opener.open(url).read() To make a simple http get request (using tor as proxy). Now I would like to ...

How to find a *good* software job if you are a new graduate?

Hi, I'll soon (in an year) be graduating with an undergraduate master's (four years) in computer related field. At my university campus placements will start the coming semester. This will be the last semester on campus as we would be going off campus for industry internships in the final semester. Generally the Placement Division gets ...

In Django I have a complex query where I need only the unique values through a foreign key, is this possible?

I have the following models: class Indicator(models.Model): name = models.CharField(max_length=200) category = models.ForeignKey(IndicatorCategory) weight = models.IntegerField() industry = models.ForeignKey(Industry) def __unicode__(self): return self.name class Meta: ordering = ('name',) clas...

Scala - how to build an immutable map from a collection of Tuple2s?

Hi all, In Python, a dictionary can be constructed from an iterable collection of tuples: >>> listOfTuples = zip(range(10), [-x for x in range(10)]) >>> listOfTuples [(0, 0), (1, -1), (2, -2), (3, -3), (4, -4), (5, -5), (6, -6), (7, -7), (8, -8), (9, -9)] >>> theDict = dict(listOfTuples) >>> theDict {0: 0, 1: -1, 2: -2, 3: -3, 4: -4, 5...

Using Ruby, Perl, or Python, how to "Move the window 'Firefox' to coordinate (0,0) on screen and resize it 1024 x 768"?

Can it be moved by Window Title as well as exe name? Other info on moving it in another language could be helpful. Update: some Perl sample can be found in Win32::GuiTest but there seems to be no resize or move functions. ...