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

-4
votes
0answers
7 views

How can I scrape data from a website and then store the data to a database using Python?

I want to scrape a website to fetch all the relevant information. I have tried Scrapy but the data is not present in the CSV ,XML,JSON files. I need to know how the data can be stored in a database ...
0
votes
1answer
4 views

Handling cookiejar from requests library python

I'm having a problem with retrieving cookies from a cookiejar. I'm trying to use the requests library, and I want to retrieve a specific cookie, but I don't know how to. Maybe one of you have more ...
0
votes
0answers
4 views

Accessing the Kth group in Pandas

Is this the only way to do it? It's quite verbose. k = 0 grouped = df.groupby('A') df.ix[grouped.groups[list(grouped.groups)[k]]] Also, wouldn't list(grouped.groups) return keys in a meaningless ...
0
votes
0answers
5 views

OpenShift returns server error when trying to access form entry

I am creating a web based application with python where the user enters a search query and data is returned. I used bottle to provide the web framework for this. Openshift is then used to post online. ...
0
votes
0answers
13 views

Redirect based on Mac Address

I need a script that will check a Mac Address list every 15 mins, if a new Mac is found on the network it will add this Mac to the list and send this new user to a defined web page until it click a ...
-1
votes
1answer
12 views

Webpage that displays the result of a function run every x seconds

I want a small web page, that once every x seconds, runs a function.(It will display the result of that function) import datetime from bottle import Bottle, run app = Bottle() @app.route('/') def ...
0
votes
0answers
11 views

Is python subprocess.Popen accept space in path?

I have a simple Python script: log("Running command: " + str(cmd)) process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, close_fds=close_fds) I'm ...
0
votes
0answers
3 views

Change Kivy button widget attribute by pressing button in another screen

In my app, I have a GameScreen that has a ClueButton1 widget with some text. Pressing that button takes the user to a ClueScreen (using kivy Screen Manager), that has 4 buttons, each being an answer ...
0
votes
1answer
7 views

Datastore App Engine quering ancestor python

Hello I'm new on Datastore and on Python and I have a basic question but it can help me to understand more the Google cloud. I have 4 entities and let's say I have a parent (match) with children : ...
-1
votes
1answer
17 views

python regex sub without order

I have following string "3 0ABC, mNone\n" and I want to remove m None and \n. The catch is that 'm', \n and None can be anywhere in the string in any order. I would appreciate any help. I can do ...
0
votes
2answers
22 views

using template format in python

I use this code to align the output template = "{0:20}{1:5}" print template.format("1","bread") 1 bread 2 cheese but what if I want the output to be like this 1 .... bread 2 .... ...
0
votes
1answer
12 views

how to create datetime object for a specific time in a timezone in django

I have a time that I want users to be reminded of when that time comes in their respective time zone: 7am. I have a timezone associated with each user. It looks like: customer1_timezone = ...
0
votes
0answers
8 views

Matplotlib ignoring timezone

The following plot import matplotlib f= plt.figure(figsize=(12,4)) ax = f.add_subplot(111) df.set_index('timestamp')['values'].plot(ax=ax) ...
1
vote
0answers
16 views

Sorting An Array - Where do comparisons and swaps take place?

Examine the given Python source code for insertion sort and selection sort. Run the code on some small examples to demonstrate that both correctly sort the given input. Instrument ...
-9
votes
2answers
28 views

Counting “bobs” Python

Can someone please guide me on how to solve this?! Thank you Question: Assume s is a string of lower case characters. Write a program that prints the number of times the string 'bob' occurs in s. ...
0
votes
0answers
13 views

Write Folder Contents to CSV with Regex

I am trying to use the Python script here for my own purposes. I'm no Python bloke, so hopefully someone can see what I have wrong. The below script doesn't error out. My CSV is created with no ...
1
vote
1answer
14 views

selenium and web2py from killer-web-development.com doesn't work

