I don't understand why the new instance of the TypeList class does not have a my_type attribute.
t.i.a. for any help
Here is my code:
import copy
class TypedList(list):
def __init__(self, typeof, iterable=''):
"""
Initialize the typed list.
Examples:
tmp = TypedList(str, 'foobar') # OK
tmp...
I want to send chinese characters to be translated by an online service, and have the resulting english string returned.
I'm using simple json and urllib for this.
And yes, i am declaring.
# -*- coding: utf-8 -*-
on top of my code.
The thing is, now everything works fine if i feed urllib a string type object, even if that object c...
I am new to python and am doing an export and import to a new db.
I have a column on my export (to be imported) of strings for units of time, "20 minutes" "1.5 hours" "2 1/2 hours", etc.
I tried googling but couldn't really find any good phrases and kept coming up with information more related to datetime units rather than just units ...
Hello,
I need to access variables given their names, in the following way:
a = numpy.array([1,2,3])
b = numpy.array([4,5,6])
names = ('a', 'b')
Then, I pass the variable names to a function, say numpy.hstack() to obtain the same result as with numpy.hstack((a,b)).
What is the best pythonic way to do so?
And what is the purpose? I ...
I had been using using PIL but I just found out that it doesn't support 16bit tiffs.
I need a library that can do:
1)Image conversion -->16bit tiff to jpeg
2)Image resize and crop and of jpegs
...
In the code below, I am considering using mutli-threading or multi-process for fetching from url. I think pools would be ideal, Can anyone help suggest solution..
Idea: pool thread/process, collect data... my preference is process over thread, but not sure.
import urllib
URL = "http://download.finance.yahoo.com/d/quotes.csv?s=%s&am...
def display_hand(hand):
for letter in hand.keys():
for j in range(hand[letter]):
print letter,
Will return something like: b e h q u w x. This is the desired output.
How can I modify this code to get the output only when the funtion has finished its loops?
Something like below code causes me problems as I can...
I'm downloading a web page (with PyQt4/QtWebKit) using given hostname, but I would like to use a pre-defined IP address for that hostname. For example, I need to hit "http://www.mysite.com" but use the IP address 1.2.3.4 instead of the actual resolved IP address. Is this at all possible in QtWebKit? I've tried a couple things so far:
H...
Well, I'm trying to build a small python prgram with a SocketServer that is supposed to send messages it receives to all connected clients. I'm stuck, I don't know how to store clients on the serverside, and I don't know how to send to multiple clients. Oh and, my program fails everytime more then 1 client connects, and everytime a clien...
I have some python code on both the client and server side. I am getting an IncompleteRead exception thrown for what seems to be no good reason. I can navigate to the URL with Firefox without any error message and also WGET it without any odd results.
The server code is:
import random
import hashlib
print "Content-Type: text/html" ...
I'm running memcached with the following bash command pattern:
memcached -vv 2>&1 | tee memkeywatch2010098.log 2>&1 | ~/bin/memtracer.py | tee memkeywatchCounts20100908.log
to try and track down unmatched gets to sets for keys platform wide.
The memtracer script is below and works as desired, with one minor issue. Watching the inter...
I do have several small modules where the tests are inside them and py.test or nose does not look for them because they do not contain test in their filename.
How can I convince py.test or nose to look for tests inside all python files, recursively - '''including the ones that do not have test in their filenames'''?
Inside the source f...
I have this script which processes lines containing windows file paths. However the script is running on Linux. Is there a way to change the os library to do Windows file path handling while running on linux?
I was thinking something like:
import os
os.pathsep = '\\'
(which doesn't work since os.pathsep is ; for some reason)
My sc...
Hello,
I've been trying to pass my login and password from Python script to the eBay sign-in page. Later I want this script to be run from "Google App Engine"
I was suggested to use "mechanize". Unfortunately, it didn't work for me:
IDLE 1.2.4
>>> import re
>>> import mechanize
>>> br = mechanize.Browser()
>>> br.open("https:...
I've come across a bug in Python (at least in 2.6.1) for the bytearray.fromhex function. This is what happens if you try the example from the docstring:
>>> bytearray.fromhex('B9 01EF')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: fromhex() argument 1 must be unicode, not str
This example works f...
I am using the App Engine Bulk loader (Python Runtime) to bulk upload entities to the data store. The data that i am uploading is stored in a proprietary format, so i have implemented by own connector (registerd it in bulkload_config.py) to convert it to the intermediate python dictionary.
import google.appengine.ext.bulkload import con...
Hello all,
I have a very large db that I am working with, and I need to know how to select a large set of id's which doesn't have any real pattern to them. This is segment of code I have so far:
longIdList = [1, 3, 5 ,8 ....................................]
for id in longIdList
sql = "select * from Table where id = %s" %id
resu...
Python 3.1.2
Windows XP SP3
I am running into a problem with some files and their timestamps in python. I have a bunch of files in a directory that I received from an external source. It's not every file I am having a problem with but for some files python is showing an hour difference from what explorer or cmd show in XP. I am specif...
Hi,
in my Pylons app i write a script to autogenerate thumbnail, from image geting by url.
To generate thumbnail i use PIL(python)
W wont to prevent image cache by browser.
I can't use after src ?[random_number] because the site, where i past this image must be static.
I try to send headers
response.headers['Cache-Control'] = 'n...
From the Django intro tutorial, in \mysite\polls\admin.py:
from django.contrib import admin
#...
class PollAdmin(admin.ModelAdmin):
#...
inlines = [ChoiceInline]
list_display = ('question', 'pub_date', 'was_published_today')
list_filter = ['pub_date']
admin.site.register(Poll, PollAdmin)
Why do inlines and list_filter both us...