Interesting Tags
   11 tags on

1 answer

Couldn't understand main drawback of Decorator Pattern

I am learning Decorator Pattern. It is very powerful pattern, and quite useful. The objective of the pattern is simple, adding(extending) behaviour to objects at runtime without recompiling source ...

4 answers

Python opened one file and is reading its data, why python still can read its data even I delete this file?

My python program is to read data from a txt file and insert data into my postgre database. The program has already started and keeps running. Then I accidently deleted the file on the disk, but the ...

1 answer

How can I do to have the django-guardian reflecting on my apps in the admin panel?

I can see no changes with django-guardian, even using the GuardedModelAdmin. I would like that the user could see and edit only the records allowed (not just owned, but allowed) for him. But even ...

0 answers

tweepy importing error while calling through AJAX

I am trying to retrieve tweets of searched user. It throws Internal Server Error - 500 when I add "import tweepy" in python script. If I comment "import tweepy" then it runs normally. But I need ...

0 answers

Error on run python script

My friend has been writed a python script. When he run that at ubuntu, it works very well. But when I run it at fedora 22, it doesn't work! It shows the: "message.txt not found". My script: # -*- ...

1 answer

How to build Flask-admin model view depending on user

How to control permissions on flask-admin view? For example, current_user.has_role() not in ('administrator', 'editor') -> MyModelView.can_create = False example of Auth flask-admin my code If ...

1 answer

Python3: eval() with custom dict not evaluating numbers

I'm working on an application which allows a user to define a math function by entering a string (like you see on wolfram alpha) and plotting the function over some pre-defined range. I use the eval() ...

5 answers

Algo to find duplicates in a very large array

During one of technical interview got this question. I know way to solve this problem using (in java) HashSet. But i could not understand when interviewer forced on the word "a very large array let's ...

5 answers | 7 mins ago by Sam on Stack Overflow
1 answer

How to compare 2 columns of a table through dynamic querying

Have a requirement in dynamic querying where i would like to compare 2 columns of a table say "column_a" and "column_b" (all columns are strings). The actual columns to compare are decided at ...

2 answers

My python play again feature does not work

def playAgain(): while True: try: replay = input("Do you want to play again? ").lower() #Asking user to play again except ValueError: print("Sorry, Invalid ...

2 answers | 16 mins ago by user2278805 on Stack Overflow
0 answers

Django rest framework is taking too slow to return nested serialized data

We are having four models which are related, While returning queryset serializing the data is too slow( Below are our models and serializer. Why django nested serializer is taking ...

3 answers

What is the right way to debug in iPython notebook?

As I know, %debug magic can do debug within one cell. However, I have function calls across multiple cells. For example, In[1]: def fun1(a) def fun2(b) # I want to set a ...

1 answer

Using Mann-Whitney U in Python: TypeError: 'list' object is not callable

I'm doing pairwise tests for my data using using Mann-Whitney U. for x in myData: for y in myData: d_value, p_value = ks_2samp(x,y) #two-tailed p-value u_value, p_value1 = ...

1 answers | 18 mins ago by meiyin on Stack Overflow
1 answer

i(1054, “Unknown column 'rango_category.slug' in 'field list'”) Django

I'm trying to create a slug field in a Django project. However I keep getting this error when trying to access the categories on django admin, I'm new to Django and just trying to keep up with a ...

1 answers | 21 mins ago by Juanvulcano on Stack Overflow
3 answers

Basic explanation of python functions

I have a basic question below to help try get my head around functions in python (following the LPTHW tutorials in prep for uni). Could someone explain the syntax below, and whether I am correct with ...

3 answers | 23 mins ago by NZSteve on Stack Overflow
4 answers

Understanding the Python 'with' statement

I'm trying to understand if there is there a difference between these, and what that difference might be. Option One: file_obj = open('test.txt', 'r') with file_obj as in_file: print ...

4 answers | 31 mins ago by MikeTheReader on Stack Overflow
1 answer

Can't get my custom odoo module to appear

I'm very new to odoo and python and was wondering if I could get some help getting my module to load. I've been following the odoo 8 documentation very closely and can't get anything to appear in the ...

1 answers | 34 mins ago by eli93 on Stack Overflow
0 answers

Serializing a nested namedtuple into JSON with Python >= 2.7

I have a problem similar to CalvinKrishy's problem Samplebias's solution is not working with the data I have. I am using Python 2.7. Here's the data: Namedtuple >>> a_t = ...

2 answers

How to make Django Queryset that selects records with max value within a group

Here is my Django class: class MyClass(models.Model): my_integer = models.IntegerField() created_ts = models.DateTimeField(default=datetime.utcnow, editable=False) I would like to retrieve ...

0 answers

python 3.4, tkinter, how do you use a video from youtube?

Is there any way to use a video on a tkinter Canvas() from youtube or from your documents? If not, can you do it without tkinter? import os import sys import tkinter import gobject import gst def ...

0 answers

How do I simply transfer and download a file from an FTP server with Python?

I've noticed that the FTP library doesn't seem to have a method or function of straight up downloading a file from an FTP server. The only function I've come across for downloading a file is ...

0 answers

django-multilingual and switching between languages on template side

I have changed my language on GeoNode. I translated all of the word on that. but actually it doesn't change on the web. I have done the correct way for changing such as bellow: copy these files ...

1 answer

split randomly a list of array in Python

i have a list of array in Python import numpy as np mylist = [np.random.randint(0, i, int(10)) for i in (10,100,3)] [array([5, 5, 7, 2, 0, 5, 7, 8, 6, 9]), array([42, 70, 30, 62, 44, 8, 40, 68, 46, ...

0 answers

SyntaxError: invalid syntax in python 2.7.5

def main(host, port, banner): for above line I am getting error as "^ SyntaxError: invalid syntax" in python 2.7.5

1 answer

Jupyter Notebook failed to run %qtconsole

When I run %qtconsole on jupyter notebook (I ran jupyter notebook using Windows power-shell0 Error gives c:\users\mohit\appdata\local\enthought\canopy\user\lib\site- ...

1 answers | 58 mins ago by Mohit Khurana on Stack Overflow
2 answers

python Named tuple to dictionary

I have a named tuple class in python class Town(collections.namedtuple('Town', [ 'name', 'population', 'coordinates', 'population', 'capital', 'state_bird'])): # ...

3 answers

Learning Python coming from PHP

My dynamic language experience is solely PHP. I want to learn Python now to broaden my career opportunities and just because I like programming. :) When learning Java, I used a site (lost the ...

3 answers | 1 hour ago by Amy B on Stack Overflow
2 answers

How can I use break and continue in Django templates?

I want to put break and continue in my code, but it doesn't work in Django template. How can I use continue and break using Django template for loop. Here is an example: {% for i in i_range %} {% for ...

2 answers | 1 hour ago by GoldenBird on Stack Overflow
0 answers

Advanced numpy array multiplication

I have a two dimensional numpy array which is (in the problem I am solving) effectively a list of vectors: [[a,b,c] [d,e,f] ..... [..,..,..]] I then have three, three dimensional numpy arrays. ...

0 answers

Shell-redirect logger output to a file

I want to write python script's output to a file. The script: import logging logging.basicConfig(level=logging.DEBUG)"Bla bla bla") I run it in shell $ python >> ...

15 30 50 per page
1 2 3