I am trying to follow the tutorial on http://killer-web-development.com/section/4/3 and I am running into the error message: ====================================================================== ...
0
votes
0answers
16 views

How can you turn an index array into a mask array in Numpy?

Is it possible to convert an array of indices to an array of ones and zeros, given the range? i.e. [2,3] -> [0, 0, 1, 1, 0], in range of 5 I'm trying to automate something like this: >>> ...
1
vote
1answer
9 views

XHR request URL says does not exist when attempting to parse it's content

Before I build a full solution to my problem using Scrapy I am posting a simplistic version of what I want to do: import requests url = ...
0
votes
2answers
24 views

concatenate and remove duplicate element from arrays

I compute an array of indices in each iteration of a loop and then I want to remove the duplicate elements and concatenate the computed array to the previous one. For example the first iteration ...
0
votes
1answer
11 views

NameError on Script & DB Insert

I am trying to use the Python script here for my own purposes. I'm no Python bloke, so hopefully someone can see what I have wrong. Is it an indent error? Traceback (most recent call last): File ...
0
votes
1answer
20 views

Accessing the variable from another function of the same class

from folder_exp import my_tcommands as t class Gravity(EarthG): def __init__(self): super(Gravity, self).__init__() def check(self): original = t.get_gravity() print ...
1
vote
0answers
8 views

Multivariate Normal changes variables in PyMC

I might be doing something wrong but I can't figure out what it is. I'm trying to reproduce some results from a real state dataset from Baton Rouge, LA. The original code is written in WinBUGS here. ...
0
votes
2answers
29 views

Iterate through unexpected layers of a nested dictionary

So my situation is as follows. I have a dictionary (shown below) of which I want to iterate through potentially large numbers of iterations, without having to manually define 'for i in ...
0
votes
2answers
36 views

Python is not writing to a file for some reason

Is there a reason why this is code is not writing to a file. Everything else works on this except for the writing part I know I need to close the file but I'm not sure how? import os import sys ...
0
votes
1answer
10 views

“Response object has no attribute 'body'”

I am using the following code which is mimicking an XHR request on a webpage to update the contents of a table object when a different tab button is selected on screen: import requests url = ...
0
votes
3answers
13 views

python object cannot find attribute error

I have a file parser.py class Parser: ... ... @staticmethod def someMethod(): Parser.argsParser.someNewMethod() And a file worker.py import connection, parser ... ... ...
1
vote
0answers
20 views

Redis still fills up when results TTL=0, Why?

Question: Why is redis filling up if the results of jobs are discarded immediately? I'm using redis as a queue to create PDFs asynchronously and then save the result to my database. Since its saved, ...
2
votes
3answers
37 views

Exception handling: what exception to raise

I am writing a python function that accepts certain parameters. I would like to make sure one of the parameter's value is a string of specific custom format. If it doesn't match the format I would ...
0
votes
0answers
6 views

Mongoengine + Django: strange errors with fields during rendering

I use Mongoengine 0.8.7 + Django 1.6.5, Mongodb 2.7 I have model class Tweet(DynamicDocument): #user = ReferenceField(User, reverse_delete_rule=CASCADE) #id = StringField(db_field='id',required=True) ...
2
votes
1answer
39 views

standalone script or as module?

I have always a dilemma with the choice of making a module/package or keeping a script standalone. I often write small scripts/programs in Perl or Python that do some work. Sometime I use the same ...
0
votes
2answers
35 views

how to get values from a list that are like values in a set in python

Let's say I have a set with values like (20140101224466, 20140209226655, ...), and I have a list that contains ('abcde.test.20140101224466', rbtd.test.20140209226655). How would I compare my list ...
0
votes
2answers
22 views

Reading key value pair from a tab delimited file in python

Following are my contents [ please ignore if its not already tab delimited. I am told it will be] A B C 1 2 3 I want to read in such a way that A gets 1, B ...
0
votes
2answers
12 views

Convert Unicode Object to a Datetime Object in a List of a List

