python

how to convert a python slicing operation into java code

Hi, I have this code line: x and k are int. lm is an array lz=[f(x,lm[:j]+lm[j+1:],k) for j in range(n)] My question is: I want to convert the above line into Java... I have created an lm array in Java, but I am thinking of making it an arraylist to avoid the problem of the array length. I know that for instanse lm is [1, 4, 1, 9]...

Reading from CSVs in Python repeatedly?

I'm trying to check the value of extracted data against a csv I already have. It will only loop through the rows of the CSV once, I can only check one value of feed.items(). Is there a value I need to reset somewhere? Is there a better/more efficient way to do this? Thanks. orig = csv.reader(open("googlel.csv", "rb"), delimiter = ';') g...

How to import classes into other classes within the same file in Python

I have the file below and it is part of a django project called projectmanager, this file is projectmanager/projects/models.py . Whenever I use the python interpreter to import a Project just to test the functionality i get a name error for line 8 that FileRepo() cannot be found. How Can I import these classes correctly? Ideally what I a...

python VTE Terminal weirdness

i'm trying to use the terminal from python VTE binding (python-vte from debian squeeze) as a virtual terminal emulator (just for ANSI/control chars text processing) in interactive python console, everything looks (almost) all right: >>> import vte >>> term = vte.Terminal() >>> term.feed("a\nb") >>> print repr(term.get_text(lambda *a: T...

add gtk.widget in a gnome Applet

Hi, I have a question : I write a little gnome applet, and when we click on a button i want to add a gtk.widget under the "gnome-panel" like the calendar of the clock-applet. But I don't know how to do this. It's my code : listButton = gtk.Button(_("lastest")) self.listTwitt = gtk.TreeView() mainLayout = gtk.VBox() mainLayout.pack_s...

Problem with python urllib

I'm getting an error when ever I try to pull down a web page with urllib.urlopen. I've disabled windows firewall and my AV so its not that. I can access the pages in my browser. I even reinstalled python to rule out it being a broken urllib. Any help would be greatly appreciated. >>> import urllib >>> h = urllib.urlopen("http://www.goog...

How do I parse a templated string in Python?

I'm new to Python, so I'm not sure exactly what this operation is called, hence I'm having a hard time searching for information in it. Basically I'd like to have a string such as: "[[size]] widget that [[verb]] [[noun]]" Where size, verb, and noun are each a list. I'd like to interpret the string as a metalanguage, such that I can ...

Setting opacity on a PyGTK label

Is there a way to make a PyGTK widget partly transparent, so that the widgets behind it can be seen through it? Specifically I'm trying to do this on a label, for typographic effect; I don't want to change the color instead, as it may not look right on all themes. ...

How do I name a variable with acronym?

For example in Java for Data Transfer Object I use as: ExampleDTO exampleDTO = new ExampleDTO(); So, if I am following PEP 8 (lower_case_with_underscores), what naming convention should I use for similar in Python? ...

In Python, how to I create a datetime with X hours?

How do I create the datetime that is 24 hours before NOW()? 48 before NOW()? X hours or days before now?? ...

xml filtering with python

Hi, I have a following xml document: <node0> <node1> <node2 a1="x1"> ... </node2> <node2 a1="x2"> ... </node2> <node2 a1="x1"> ... </node2> </node1> </node0> I want to filter out node2 when a1 = x2. The user provides the xpath and attribute values that need to tested and filtered out. I looked at some soluti...

How do I count the highest key in a python dictionary? (very pythonic way?) EDIT: make a list

d = {'apple':9,'oranges':3,'grapes':22} How do I return the largest key/value? Edit: How do I make a list that has this sorted by largest to lowest value? ...

How do I send this email in Python, opening files and stuff?

msg = EmailMessage(subject, body, from_email, [to_email]) msg.content_subtype = "html" msg.send() This is how I send an email in Django. But what if I want to open a text file and take into account all its line breaks and tabs. I want to take the body of the text file (with line breaks \n) and email it as text of the "body". ...

Install h5py in Mac OS X 10.6.3

I'm trying to install h5py in Mac OS X 10.6.3. First I installed HDF5 1.8, which used the following commands: ./configure \ --prefix=/Library/Frameworks/Python.framework/Versions/Current \ --enable-shared \ --enable-production \ --enable-threadsafe \ CPPFLAGS=-I/Library/Frameworks/Python.framework/Versions/Current/include \ LDFLAGS=-L/...

How do I include the Django settings file?

I have a .py file in a directory , which is inside the Django project folder. I have email settings in my settings.py, but this .py file does not import that file. How can I specify to Django that settings.py should be used , so that I can use EmailMessage class with the settings that are in my settings.py? ...

Can EPD Python and MacPorts Python coexist on OS X (matplotlib)?

I've been using MacPorts Python 2.6 on OS X 10.6. I am considering also installing the Enthought Python Distribution (EPD) on the same machine because it comes preconfigured with matplotlib and other nice data analysis and visualization packages. Can the two Python distributions co-exist peacefully on the same machine? What potential ...

Open payment gateway libraries for Java, Python, Ruby, and PHP

I'm looking for generic and open source payment libraries that support many different payment processor APIs. In other words, I'd like to develop an application using a single payment processing API, but be able to easily switch between payment gateways, such as Authorize.Net, Payflow Pro, Braintree, PayPal, Google, Amazon, etc. This qu...

python feedparser with yahoo weather rss

I'm trying to use feedparser to get some data from yahoos weather rss. It looks like feed parser strips out the yweather namespace data: http://weather.yahooapis.com/forecastrss?w=24260013&amp;u=c <yweather:condition text="Fair" code="34" temp="23" date="Wed, 19 May 2010 5:55 pm EDT" /> looks like feedparser is completely ignoring...

django-admin.py startproject mysite not working well on windows 7

Hi I'm learning django and I did successfully start a site on Window XP by following the tutorial. However, on Window 7 when I issued: django-admin.py startproject mysite python.exe was started and a window appeared to ask me to choose either python.exe or other program to open a file.... did I do anthing wrong or there are more tric...

Python readability hints for a Java programmer

I'm a java programmer, but now entering the "realm of python" for some stuff for which Python works better. I'm quite sure a good portion of my code would look weird for a Python programmer (e.g. using parenthesis on every if). I know each language has its own conventions and set of "habits". So, from a readability standpoint what are c...