python

Is there an equivalent of Python's itertools for Java?

I'm searching for a library (preferably generic) that generates iterable combinations and permutations of data contained in collections. Cartesian product would also be nice. The best way of describing what I want would be "itertools for Java". ...

Can't set attributes of object class

So, I was playing around with Python while answering this question, and I discovered that this is not valid: o = object() o.attr = 'hello' due to an AttributeError: 'object' object has no attribute 'attr'. However, with any class inherited from object, it is valid: class Sub(object): pass s = Sub() s.attr = 'hello' Printing s....

Can a WIN32 program authenticate into Django authentication system, using MYSQL?

I have a web service with Django Framework. My friend's project is a WIN32 program and also a MS-sql server. The Win32 program currently has a login system that talks to a MS-sql for authentication. However, we would like to INTEGRATE this login system as one. Please answer the 2 things: I want scrap the MS-SQL to use only the Djang...

why is urllib2 missing table fields which I can see in the Firefox source?

the html that I am receiving from urllib2 is missing dozens of fields of data that I can see when I view the source of the URL in Firefox. Any advice would be much appreciated. Here is what it looks like: from FireFox view source: # ...<td class=td6>as</td></tr></thead>|ManyFields|<br></div><div id="c1">... from urllib2 return html...

Help to solve my problems with python LIST?

author_A = [['book_x',1,10],['book_y',2,20],['book_z',3,30]] author_B = [['book_s',5,10],['book_t',2,20],['book_z',3,30]] author_A AND author_B = ['book_z',3,30] author_A = [['book_x',1,10],['book_y',2,20]] author_B = [['book_s',5,10],['book_t',2,20]] --------------------------------------------- ...

Python sqlite3 "unable to open database file" on windows

I am working on a windows vista machine in python 3.1.1. I am trying to insert a large number of rows into a SQLite3 db. The file exists, and my program properly inserts some rows into the db. However, at some point in the insertion process, the program dies with this message: sqlite3.OperationalError: unable to open database file...

Print extremely large long in scientific notation in python

Is there a way to get python to print extremely large longs in scientific notation? I am talking about numbers on the order of 10^1000 or larger, at this size the standard print "%e" % num fails. For example: Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" f...

how to create new file using python

how can i create new file in /var/log directory using python language in OSX leopard? i tried to do it using os.open function but i get "permission denied" thanks in advance ...

How do I change the foreground or background colour of a Tkinter button on Max OS X 10.6 with Python 2.6.1?

I've been working through the Tkinter chapters in Programming Python and encountered a problem where the foreground and background colours of a button will not change. I am working on a Mac OS X 10.6 system with Python 2.6.1. The colours of a label will change, but not the colours of a button. For example: from Tkinter import * Label(N...

Debugging a scripting language like ruby

I am basically from the world of C language programming, now delving into the world of scripting languages like Ruby and Python. I am wondering how to do debugging. At present the steps I follow is, I complete a large script, Comment everything but the portion I want to check Execute the script Though it works, I am not able to deb...

Ruby methods equivalent of "if a in list" in python?

In python I can use this to check if the element in list a: >>> a = range(10) >>> 5 in a True >>> 16 in a False How this can be done in Ruby? ...

Cannot shuffle list in Python.

This is my list: biglist = [ {'title':'U2','link':'u2.com'}, {'title':'beatles','link':'beatles.com'} ] print random.shuffle(biglist) that doesn't work! It returns none. ...

In Django, the HTML code is shown instead of the actual text.

& g t ; Welcome How do I show the actual symbol instead? Is it a template filter? Thanks. ...

I heard that Python has automated "garbage collection" , but C++ does not. What does that mean?

I heard that Python has automated "garbage collection" , but C++ does not. What does that mean? ...

How do I change my float into a two decimal number with a comma as a decimal point separator in python?

I have a float: 1.2333333 How do I change it into a two decimal number with a comma as a decimal point separator, eg 1,23? ...

How to clear cookies using python 2.6.x cookielib

It seems my previous description was not clear, so rewriting it. Using python urllib2, I am automating fileupload task in my webapp. And am using Cookielib to store session information, and also I could able to successfully automate the fileupload task. Problem is, when I change the login credentials and did not supply those or supply ...

Definition of mathematical operations (sin…) on NumPy arrays containing objects

I would like to provide "all" mathematical functions for the number-like objects created by a module (the uncertainties.py module, which performs calculations with error propagation)—these objects are numbers with uncertainties. What is the best way to do this? Currently, I redefine most of the functions from math in the module uncerta...

Don't touch my shebang!

One thing I hate about distutils (I guess he is the evil who does this) is that it changes the shebang line. In other words, the more rational and environment-vars decided scripture #!/usr/bin/env python gets magically converted into #!/whatever/absolute/path/is/my/python This is seen also with grok: I used grokproject in a virtua...

how do I sign data with pyme?

I just installed pyme on my ubuntu system. it was easy (thanks apt-get) and I can reproduce the example code (encrypting using a public key in my keyring). now I would like to sign some data and I didn't manage to find any example code nor much documentation. this is what I've been doing: >>> plain = pyme.core.Data('this is just some...

Incrementally building a numpy array and measuring memory usage

I have a series of large text files (up to 1 gig) that are output from an experiment that need to be analysed in Python. They would be best loaded into a 2D numpy array, which presents the first question: As the number of rows is unknown at the beginning of the loading, how can a very large numpy array be most efficiently built, row by...