I am trying to take a list of a list and I would like to split apart the datetime object that is in the first element of each element of the list as shown below. list = [[u'2014-09-02T23:00:00', ...
-2
votes
6answers
38 views

what is the difference between list and iterator in python?

I am reading the book Think Python: How to think like a computer scientist. In that book, it is written that in Python 3, dict([list of tuples]) returns an iterator instead of a list, as it is the ...
0
votes
3answers
21 views

Python regex swallows one character upon new line substituion

I am trying to understand what is wrong with my python regex. Task: I have the following text. This is a red fox\LF that chases a cat.\LF \LF The dog barks. I need to correct the first sentence by ...
0
votes
3answers
55 views

How to write file to RAM on Linux

A program that I can not modify writes it's output to a file provided as an argument. I want to have the output to go to RAM so I don't have to do unnecessary disk IO. I thought I can use tmpfs and ...
0
votes
0answers
6 views

Missing file in compiled py2exe app selenium

I am trying to get my Selenium app to work. It compiles everything, but when I open the app it gives me this: C:\Python34\dist>browse.exe Traceback (most recent call last): File "browse.py", line ...
0
votes
0answers
11 views

Figure appearance is not preserved when its axes are added to new figure

I have several figures generated by independent scripts that I would like to lump in one complex figure with custom axes (position and size) for each panel. I know that this approach seems not to be ...
0
votes
0answers
3 views

mayavi misaligned streamline and image plane when overplotted

I have 3D scalar and vector data that I'm plotting together with streamlines (mlab.pipeline.streamline) and image planes (mlab.pipeline.image_plane_widget). This is often working, but sporadically ...
0
votes
0answers
10 views

Create a .eml file in Python

Anybody knows how to do this? I got all the information of the email (body, subject, from , to, cc, bcc) and need to generate an .eml file out of it.
0
votes
1answer
27 views

How to replace efficiently values on a pandas DataFrame?

I've got a large DataFrame(600k,2) named data and basically I have in the second column a set of 50k unique values distributed along the data. The data looks like this image_id term 0 ...
0
votes
3answers
27 views

NameError: global name 'program_startdate' is not defined

I am working on my python script to get the list of time formats that I stored in sqlite3 database. I have got a problem with the variable program_startdate which is under the loop for each row in ...
-1
votes
1answer
17 views

Use Python to Edit Windows 8 Power Options

The Problem: Every time I restart my computer my Windows 8 power settings go back to default and puts my computer to sleep after an hour. I don't want my computer to ever go to sleep unless I say ...
1
vote
2answers
18 views

Converting timezones from pandas Timestamps

I have the following in a dataframe: > df['timestamps'].loc[0] Timestamp('2014-09-02 20:24:00') I know the timezone (I think it is GMT) it uses and would like to convert the entire column to ...
0
votes
1answer
21 views

Find attribute name by value in BeautifulSoup (not reverse)

I'd like to automatically find the attribute name when knowing a unique value I'd be searching for in BeautifulSoup. E.g. >>> soup = '<div class="bla">123</div>' "Knowing" ...
0
votes
0answers
5 views

Tweepy search by location using shapefile

I'm on a project trying to analyze spatial distribution of Tweets. I don't want to depend on the geotaged Twitters, as they are very rare. My idea is to input a shapefile and use each feature of it ...
0
votes
1answer
12 views

Determine Size of Pickled Datetime

I am currently pickling a python datetime to be passed to a task via celery, and am running into memory issues. I'd like to find a way to determine the resulting size of pickling a datetime object so ...
1
vote
3answers
21 views

Django :: Reference foreign key

I want to create a page where I can display properties by their pictures on a webpage. Currently, My Property model looks like this (some codes are taken out): class Property(models.Model): ...
0
votes
0answers
11 views

Converting grammar to EBNF

in an exercise the following grammar should be converted to EBNF so it produce correct Python identifiers: identifier ::= (letter|"_") (letter | digit | "_")* letter ::= lowercase | ...