Tagged Questions
Python is a dynamic and strongly typed programming language that is designed to emphasize usability. Two similar but incompatible versions of Python are in widespread use (2 and 3). Please consider mentioning the version and implementation that you are using when asking a question about Python.
0
votes
0answers
10 views
Sort list by key name
I have the following data structure (coming from a piece of code I can't modify):
{
'key2':[{'name':'Oliver','value':1}, {'name':'Rambo','value':2}],
'key1':[{'name':'Robert','value':4}, ...
0
votes
0answers
2 views
Jython error in eclipse ImportError: No module named java.lang.InterruptedException :
I am using Jython 2.5.3 version to integrate my python scripts with java.
But while running the script I am getting an error while importing any java class. For example:
ImportError: No module named ...
1
vote
0answers
14 views
Does it exist a pattern for one use only objects?
Suppose you are representing some task to do using objects of a class Task2Do. These objects are runnable, that is, they have a method which perform a task doTask.
On the other hand, you have a queue ...
0
votes
0answers
2 views
py2exe runtime error R6034
Running an py2exe generated exe-file gives me the R6034 runtime error. As described here one need to add something to a manifest_template, but what do i have to put in there? I've VS 11 installed.
...
0
votes
1answer
9 views
Python: List of integers to datetime?
I have a list [14,9,11,2,1,21] and I want to transform it in datetime object (e.g. 2014/09/11 02:01:21)
>>> from datetime import datetime
>>> x = [14,9,11,2,1,21]
>>> ...
0
votes
0answers
6 views
Why is my Python 3.1.2 code showing NZEC?
arr=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29 ... (And primes upto 50,000) (I've removed them here as of now)]
length=len(arr)
T=int(input())
while(T>0):
m=0
display=[]
val=int(input())
...
0
votes
0answers
3 views
SQLAlchemy - 'list' object has no attribute 'ref'
I can't figure out why SQLAlchemy keep showing me this error. In the subquery I am selecting a list of refs (ids) and using it in the second query as a filter. any help would be appreciated:
def ...
0
votes
0answers
4 views
web.py invalid literal for int() with base 10
I need to convert a string type, from and get call on web.py, into an integer, but I'm getting this error:
invalid literal for int() with base 10
Here is my code:
import web
render = ...
0
votes
0answers
10 views
Differences between time.monotonic() and time.perf_counter()
I'm trying to understand those functions: time.monotonic() and time.perf_counter().
I read the PEP 418, even though I didn't get much. However if I am not wrong, under linux the are exactly the same ...
0
votes
0answers
10 views
how to get the registration form?
please help to solve the problem. I use python3.4 and django1.6
trying to create a registration form. Here is a models.py:
from django.db import models
from django.contrib.auth.models import User, ...
0
votes
0answers
12 views
Kivy understanding
Okey guys Iam newbee with Kivy GUI framework and I have a few questions related to kvlang:
1.How can I add my custom widget class to root in kv file?(example)
PS: I use here clear_widgets here then I ...
0
votes
0answers
7 views
GAE Python application (User Services) error on Android Chrome with multiple google account associated
My following application works perfectly on desktop (all browsers including Chrome). On android devices, this works perfectly as well, on all browsers except Chrome.
class ...
0
votes
0answers
17 views
Is my model overfitting? Values seem too good to be true
I'm using this code to generate test and train datasets, fit a classifier to it, and return several metrics. However, I've been getting extremely good scores. Am I overfitting, or just being ...
0
votes
0answers
12 views
Issue with pip and virtualenv when specifying python version
I'm using virtualenv (1.11.6) to manage my python projects, I created a new one but I noticed that it uses an old python version (2.7.2 instead of 2.7.8), so I recreated a virtualenv by using the -p ...
0
votes
1answer
8 views
Can I install a python package for all users (with setuptools in develop mode)
I found out that packages that I installed with setuptools are not accessible by other users. I understand that this behavior is logical, especially because I installed them in develop mode. However I ...
1
vote
2answers
16 views
ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
I use pickle to dump a file on python 3, and I use pickle to load the file on python 2, the ValueError appears.
So, python 2 pickle can not load the file dumped by python 3 pickle?
If I want it? ...
0
votes
0answers
6 views
Failed to select folder even though it is listed from the LIST command
Here's the (trimmed) output of the LIST command:
[... ((u'\\HasNoChildren', u'\\Inbox'), u'/', u'Входящие'),
((u'\\Noselect', u'\\HasChildren'), u'/', u'[Gmail]'),
((u'\\HasNoChildren', ...
0
votes
0answers
6 views
Flask application deployed to Heroku returns Application Error
I'm having trouble with heroku not successfully running my app. I have 3 key files:
A python file with the core engine.
A python file that calls the first python file and runs Flask to ...
0
votes
1answer
11 views
Realize padding and rounding up values via awk out of a python script with subprocess
I use this command string to get the percentage value of the CPU utilization.
top -d 0.5 -b -n2 | grep 'Cpu(s)'|tail -n 1 | awk '{result = $2 + $4} END {printf "%3.0f\n", result'}
In the shell it ...
0
votes
0answers
13 views
DebuggerStepThrough in python?
Is there a way to mark a certain method in python so that the debugger won't step into it while debugging ?
(I'm using PyCharm, so if there's something specific that the IDE can help me with, that ...
0
votes
0answers
29 views
How to list the contents of a function?
A function I have defined has scrolled off hundreds of lines off the console screen. How do I recall it to display its contents?
I want to achieve like in PowerShell: get-content ...
0
votes
4answers
39 views
Unwanted space in Python
name = raw_input ("What's your name? ")
print "Hello",name, "!"
It returns the following:
What's your name? John
Hello John !
How do I make it so that the space between John and ! doesn't appear?
...
-2
votes
0answers
22 views
I have a error TypeError: 'str' object does not support item assignment
I have the following error
File "eje", line 72, in bin_incrementa
binario[len(binario)-i-1]=0
TypeError: 'str' object does not support item assignment
the code is
#!/usr/bin/env python
# -*- ...
-4
votes
1answer
29 views
Python 3.3.2 - Why does my def function not work? [on hold]
global_var = 1
def my_vars():
print( 'Global Variable:' , local_var )
local_var = 2
print( 'Local variable:' , local_var )
global inner_var
inner_var = 3
my_vars()
print( ...
2
votes
1answer
29 views
Can you force os.path.isfile() to use case insensitivity when checking a file on a case-sensitive file system?
If I use os.path.isfile("foo.txt) to check a file named Foo.txt, the function returns True on case-insensitive file systems and Windows. However, it returns False on case-sensitive file systems. Is ...
0
votes
0answers
10 views
Change path of input file , comtypes
I wanted to convert a file called 'nored.doc' to 'modred.docx', and I could do it using the following code.
import sys
import os
import comtypes.client
os.getcwd()
in_file = ...
0
votes
1answer
8 views
Selenium Python: Call a click event by a class name even class name is seperated by “space”
I'm facing a problem when trying to execute an automatic script of python using package "selenium"
Problem: If class name is separated by "space" then it throws an error.
Following is the instruction
...
0
votes
2answers
43 views
Replacing string+number in a file using Python
I have a file in which I would like to find and replace the figure in an expression as follows
...
.param vthna=0.466
.param vthnb=0.466
...
For example, I would like to change the original ...
0
votes
1answer
76 views
Is there a cleaner way to do this loop?
Can any one help me come up with a solution that makes this loop simpler. The code runs fine but just seems too much for what it does.
font_sizes = map(int, re.findall(r'\\fs(\d+)', rtf)) # Get ...
0
votes
1answer
16 views
Input in terms of variables
I am making a simple function plotter in python using pygame. I want the user to be able to enter the function in terms of x and y through the console. For example:
math.sin(x) + math.sin(y) should be ...
-2
votes
2answers
30 views
Ping to a specific IP address using python
I want to write a python script that should check if a particular IP address is reachable or not. I'm new to python programming and have no idea how the code might look. Help out
0
votes
0answers
6 views
django-oraclepool not found exception
I need a sessionpool for django (and oracle database).
I found this https://pypi.python.org/pypi/django-oraclepool. But how do I use it?
I made a pip install and added the following lines to ...
0
votes
0answers
32 views
How to seperate login redirect urls in django
I have built a django app.Can someone help me in seperating the redirect URLs while logging in from facebook(django-social-auth) and a normal login form.
I have two types of users, one which I need to ...
0
votes
1answer
7 views
Create a search “engine” to get information from a Google DataStore in python
I'm looking for some information to create a search engine to search information from my DataStore.
I have build a datastore and I can seach information from it with queries (my datatstore store ...
0
votes
0answers
21 views
python, You must not use 8-bit bytestrings
I'm converting a SQL query in python into a pandas dataframe. Then I'm using pandas sql to make a left outer join between two pandas dataframe.
My code is:
import MySQLdb as mdb
from pandasql import ...
0
votes
0answers
11 views
Write more than one Dataframe values
I am new to python and i want to know that is there any way to write more than one DataFrame values with Different columns using python xlsxwriter. writing a single DataFrame works fine but what if i ...
0
votes
0answers
9 views
How to use threading in Scrapy/Twisted?
I need run some multi-thread\multiprocessing work (because I have some library which uses blocking call) in Scrapy, and after its completion put back Request to Scrapy engine.
I need something like ...
0
votes
1answer
36 views
How to decrease the size of a float-python
I am trying to create a readable file name generator given the number of bytes, but also doing it without if statements or loops:
def memory_size(n):
suffix = ['B','KB','MB','GB','TB']
...
-1
votes
0answers
16 views
Linux Serial Port in C rubbish characters after restarting pc
I have a host and a client PC on which I'm running a serial link.
The host is running C in CentOS, and the client is running Python script in Fedora.
The settings are :
Baudrate = 115200
parity = ...
-1
votes
1answer
20 views
Quesion when I use HttpResponseRedirect in Django
I'm writing a simple blog application, I used HttpResponseRedirect() to redirect to the blog detail after users commented like this
return HttpResponseRedirect(reverse('detail', args=(in_blog_id)))
...
0
votes
0answers
6 views
Is it possible to write all font files used in a python program into a string or list
I am using Py2exe to "exeify" my python scripts into windows executable program. So far I have been successful in binding all data including images, audio and txt files as data written into py files. ...
0
votes
1answer
12 views
Clipping Line shapefiles within the extent of Polygon shape
My question is an extension of Vertical lines in a polygon shapefile. Kindly refer to that question first.
What you shall see there is a method of generating vertical lines with respect to the ...
2
votes
2answers
45 views
Python: return a default value if function or expression fails
Does Python has a feature that allows one to evaluate a function or expression and if the evaluation fails (an exception is raised) return a default value.
Pseudo-code:
evaluator(function/expression, ...
0
votes
0answers
7 views
Mayavi2 standalone script with command line arguments
I am trying to parse command line argument to a MayaVi2 standalone script. However, the mayavi2.standalone() function eats command line arguments before me. For example:
#! /usr/bin/python
import ...
0
votes
2answers
20 views
django best approach for creating multiple type users
I want to create multiple users in django. I want to know which method will be the best..
class Teachers(models.Model):
user = models.ForeignKey(User)
is_teacher = ...
0
votes
0answers
18 views
Python - urllib2 How to open other url directed from one url
So say we needed to use authentication before we can actually access the web then:
import urllib2, base64
authenip = "10.203.10.12" #What ever the authenication ip is....
req = ...
0
votes
0answers
10 views
rebuilding scikit-learn under anaconda on OSX 10.9
I am using scikit-learn 0.15.2 installed on mac osx 10.9 using anaconda Python 2.7.8 |Anaconda 2.0.1.
I modified some code inside scikit-learn specifically the gradient_boosting.py. I tried to ...
1
vote
3answers
58 views
Python : Ensure string is exactly in A.B.C format .. ( two dots separating 3 strings )
The problem with this code is..
a = '1111.222.333'
b = a.split('.')
first = b[0]
second = b[1]
third = b[2]
is that.. if the string is missing pieces such as..
a = '222.333'
the ...
0
votes
1answer
18 views
Qt - Normal vertical scrollbar handle behavior in QTableView
I'm using a QTableView in Qt (PyQt4, actually). The vertical scrollbar acts very weird, different than how a QTableWidget scrollbar or any other scrollbar acts. I have a large table, with thousands of ...
0
votes
0answers
41 views
list output in template
I want to print list in templates...
@login_required
def upload_view(request):
template_var = {}
settings = Tracks.objects.filter(album__exact=None).values_list('file', flat=True)
for ...