hi there, are there any way to create an object form any class inside a numpy array?¿. Something like:
a = zeros(4)
for i in range(4):
a[i]=Register()
Thanks
From what I can tell, pdb does not recognize when the source code has changed between "runs". That is, if I'm debugging, notice a bug, fix that bug, and rerun the program in pdb (i.e. without exiting pdb), pdb will not recompile the code. I'll still be debugging the old version of the code, even if pdb lists the new source code.
So, does pdb not update the compiled code as the source changes? If not, is there a way to make it do so? I'd like to be able to stay in a single pdb session in order to keep my breakpoints and such.
FWIW, gdb will notice when the program it's debugging changes underneath it, though only on a restart of that program. This is the behavior I'm trying to replicate in pdb.
I have the following model:
class Image(db.Model):
auction = db.ReferenceProperty(Auction)
image = db.BlobProperty()
thumb = db.BlobProperty()
caption = db.StringProperty()
item_to_tag = db.StringProperty()
And the following form:
class ImageForm(djangoforms.ModelForm):
class Meta:
model = Image
When I call ImageForm(), only the non-Blob fields are created, like this:
<tr><th><label for="id_auction">Auction:</label></th><td><select name="auction" id="id_auction">
<option value="" selected="selected">---------</option>
<option value="ahRoYXJ0bWFuYXVjdGlvbmVlcmluZ3INCxIHQXVjdGlvbhgKDA">2010-06-19 11:00:00</option>
</select></td></tr>
<tr><th><label for="id_caption">Caption:</label></th><td><input type="text" name="caption" id="id_caption" /></td></tr>
<tr><th><label for="id_item_to_tag">Item to tag:</label></th><td><input type="text" name="item_to_tag" id="id_item_to_tag" /></td></tr>
I want the Blob fields to be included in the form as well (as file inputs). What am I doing wrong?
I am building a high school team application using Django.
Here is my working models file:
class Directory(models.Model):
school = models.CharField(max_length=60)
website = models.URLField()
district = models.SmallIntegerField()
conference = models.ForeignKey(Conference)
class Conference(models.Model):
conference_name = models.CharField(max_length=50)
url = models.URLField()
class Meta:
ordering = ['conference_name']
When I open my admin pages and go to edit a school's conference the drop down looks like this:
<select>
<option value="1">Conference Object</option>
<option value="2">Conference Object</option>
<select>
How do I replace "Conference Object" with the conference_name?
I am using PyGTK to build a GUI application. I want to update the textview widget from another thread but the widget is not getting updated everytime i try an update. What should i do to get a reliable GUI updating?
In using the m4_ax_python_module.m4 macro in configure.ac (AX_PYTHON_MODULE), one can know at configure time if a given module is installed. It takes two arguments, the module name, and second argument which if not empty, will lead to an exit, useful when the module is a must-have.
In the case where you don't want a fatal exit, how do you test in configure.ac which modules were found or not? They output "yes" or "no" when configure is run, but that's all I've found so far. Basically If I have these lines in configure.ac:
AX_PYTHON_MODULE(json,[])
AX_PYTHON_MODULE(simplejson,[])
How do I test which of the two modules were found?
See http://www.gnu.org/software/autoconf-archive/ax_python_module.html#ax_python_module for documentation about this macro.
I'm using Turbogears 2.1 and repoze.who/what and am having trouble figuring out how to extend the basic authentication functionality. I am essentially attempting to require users to activate their account via an emailed link before they can login. If they try to login without activating their account, I want to display an appropriate error message. The default Turbogears functionality simply displays one message for all errors.
I created my own authentication plugin which works fine. It won't allow users to login if they have not activated their account. However, the problem comes when I try to create the form and display custom error messages. How can I go about doing this?
Thanks
I am trying to check whether the string starts and ends with the same word. egearth.
s=raw_input();
m=re.search(r"^(earth).*(earth)$",s)
if m is not None:
print "found"
my problem is when the string consists only of one word eg: earth
At present I have hard coded this case by
if m is not None or s=='earth':
print "found"
Is there any other way to do this?
EDIT:
words in a string are separated by spaces. looking for a regex solution
some examples:
"earth is earth" ,"earth", -- valid
"earthearth", "eartheeearth", "earth earth mars" -- invalid
My code is:
print os.urandom(64)
which outputs:
> "D:\Python25\pythonw.exe" "D:\zjm_code\a.py"
\xd0\xc8=<\xdbD'
\xdf\xf0\xb3>\xfc\xf2\x99\x93
=S\xb2\xcd'\xdbD\x8d\xd0\\xbc{&YkD[\xdd\x8b\xbd\x82\x9e\xad\xd5\x90\x90\xdcD9\xbf9.\xeb\x9b>\xef#n\x84
which isn't readable, so I tried this:
print os.urandom(64).decode("utf-8")
but then I get:
> "D:\Python25\pythonw.exe" "D:\zjm_code\a.py"
Traceback (most recent call last):
File "D:\zjm_code\a.py", line 17, in <module>
print os.urandom(64).decode("utf-8")
File "D:\Python25\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 0-3: invalid data
What should I do to get human-readable output?
I got an access_token using facebook Graph API. https://graph.facebook.com/me?access_token=...
I want infinite session key is there any method to get infinite session key?.
I have a long string and a set of <end-index, string> list like the following:
long_sentence = "This is a long long long long sentence"
indices = [[6, "is"], [8, "is a"], [18, "long"], [23, "long"]]
An element 6, "is" indicates that 6 is the end index of the word "is" in the string. I want to get the following string in the end:
>> print long_sentence
This .... long ......... long sentence"
I tried an approach like this:
temp = long_sentence
for i in indices:
temp = temp[:int(i[0]) - len(i[1])] + '.'*(len(i[1])+1) + temp[i[0]+1:]
While this seems to be working, it is taking exceptionally long time (more than 6 hours on 5000 strings inside a 300 MB file). Is there a way to speed this up?
I've been trying to create a tabbed interface using Django. The current effort (which works fine) is having each template have the header hard-coded in, with the selected tab given the "selected" CSS attribute. Of course, this is a massive violation of DRY and I'm looking to remedy it.
My current idea is adding a jQuery script to the page that looks at all the tabs and sets one to "selected" if it's text matches the beginning of the title for the page. Is there a better way to do this without using JavaScript and just pure CSS?
I want to have some place where I can watch all the pendings tasks.
I'm not talking about the registered functions/classes as tasks, but the actual scheduled jobs for which I could display: name, task_id, eta, worker, etc.
Using Celery 2.0.2 and djcelery, I found `inspect' in the documentation. I tried:
from celery.task.control import inspect
def get_scheduled_tasks(nodes=None):
if nodes:
i = inspect(nodes)
else:
i = inspect()
scheduled_tasks = []
dump = i.scheduled()
if dump:
for worker, tasks in dump:
for task in tasks:
scheduled_task = {}
scheduled_task.update(task["request"])
del task["request"]
scheduled_task.update(task)
scheduled_task["worker"] = worker
scheduled_tasks.append(scheduled_task)
return scheduled_tasks
But it hangs forever on dump = i.scheduled().
Strange, because otherwise everything works.
Using Ubuntu 10.04, django 1.0 and virtualenv.
Hello, is it any way to read path to current page? For example, I am at www.example.com/foo/bar/ - and I want to read '/foo/bar/'. But, all have to be done in template file without modyficating views. I have to many view files to edit each one.
Sorry for my english, hope everyone understand. Cheers.
I'm trying to develop an app using Django 1.1 on Webfaction. I'd like to get the IP address of the incoming request, but when I use request.META['REMOTE_ADDR'] it returns 127.0.0.1. There seems to be a number of different ways of getting the address, such as using
HTTP_X_FORWARDED_FOR or plugging in some middleware called SetRemoteAddrFromForwardedFor. Just wondering what the best approach was?
I know this sounds kind of vague, but please let me explain-
I'm starting work on a brand new project, it will have two main components: "ACME PRODUCT" (think Gmail, Meebo, etc), and "THE SITE" (help, information, marketing stuff, promotional landing pages, etc lots of marketing-induced cruft).
So basically the url /acme/* will load stuff in the uber cool ajaxy application, and every other URI will load stuff in the other site.
Problem: "THE SITE" component is out of my hands, and will be handled by a consultants team that will work closely with marketing, And I and my team will work solely on the ACME PRODUCT.
Question: How to set up the django project in such a way that we can have:
Seperate releases. (They can push new marketing pages and functionality without having to worry about the state of our code. Maybe even separate Subversion "projects")
Minimize impact (on our product) of whatever flying-unicorns-hocus-pocus the other team codes into the site.
Still allow some code reusal.
My main concern is that the ACME product needs to be rock solid, and therefore needs to be somewhat isolated of whatever mistakes/code bloopers the consultants make in their marketing side of the site.
How have you handled this? Any ideas?
Thanks!
In my test, I try to verify if certain text exists (after an action) using find_element_by_xpath. If I use the right expression and my test pass, the routine ends correctly in no time.
However if I try a wrong text (meaning that the test will fail) it hangs forever and I have to kill the script otherwise it does not end.
Here is my test (the expression Thx user, client or password you entered is incorrect does not exist in the system, no matter what the user does):
# -*- coding: utf-8 -*-
import gettext
import unittest
from selenium import webdriver
class TestWrongLogin(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get("http://10.23.1.104:8888/")
# let's check the language
try:
self.lang = self.driver.execute_script("return navigator.language;")
self.lang = self.lang("-")[0]
except:
self.lang = "en"
language = gettext.translation('app', '/app/locale', [self.lang],
fallback=True)
language.install()
self._ = gettext.gettext
def tearDown(self):
self.driver.quit()
def test_wrong_client(self):
# test wrong client
inputElement = self.driver.find_element_by_name("login")
inputElement.send_keys("root")
inputElement = self.driver.find_element_by_name("client")
inputElement.send_keys("Unleash")
inputElement = self.driver.find_element_by_name("password")
inputElement.send_keys("qwerty")
self.driver.find_element_by_name("form.submitted").click()
# wait for the db answer
self.driver.implicitly_wait(10)
ret = self.driver.find_element_by_xpath(
"//*[contains(.,'{0}')]".\
format(self._(u"Thx user, client or password you entered is incorrect")))
self.assertTrue(isinstance(ret, webdriver.remote.webelement.WebElement))
if __name__ == '__main__':
unittest.main()
Why does it do that and how can I prevent it?
Does map() iterate through the list like "for" would? Is there a value in using map vs for?
If so, right now my code looks like this:
for item in items:
item.my_func()
If it makes sense, I would like to make it map(). Is that possible? What is an example like?
Hi lads,
After obtaining the urls for various blogspots, tumblr and wordpress pages, I faced some problems processing the html pages. The thing is, i wish to distinguish between the content,title and date for each blog post. I might be able to get the date through regex, but there are so many custom scripts people are using now that the html classes and structure is so different.
Does anyone has a solution that may help?
Looking to have a database query set all the instance variables in a class:
Example:
def populate(self, if):
#Perform mysql query
self._name = row['name']
self._email = row['email']
...
What's the fastest way to do this? Or is this not recommended (with a better approach)?
Thanks.
I have a model called Movie, which has a ManyToManyField called director to a model called Person, and I'm trying to create a form with ModelChoiceField like so:
class MovieSearchForm(forms.Form):
producer = forms.ModelChoiceField(label='Produced by',
queryset=movies.models.Person.producer_set,
required=False)
but this seems to be failing to compile (I'm getting a ViewDoesNotExist exception for the view that uses the form, but it goes away if I just replace the queryset with all the person objects), I'm guessing because '.producer_set' is being evaluated too 'early'. How can I get this work?
here are the relevant parts of the movie/person classes:
class Person(models.Model):
name = models.CharField(max_length=100)
class Movie(models.Model):
...
producer = models.ForeignKey(Person, related_name="producers")
director = models.ForeignKey(Person, related_name="directors")
What I'm trying to do is get ever Person who is used in the producer field of some Movie.
Ok, here is the question.
Imagine I have a ModelForm which have only two fields. like this one:
class ColorForm(forms.Form):
color_by_name = forms.CharField()
color = forms.IntegerField(widget = forms.Select(choices=COLOR_CHOICES))
So a user can either input a color name, a choose it from a list. Color is required, but that doesn't mean, that user should enter it manually. There do I put validation, so that my code checks if user selected color in dropdownlist and if not then he should write it manually?
I want to do something like this. The _print_attr function is designed to be called lazily, so I don't want to evaluate it in the init and set the value to attr. I would like to make attr a property that computes _print_attr only when accessed:
class Base(object):
def __init__(self):
for attr in self._edl_uniform_attrs:
setattr(self, attr, property(lambda self: self._print_attr(attr)))
def _print_attr(self, attr):
print attr
class Child(Base):
_edl_uniform_attrs = ['foo', 'bar']
me = Child()
me.foo
me.bar
#output:
#"foo"
#"bar"
Suppose I have a numpy array x = [5, 2, 3, 1, 4, 5], y = ['f', 'o', 'o', 'b', 'a', 'r']. I want to select the elements in y corresponding to elements in x that are greater than 1 and less than 5.
I tried
x = array([5, 2, 3, 1, 4, 5])
y = array(['f','o','o','b','a','r'])
output = y[x > 1 & x < 5] # desired output is ['o','o','b','a']
but this doesn't work. How would I do this?