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.

learn more… | top users | synonyms (3) | python jobs

0
votes
1answer
15 views

Is it possible to make Python interpret a script line by line and generate output as if from an interactive shell?

Considering the following interactive shell session. Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. ...
0
votes
1answer
8 views

Python Threaded Timer Returning Random Errors

I have a python thread that runs every 20 seconds. The code is: import threading def work(): Try: #code here except (SystemExit, KeyboardInterrupt): raise except ...
-2
votes
1answer
22 views

why second for loop overwrites the first in python

I wanted to add the first seven lines of the file abc using a seperate forloop with j and the rest of the subsequent lines as the forloop with i. However the following script just gives me the 64 ...
1
vote
1answer
10 views

Python csv writerows reformatting datetime to include seconds

Using Python, I have a datetime object in a list. The datetime format I want and have during program execution is (%Y/%m/%d %H:%M). Then, I use csv.writer and writerows (on a list of list) to save a ...
2
votes
3answers
23 views

String Mirror Function

I wanted to write a function that mirrors a string without using any built in functions and only using a loop. For example, wordMirror("stackexchange") returns 'stackexchangeegnahcxekcats'. I wrote ...
1
vote
1answer
8 views

Execute statements on multiple cursors (like ST's MiniPy)

In Sublime Text I used small and handy MiniPy plugin. It evaluates each expression in multi-cursor selection and replaces the selection with the result. For example, I have selected these lines in ...
0
votes
0answers
5 views

Create Webpages with Python (CGI/WebFrameWorks/Webservers/Webservices/ContentManagementSystems)?

I want to create a website, I am not from software background but I understand that I could write a simple CGI script in python. I created a simple CGI script and got it running. Problem is, I do not ...
0
votes
2answers
10 views

pandas - Joining CSV time series into a single dataframe

I'm trying to get 4 CSV files into one dataframe. I've looked around on the web for examples and tried a few but they all give errors. Finally I think I'm onto something, but it gives unexpected ...
-4
votes
0answers
19 views

Simple Program to Open a Batch File Remotely?

I need to run a simple script on my friend's computer unsuspectingly (for personal reasons). It would be nice if I could do it from a mobile device, but from another computer is also fine. I know ...
0
votes
0answers
14 views

delete subgraph from graph [igraph-python]

Suppose I have a graph g and a sub-graph h of g. What is the best way of removing h from g, to get g - h (remove all nodes and edges in h from g)?
2
votes
2answers
26 views

Are python imports guaranteed to be in sequence order? Is relying on this a good idea?

If I have the following Python code: import module1 import module2 Does Python guarantee that module1 is loaded before module2, and that they are not, for example, loaded in parallel? This works ...
0
votes
2answers
23 views

Add a restriction to a regex expression

Out of hundreds of thousands of words, two examples -- JANE_FONDA_AM_PM_YOGA_FOR_BEGINNERS JANE_FONDA_EN The output I need for this is: JANE_FONDA_AM_PM_YOGA_FOR_BEGINNERS JANE_FONDA The regex I ...
1
vote
1answer
15 views

Python asyncio buffer and process data

I'm having trouble with some CPU-intensive tasks within an asyncio event loop. The troubles I have arise when dealing with maintaining a buffer of incoming data and building packets from it. I've ...
0
votes
1answer
16 views

Django dealing with bootstrap form

I have this form: <form class="form-signin" role="form" method="POST" action="{% url 'django.contrib.auth.views.login' %}"> {% csrf_token %} <input type="text" ...
0
votes
0answers
5 views

Celery task calling another task

I have two files. One is the main file of my programm and it has all celery tasks that have to be done: chord( tasks.task_01.subtask(task_id='task_01'), ...
0
votes
2answers
17 views

How to check for empty cells in csv before converting to int (Python script)?

I am new to stackoverflow and python so please forgive me if this question lacks detail I want to import data from a csv file to a table in Postgres. However, I'm not sure how to check for null ...
0
votes
0answers
16 views

How to move a turtle stamp in python

I'm doing a minigame on turtles in python. The objective is using stamps of turtles in different colors, spawn them in a line, and make them race. But I don't know how to move the stamp. My ...
0
votes
0answers
14 views

Avoid duplication while using models.py in Flask application

I'm not sure if this is a dumb question. But, I have this independent project that I am working on. It has a font end and a back end that I'm working on that need to use the same models.py file ( for ...
0
votes
1answer
11 views

How to scrape table with different xpath on the same level with Scrapy?

I got this HTML (simplified): <table> <div class="button-left" style="margin-bottom: 4px">04.09.2013</div> <table width="100%" class="record generic schedule margin-4" ...
0
votes
2answers
28 views

In Python, how do I get a variable via a string representation of the name of the variable?

I'm using Python 2.7. Take, for example, the following code: class Apple: def __init__(self, n): self.n = n def printVariable(self, s): # print variable named s if ...
1
vote
1answer
29 views

Do Python modules need shebangs or encoding directives?

our application is composed of several modules grouped in two packages, and one script. I am not sure, and don't manage to google my way through to knowing if the modules need a coding directive in ...
0
votes
1answer
4 views

Can I double-click a tkinter Listbox option to invoke function in Python?

I have a Listbox with an associated "Select" button. I want my GUI such that a double-click on any Listbox value invokes this button's command. My attempt (below) works when an option is selected and ...
1
vote
1answer
20 views

How to reduce multiple queries to only one query?

How do I build a single query with djangos ORM to get the best score, lower than 1.000, for every player? I'm using django 1.7 rc2 and python 3.4. models.py: from django.db import models class ...
0
votes
0answers
15 views

Notepad++ how to get python-like code folding in a user-defined language

I can't seem to solve my current problem with Notepad++. I want notepad++ to color all the code in a line that occurs after a $ The problem is when I make my own user-defined language to do this, I ...
-4
votes
1answer
21 views

How to look for next key in python dictionary and delete that key when the dictionary is randomly ordered

I want to search the next key depending on the current key in a randomly ordered python dictionary. Then if the current value (e.g d[k]) is less then the next value (e.g d[k+1) then the current ...
-3
votes
2answers
23 views

how to print in python a simple string [duplicate]

I have centos 6.5 If I type python, I get: Python 3.3.2 (default, Oct 30 2013, 08:01:17) [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux I created a file 1.py with: print "Goodbye, World!" I ...
0
votes
4answers
45 views

RuntimeWarning: Divide by Zero error: How to avoid? PYTHON, NUMPY

I am running in to RuntimeWarning: Invalid value encountered in divide import numpy a = numpy.random.rand((1000000, 100)) b = numpy.random.rand((1,100)) dots = numpy.dot(b,a.T)/numpy.dot(b,b) ...
-1
votes
1answer
5 views

Binding MouseClick to widget of an instance

I have an instance of a ttkcalendar object, "cal". When I bind a button click to cal, the function called only executes if I click in the corners of the ttcalendar frame; when I click on the actual ...
1
vote
3answers
31 views

Regex - select string until ' / '

Hello! Im using Regex to parse HTML. (if you are reading this and doing it too, i really rocommend you use HTMLParser insted) i have a web page the looks like this: ...
0
votes
0answers
6 views

Oauth2 on Openshift with Django

I'm having issues using oauth2 on django python. The following error: I'm using import py3oauth2 as oauth consumer = oauth.Consumer(consumer_key, consumer_secret) giving the error 'module' ...
0
votes
0answers
5 views

Add color to nose2 output

This is such a simple question, but I can't find it anywhere... how do I add color to the output of running tests with nose2? For example, I would like failures to show up as red.
0
votes
3answers
26 views

How to pass an augment in super() correctly

My class takes an augment called resource: > AClass(resource="123") Class: class AClass(Base): def __init__(self, resource): super(AClass, self).__init__(self) Which will ...
0
votes
2answers
26 views

python2.7: passing kwargs in instance methods

If I want to pass an indentical list of args from one function to another, I can use the locals function. However this falls over if I'm in an instance method, as self cannot be passed as kwarg. I can ...
0
votes
0answers
6 views

sqlalchemy mapper difference between mapper and Base

i am much confused on how to configure mapper on sqlalchemy!! class Parent(object): def __init__(self, _a): self.a = _a engine = create_engine() metadata = Metadata() parent= ...
-1
votes
2answers
29 views

Atomic copy an object attributes

I have an object which keeps changing with time independent of my program. So for example, my data keeps getting updated after some random but small interval. Now I wish to copy certain attributes ...
1
vote
1answer
17 views

Calculate difference between two datetimes if both present in pandas DataFrame

I currently have various time columns (DateTime format) in a pandas DataFrame, as shown below: Entry Time Exit Time 00:30:59.555 06:30:59.555 00:56:43.200 10:30:30.500 ...
0
votes
1answer
6 views

Parsing arguments using argparse and mpi4py

I want to run a Python script in several parallel processes under MPI, and I need to pass command-line arguments. I'm using the argparse module in Python, but it's a little messy sometimes. If I don't ...
0
votes
0answers
15 views

Flask is not getting any POST data from a request

Within our server we've got this piece a code calling a function inside my APP like this: data = urllib.urlencode( dict(api_key="a-key-goes-here") ) headers = { "User-Agent" : "Mozilla/5.0 ...
3
votes
5answers
39 views

How to format text with style

A code below: info={'Resolution':'640x360', 'DisplayResolution': '640x360', 'Display Channels':'R,G,B,A'} for key in info: print (key + str(info[key].rjust(45,'.'))) produces a following ...
0
votes
0answers
4 views

Python: Whoosh seems to return incorrect results

This code is straight from Whoosh's quickstart docs: import os.path from whoosh.index import create_in from whoosh.fields import Schema, STORED, ID, KEYWORD, TEXT from whoosh.index import open_dir ...
0
votes
0answers
6 views

Return Pymongo result in Python Bottle

I try to implement a 'kind-of' personal API for my own usage. I work in Python Bottle with Pymongo. Here is my code: @bottle.get('/getscore') def getscore(): mode = ...
1
vote
0answers
9 views

python SWIG object compare

I have two lists of SWIG objects: a and b. I need to do set or comparison operations to find items in a that are not in b. (I have other operations to do also, but this is a good starting example). ...
0
votes
1answer
26 views

Python “No such file or directory” error

Today I changed my system settings to include C:\python27 as a path variable. Now I am getting the error "IOERROR: [Errno 2} No such file or directory: 'Skusnew1.cvs'" when I run this code: import ...
0
votes
1answer
15 views

Python easygui can't select file

Here's my code: import easygui f = easygui.fileopenbox() print f Seems simple, but when I run it, I can't select any of the files, see figure in link. Sorry if this is dumb, but I am at my wit's ...
0
votes
0answers
13 views

2D Interpolation with periodic boundary conditions

I'm running a simulation on a 2D space with periodic boundary conditions. A continuous function is represented by its values on a grid. I need to be able to evaluate the function and its gradient at ...
0
votes
0answers
4 views

Django haystack related name search

so i have the following models: class Article(models.Model, PublicationMixin): publication = models.ForeignKey('Publication', related_name="articles") ... class Publication(models.Model, ...
0
votes
1answer
8 views

Regex that works with BaseSpider causes error with CrawlSpider

I am using Python.org version 2.7 64 bit on Windows Vista 64 bit. I have the following code containing a regex on a Javascript item called Datastore.prime that i know definitely existed on a static ...
1
vote
1answer
19 views

send multiple files in a post request

I am trying to send multiple files in a post request. Following is the code I use. orig_src = "./orig_src/" url = "http://"+server+":"+port+"/my_service" files = [] for root, dirs, files in ...
0
votes
0answers
13 views

Are django signals the only way to log method calls like create, delete, get, post etc in django models and mixins?

For purposes of debugging and book keeping, I am trying to put in place python logging for django default model methods like create and get/post methods in django mixins. I do not want to specially ...
1
vote
1answer
14 views

check mimetype of stored data using Python

Problem: I extracted the content block from a WARC file. I am writing a filter to check the mimetype of this content block before saving the content into a file. Particularly, I am only interested in ...