python

simple question about '//' in python

I saw this in someone's code: y = img_index // num_images where img_index is a running index and num_images is 3. when I mess around with '//' in ipython, it seems to act just like a division sign (i.e. one forward slash). I was just wondering if there is any reason for having double forward slashes? Thanks all! ...

How to interpret status code in Python commands.getstatusoutput()

In a related question, I asked where to find the documentation for the C function "wait." This was an attempt to figure out return codes for the commands.getstatusoutput() module. Stackoverflow came through, but the documentation didn't help. Here's what puzzles me: #!/usr/bin/python import commands goodcommand = 'ls /' badcommand = 'ls...

Python not a standardized language?

I stumbled upon this 'list of programming' languages and found that popular languages like Python are not standardized? Why is that, and what does 'Standardized' mean anyway? ...

Customizing time zones for Django users using geography

I am working on a Django app that needs to report the local time relative to the user. I would prefer not ask the user to input the time zone directly because I have his address stored in the database. I am only considering American users. Since most states in the USA are in only one time zone it is possible to calculate the time zone...

Turbogears 2.0 with Python 2.6

I've tried to install TurboGears 2.0 with Python 2.6 on both Windows 7 and Windows XP, but both give the same error: File "D:\PythonProjects\tg2env\Scripts\paster-script.py", line 8, in <module> load_entry_point('pastescript==1.7.3', 'console_scripts', 'paster')() File "D:\PythonProjects\tg2env\lib\site-packages\pastescript-1.7.3-py2.6....

How to do email-confirmation after registration in Django?

I am using Django's authentication system. Is there an easy way to do this? ...

Can't Delete Function Call

This question is just out of general curiosity. I've just noticed it when working on my current project (surprisingly I haven't came across before today). Take this code: List = ["hi","stack","over","flow","how","you","doing"] del List(len(List)-1) Error: SyntaxError: can't delete function call I don't understand why you aren't al...

Building universal binaries on Mac - Forcing single compiler child process

Cheers, at company, we're creating a port of our games, and we need to compile PythonOgre, a wrapper of Ogre3d for Python. This is an enormous chunk of code, particularly the generated wrapper code. We have a Mac Mini with 1GB RAM. We've built i386 version. Since we have only 1GB of RAM, we've forced the build system to use only one co...

Creating Title / Slug based on PK ID

What would be the generic way to create record title and slub based on the ID? I am working with django-photologue here. I want to save a record with title and slug based on the PK. The generic problem is that I can't get the PK until the record is saved into database. On the other side, I can't save it without title and slug. What com...

Reading from sockets and download speed

Just for fun, I develop a download manager and I'd like to know if reading a large stack of data (i.e. 80 or 100KB) from a socket over the net makes the download speed higher, instead of reading 4KB for each loop iteration? (My average download speed is 200KBPS when I download a file with firefox for example) Thanks, Nir Tayeb. ...

Variables inside and outside of a class __init__() function

I'm trying to understand, is there any difference at all between these classes besides the name? Does it make any difference if I use or don't use the __init__() function in declaring the variable "value"? class WithClass (): def __init__(self): self.value = "Bob" def my_func(self): print(self.value) class Witho...

What do I need to know/learn for automated python deployment?

I'm starting a new webapp project in Python to get into the Agile mind-set and I'd like to do things "properly" with regards to deployment. However, I'm finding the whole virtualenv/fabric/zc.buildout/etc stuff a little confusing - I'm used to just FTP'ing PHP files to a server and pointing a webserver at it. After deployment the server...

Identifying twitter user's longitude and latitude

As per my requirement in need to search twitter and display user's location on map. Can anyone help me identifying longitude and latitude from search api result? ...

SimpleParse non-deterministic grammar until runtime

Hi I'm working on a basic networking protocol in Python, which should be able to transfer both ASCII strings (read: EOL-terminated) and binary data. For the latter to be possible, I chose to create the grammar such that it contains the number of bytes to come which are going to be binary. For SimpleParse, the grammar would look like th...

Python multiprocessing and database access with pyodbc "is not safe"?

The Problem: I am getting the following traceback and don't understand what it means or how to fix it: Traceback (most recent call last): File "<string>", line 1, in <module> File "C:\Python26\lib\multiprocessing\forking.py", line 342, in main self = load(from_parent) File "C:\Python26\lib\pickle.py", line 1370, in load r...

Read bytes from string as floats

I've got a python webserver where small binary files are POST:ed. The posted data is represented as strings. I want to examine the contents of these strings. But to do that, I need to convert each 4 bytes to floats (little endian). How do you do that? ...

How to redirect and then display errors with Google App Engine

I'm working on a Google App Engine project that collects stories submitted by users. This is how I handle submission errors in the post method of my Request Handler: # get the title and content using self.request.get() errors = [] if not title: errors.append("Please enter a title.") if not content: errors.append("Please enter a...

QGraphicsView with automatic items placing

I would like to write an asset browser using QGraphicsView. It's a little different from examples using QGraphicsView and QGraphicsItems, because I want only one scrollbar and I want items to move automatically, when the viewport size changes. For example, when viewport width is large enough to display 4 asssets, they should be displayed...

How can I get the name of an object in Python?

Is there any way to get the name of an object in Python? For instance: my_list = [x, y, z] # x, y, z have been previously defined for bla in my_list: print "handling object ", name(bla) # <--- what would go instead of `name`? # do something to bla Edit: Some context: What I'm actually doing is creating a list of functions t...

how to extract text from djvu and other ebooks format (possibly in Python)

I have a collection of ebooks in djvu, pdf, chm format and I am looking for a way to search the keyword in the content. I have been researching around and find couple suggestion to parse pdf content but there seems to be no way to convert the content in djvu into text. By any chance, does anyone know a way to decode djvu content into tex...