I need to determine the argspec (inspect.getargspec) of a function within a decorator:
def decor(func):
@wraps(func)
def _decor(*args, **kwargs):
return func(*args, **kwargs)
return _decor
@decor
def my_func(key=1, value=False):
pass
I need to be able to inspect the wrapped "my_func" and return the key/value a...
I have a class A that can be generated from two different ways.
a = A(path_to_xml_file)
a = A(listA, listB)
The first method has file path as an input to parse from XML file to get listA, and listB. The second method is given two lists.
I can think of two ways to implement multiple constructor. What do you think? What method normall...
I have a list of lists composed of tuples representing blocks of military times:
[[(1405, 1525)],[(1405,1455),(1605,1655)],[(1505,1555),(1405,1455),(1305,1355)]]
I have a function to compare the times of two tuples:
def doesOverlap(tuple1, tuple2):
#tuples each represent times for courses
#the 0 index for each tuple is a start...
Hello,
Is there an easier way to do this in Python (2.7)?: Note: This isn't anything fancy, like putting all local variables into a dictionary. Just the ones I specify in a list.
apple = 1
banana = 'f'
carrot = 3
fruitdict = {}
# I want to set the key equal to variable name, and value equal to variable value
# is there a more Pythonic...
Here is my code:
trainingSet = {"0,0":0, "1,0":1, "2,0":1, "0,1":0, "1,1":1, "1,2":0, "2,0":0, "2,1":0, "2,2":1}
for k,expectedOutput in trainingSet.iteritems():
print 1
coordinates = k.split(",")
network.layers[0].neurons[0].value = float(coordinates[0])
network.layers[0].neurons[1].value = float(coordinates[1])
ou...
Hi, I need a code with which I can send queries to Google and get the results back for some processing. i am mostly interested in retrieving the snippets of the results. It would be nice if I can do this without installing any extra packages for Python. A pre-written api would also do the trick.
Thanks
...
I am having some problems using raw IPv6 sockets in python. I connect via:
if self._socket != None:
# Close out old socket first
self._socket.close()
self._socket = socket.socket(socket.AF_INET6, socket.SOCK_RAW)
self._socket.bind((self._interface,0))
self._socket.sendall(data)
where self._interface is...
Hi. easy_thumbnails is a big help when making models or views for thumbnails.
I am using the templatetag (via template, not via model) and easy_thumbnails creates sucessfully the thumbnail files.
what happen when I want to use easy_thumbnails via view, not model o templatetag (the rendering of the images is via ajax, and django will ...
in curl i do this:
curl -u email:password http://api.foursquare.com/v1/venue.json?vid=2393749
How i can do this same thing in python?
...
I want to make (and decode) a single string composed of several python pickles.
Is there a character or sequence that is safe to use as a separator in this string?
I should be able to make the string like so:
s = pickle.dumps(o1) + PICKLE_SEPARATOR + pickle.dumps(o2) + PICKLE_SEPARATOR + pickle.dumps(o3) ...
I should be able to take...
Is there a way to remove/escape html tags using lxml.html and not beautifulsoup which has some xss issues? I tried using cleaner, but i want to remove all html.
...
I want the ability to let users indicate what countries they have visited.. my models.py looks something like this:
class User(models.Model):
name = models.CharField(max_length=50)
countries = models.ManyToManyField(Countries)
class Countries(models.Model):
#This is where I don't know what to do.
#The end goal i...
For example, if I'm decorating a method like so
def my_decorator(fn):
# Do something based on the class that fn is a method of
def decorated_fn(*args, **kwargs):
fn(*args, **kwargs)
return decorated_fn
class MyClass(object):
@my_decorator
def my_method(self, param):
print "foo"
Is it possible i...
I'm interested in subclassing django's ImageFileField to allow access to the image IPTC metadata, something like:
>>> from myapp.models import SomeModel
>>> obj = SomeModel.objects.all()[0] # or what have you
>>> obj.image.iptc['keywords']
('keyword','anotherkeyword','etc')
... the docs say to read over django's internal code, which I...
how can i use http.cookiejar to save cookie created with http.cookies
i use python 3.1 and apache 2.2
...
I'm trying to make a program to convert a number in any base to another base of the user's choice. The code I have so far goes like this:
innitvar = float(raw_input("Please enter a number: "))
basevar = int(raw_input("Please enter the base that your number is in: "))
convertvar = int(raw_input("Please enter the base that you would like ...
I'm writing a simple browser-based front end that should be able to launch a background task and then get progress from it. I want the browser to receive a response saying whether the task launched successfully, and then poll to determine when it is done. However, the presence of a background task seems to be stopping the XMLHttpReques...
I generate a long and ugly XML string with python, and I need to filter it through pretty printer to look better.
I found this post for python pretty printers, but I have to write the XML string to a file to be read back to use the tools, which I want to avoid if possible.
What python pretty tools that works on string are available?
...
I had this:
if Setting["Language"] == "en":
f.m_radioBox3.SetSelection(0)
elif Setting["Language"] == "pt":
f.m_radioBox3.SetSelection(1)
elif Setting["Language"] == "fr":
f.m_radioBox3.SetSelection(2)
elif Setting["Language"] == "es":
f.m_radioBox3.SetSelection(3)
Then I did this:
...
As far as my programming career went, I started out with Python, then went into Javascript, now I'm into PHP. I really want to learn a compiled language like c++ and Java. I don't exactly know how to start, especially since I'm currently looking into going into CS or CE in University, and my school don't offer anything that will let me l...