python

python: Writing Application- Different modules/Licenses and impact on Proprietary application

Hello, I've written an application using wxPython and various other small modules (xlrd, xlwrt, pyserial, etc.) xlrd/xlwt i believe use a BSD license, and wxPython.. ""Being a wrapper, wxPython uses the same free software licence used by wxWidgets (wxWindows License)—which is approved by Free Software Foundation and Open Source ...

Fastest way to convert file from latin1 to utf-8 in python.

I need fastest way to convert files from latin1 to utf-8 in python. The files are large ~ 2G. ( I am moving DB data ). So far I have import codecs infile = codecs.open(tmpfile, 'r', encoding='latin1') outfile = codecs.open(tmpfile1, 'w', encoding='utf-8') for line in infile: outfile.write(line) infile.close() outfile.close() but ...

How to check if text is "empty" (spaces, tabs, newlines) in Python?

How can I test if the string is empty in Python? For example, "<space><space><space>" is empty, so is "<space><tab><space><newline><space>", so is "<newline><newline><newline><tab><newline>", etc. ...

Own help message using optparse

Hi there, is possible to make own help message or attach own event on help option using optparse module in Python? ...

How do I override __getattr__ in Python without breaking the default behavior?

I want to override the __getattr__ method on a class to do something fancy but I don't want to break the default behavior. What's the correct way to do this? ...

Why would memcached refuse to store data with some keys ?

Hello, I use the memcache extension for python, and I have a very strange problem. Memcached refuses to store the exact same data with some keys, and succeeds in caching some others. >>> import memcache >>> conn = memcache.Client('121.0.0.1:11211', debug=0) >>> conn.set('138b9c95d693760840aab85ee5591d2', 'test'); True >>> conn.set('138...

Python: how to switch between workspaces using Xlib?

Hi, how do I switch between my window manager's workspaces using Python with Xlib module? I've been searching Google the last couple of hours, and this is my most promising attempt: #!/usr/bin/python from Xlib import X, display, error, Xatom, Xutil import Xlib.protocol.event screen = Xlib.display.Display().screen() root = screen.r...

How to stop a QDialog from executing while still in the __init__ statement(or immediatly after)?

I am wondering how I can go about stopping a dialog from opening if certain conditions are met in its __init__ statement. The following code tries to call the 'self.close()' function and it does, but (I'm assuming) since the dialog has not yet started its event loop, that it doesn't trigger the close event? So is there another way to c...

Traverse Object Graph in Python(BeanUtils/OGNL for Python)

Hi, I'd like to know how to traverse an object graph in python from a String, is there any project or feature like OGNL (http://www.opensymphony.com/ognl/) or BeanUtils (http://commons.apache.org/beanutils/) in Java? Basicaly I need to write a string "property.innerproperty = True" or "property = 'xpto'" and process it from a root obje...

Python: Indexing list for element in nested list

I know what I'm looking for. I want python to tell me which list it's in. Here's some pseudocode: item = "a" nested_list = [["a", "b"], ["c", "d"]] list.index(item) #obviously this doesn't work here I would want python to return 0 (because "a" is an element in the first sub-list in the bigger list). I don't care which sub-element...

Use of infix operator hack in production code (Python)

What is your opinion of using the infix operator hack in production code? Issues: The effect this will have on speed. The potential for a clashes with an object with these operators already defined. This seems particularly dangerous with generic code that is intended to handle objects of any type. It is a shame that this isn't built ...

Python Naming Conventions for Dictionaries/Maps/Hashes

While other questions have tackled the broader category of sequences and modules, I ask this very specific question: "What naming convention do you use for dictionaries and why?" Some naming convention samples I have been considering: # 'value' is the data type stored in the map, while 'key' is the type of key value_for_key={key1:valu...

detecting circular imports

I'm working with a project that contains about 30 unique modules. It wasn't designed too well, so it's common that I create circular imports when adding some new functionality to the project. Of course, when I add the circular import, I'm unaware of it. Sometimes it's pretty obvious I've made a circular import when I get an error like A...

Get the last '/' or '\\' character in Python

If I have a string that looks like either ./A/B/c.d OR .\A\B\c.d How do I get just the "./A/B/" part? The direction of the slashes can be the same as they are passed. This problem kinda boils down to: How do I get the last of a specific character in a string? Basically, I want the path of a file without the file part of it. ...

Setting up a python screen scraper that could work on Google App engine

I am looking to setup a automated screen scraper that will run on Google app engine using python. I want it to scrape the site and put the specified results into a Entity in app engine. I am looking for some directions on what to use. I have seen beautifulsoup but wonder if people could recommend anything else that could run on Google Ap...

Python: I need a code to auto login a website with HTTPS

Hi, I'm new here and on python too, and i need a code to login an HTTPS webpage the page is: ritaj.birzeit.edu and how can i know if its correct username or password , can you help in this :) ...

Getting readline to block on a FIFO

I create a fifo: mkfifo tofetch I run this python code: fetchlistfile = file("tofetch", "r") while 1: nextfetch = fetchlistfile.readline() print nextfetch It stalls on readline, as I would hope. I run: echo "test" > tofetch And my program doesn't stall anymore. It reads the line, and then continues looping forever. Why w...

Implementing a Patricia Trie for use as a dictionary

I'm attempting to implement a Patricia Trie with the methods addWord(), isWord(), and isPrefix() as a means to store a large dictionary of words for quick retrieval (including prefix search). I've read up on the concepts but they just aren't clarifying into an implementation. I want to know (in Java or Python code) how to implement the T...

Google App Engine: Users API acting oddly

I think I'm using the Users API incorrectly: class BaseHandler(webapp.RequestHandler): user = users.get_current_user() def header(self, title): if self.user: render('Views/link.html', self, {'text': 'Log out', 'href': users.create_logout_url('/')}) else: render('Views/link.html', self, {'text': 'Log in',...

I want to scrape a site using GAE and post the results into a Google Entity

I want to scrape this URL : https://www.xstreetsl.com/modules.php?searchSubmitImage_x=0&amp;searchSubmitImage_y=0&amp;SearchLocale=0&amp;name=Marketplace&amp;SearchKeyword=business&amp;searchSubmitImage.x=0&amp;searchSubmitImage.y=0&amp;SearchLocale=0&amp;SearchPriceMin=&amp;SearchPriceMax=&amp;SearchRatingMin=&amp;SearchRatingMax=&amp;s...