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 the following DataFrame containing song names, their peak chart positions and the number of weeks they spent at position no 1:
Song Peak Weeks
76 Paperback Writer 1 16
117 Lady Madonna 1 9
118 Hey Jude 1 27
22 Can't Buy Me Love 1 17
29 A Hard Day's Night 1 14
48 Ticket To Ride 1 14
56 Help! 1 17
109 All You Need Is Love 1 16
173 The Ballad Of John And Yoko 1 13
85 Eleanor Rigby 1 14
87 Yellow Submarine 1 14
20 I Want To Hold Your Hand 1 24
45 I Feel Fine 1 15
60 Day Tripper 1 12
61 We Can Work It Out 1 12
10 She Loves You 1 36
155 Get Back 1 6
8 From Me To You 1 7
115 Hello Goodbye 1 7
2 Please Please Me 2 20
92 Strawberry Fields Forever 2 12
93 Penny Lane 2 13
107 Magical Mystery Tour 2 16
176 Let It Be 2 14
0 Love Me Do 4 26
157 Something 4 9
166 Come Together 4 10
58 Yesterday 8 21
135 Back In The U.S.S.R. 19 3
164 Here Comes The Sun 58 19
96 Sgt. Pepper's Lonely Hearts Club Band 63 12
105 With A Little Help From My Friends 63 7
I'd like to rank these songs in order of popularity, so I'd like to sort them according to the following criteria: songs that reached the highest position come first, but if there is a tie, the songs that remained in the charts for the longest come first.
I can't seem to figure out how to do this in Pandas.
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.
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
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
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?
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 have an ec2 instance running Ubuntu 14.04 and I want to host two sites from it. On my first site I have two settings file, production_settings.py and settings.py (for local development). I import the local settings into the production settings and override any settings with the production settings file.
Since my production settings file is not the default settings.py name, I have to create an environment variable
DJANGO_SETTINGS_MODULE='site1.production_settings'
However because of this whenever I try to start my second site it says
No module named site1.production_settings
I am assuming that this is due to me setting the environment variable. Another problem is that I won't be able to use different settings file for different sites.
How do I start use two different settings file for two different websites?
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?
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 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?
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
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 have the following code in the urls.py in mysite project.
/mysite/urls.py
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^gallery/$', include('mysite.gallery.urls')),
)
This results in a 404 page when I try to access a url set in gallery/urls.py.
/mysite/gallery/urls.py
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^gallery/browse/$', 'mysite.gallery.views.browse'),
(r'^gallery/photo/$', 'mysite.gallery.views.photo'),
)
404 error
Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:
^gallery/$
The current URL, gallery/browse/, didn't match any of these.
Also, the site is hosted on a media temple (dv) server and using mod_wsgi
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.
import math
def gen_caller(a):
for z in a:
x,y=z
if x==1:
x=2
if y>=x and y-x<=100000:
for i in range(x,y+1):
flag=0
for j in range(2,(long(math.sqrt(i))+1)):
if(i%j==0):
flag=1
break
if flag==0:
print i
print ""
n=(int(raw_input()))
gen_caller([[(long(raw_input())) for j in range(0,2)] for i in range(0,n) if n<=10])
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"
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!
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?
the docs says:
post_save
django.db.models.signals.post_save
created
A boolean; True if a -new- record was create.
and I have this:
from django.db.models.signals import post_save
def handle_new_user(sender, instance, created, **kwargs):
print "--------> save() "+str(created)
post_save.connect(handle_new_user, sender=User)
when I do in shell:
u = User(username="cat")
u.save()
>>> --------> save() True
u.username = "dog"
u.save()
>>> --------> save() True
I expect a -------- save() False when I save() the second time because is an update? not?
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?
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?