2
votes
1answer
35 views

Matrix of lists - Python

I want to create a matrix of list, but when I create the lists inside the matrix it created a linked list, and I don't need that. A=[[{}]*3]*3 result: [[{}, {}, {}], [{}, {}, {}], [{}, {}, {}]] ...
0
votes
3answers
27 views

python delete next and previous rows from textfile. Based on sample

I have to delete the specified rows from textfile and the previous and next rows. I can delete the specified row, but I don't know how can I delete the next and the previous. Here is my code def ...
0
votes
0answers
15 views

Debug memory consumption\leaks of already running script

I have a Python program that started eating a lot of RAM. The problem is that it has been working for around 2 days with no issues, but started eating a lot of RAM suddenly. The script is quite large ...
1
vote
1answer
32 views

Accesing private module variable from class

I'm trying understand python scope rules. To do this I try access "very private" variable from class in same module bar = "bar" _bar = "underscore" __bar = "double underscore" def foo(): print ...
-2
votes
0answers
34 views

Python substring searching speed

In python, how does the speed of finding a substring in a string vary depending on the length of the pattern (the needle), all else constant? EDIT: The hypothetical example: 'mn' in ...
-2
votes
0answers
23 views

Python : Is there another way to install with setup.py (not with an install command)?

I am trying to install the chardet module but i have to install it with a setup.py file, adn it does not work with Windows command. I opened the Windows command and wrote the path to the ...
-5
votes
1answer
54 views

python append list return none

I have the following code to generate a list of tuples: list_of_tuples = list() for name in list_of_names: temporary_list = [name] date = function_that_return_a_list #like ['2014', ...
0
votes
0answers
16 views

Create virtualenv with python2.7 results in error

I'm operating on Ubuntu 13.10 I needed to install virtualenv 1.10.1, because 1.11 had some issues. Now when I run the command: virtualenv venv I don't get any errors, everything is fine. Except ...
0
votes
1answer
30 views

How to pass variable to SQL in Python

I have a python script like the below. It will receive parameters and will query in DB. However I am not sure how to pass the variable abcd to the SQL statements mentioned below. abcd = ...
15
votes
1answer
140 views

Why is float() faster than int()?

Experimenting with some code and doing some microbenchmarks I just found out that using the float function on a string containing an integer number is a factor 2 faster than using int on the same ...
0
votes
0answers
11 views

In Python, how to begin with chardet module?

I would like to try some code that uses the chardet module. This is the code i have found on the web : import urllib2 import chardet def fetch(url): try: result = urllib2.urlopen(url) rawdata ...
0
votes
1answer
39 views

How to create a class decorator that can add multiple methods to a class?

I'm currently trying to implement a class decorator that can add multiple methods depending on the arguments. For example: @decorator('my_func') class Screen: ... will add the method 'my_func' ...
0
votes
3answers
32 views

Removing common words from a string?

I'm trying to filter common words to end up with a city name. Here's what I have: import re ask = "What's the weather like in Lexington, SC?" REMOVE_LIST = ["like", "in", "how's", "hows", "weather", ...
3
votes
3answers
48 views

Numpy quirk: Apply function to all pairs of two 1D arrays, to get one 2D array

Let's say I have 2 1D numpy arrays, a and b, with lengths n1 and n2 respectively. I also have a function, F(x,y), that takes two values. Now I want to apply that function to each pair of values from ...
0
votes
1answer
16 views

Python/Pygame 2.7 Text to image conversion

I am writing a program that reads from an external file (level.lev) and converts the x's and o's in that file into red and green squares accordingly into a pygame window. The code works for detecting ...
0
votes
1answer
36 views

Fast ping sweep in python

So, I'm trying to get similar results using python as I do with a bash script. Code for the bash script: #!/bin/bash for ip in $(seq 1 254); do ping -c 1 10.10.10.$ip | grep "bytes ...
0
votes
1answer
44 views

Python alternative to fscanf C code

I have some C code that works well: #include<stdio.h> #include<stdlib.h> int main() { FILE *fp; struct emp { char name[40]; int age; float bs; }; ...
-1
votes
1answer
22 views

Python - Remove “tagged” item from list only if another item with greater “tag” exists

My starting list (with "tagged" items as [Ann] and nn being a 2-digit integer) : myList ['[A01]apple', '[A02]apple_sauce', '[A03]apple_juice', '[A04]banana', '[A05]banana_bread', '[A06]banana_ice'] ...
0
votes
0answers
34 views

In Windows how to keep running a python script in the background even after logging out?

A Google search revealed some good answers but they don't exactly solve my problem. For running a python script after logging out from SSH the answer is: ...
0
votes
1answer
55 views

Math Equations as Python Objects

I'm trying to develop a program that contains a set (or list) of defined functions, such as follows: x = ["f1(x)=x^2", "f2(x)=2x+1", ...] Afterward, I can use matplotlib and render them, etc. ...
0
votes
2answers
27 views

Find Process ID active when process name is given

I am using python 2.7 and windows. I want to find out the list of process IDs active when process name is given. import time import win32pdh def GetProcessID( name ) : object = "Process" ...
2
votes
1answer
24 views

Python: How to import all methods and attributes from a module dynamically

I'd like to load a module dynamically, given its string name (from an environment variable). I'm using Python 2.7. I know I can do something like: import os, importlib my_module = ...
1
vote
2answers
28 views

Making a Python 2.7 module: Referencing values?

I'm making a fairly simple weather module for myself and I have run into a major issue, I can't get a value from my module. First, let me show you what I have so I can point out my issue. ...
1
vote
0answers
16 views

dtype mismatch in sklearn on k-means

I am attempting to run the first answer to this question Python Relating k-means cluster to instance however I am getting the following error: Traceback (most recent call last): File "test.py", ...
1
vote
2answers
61 views

Dictionary seens ok , but function return “List index out of range”

I'm not sure why this function is returning "List index out of range" Since it seens ok. What the function does is basically work the content of the file.txt to create a dictionary with the values. ...
0
votes
0answers
24 views

How to implement a class to represent Polygon

I want to Implement a class for representing a polygon that possibly has holes. A class like Polygon(object) that represents a polygon like poly1 = Polygon(((0, 0), (0, 1), (1, 1), (1, 0))). I've ...
0
votes
0answers
18 views

Running subprocess module assigned to os environment

I have a problem with my python script and after trying/searching for hours I haven't found the solution yet. So I'm seeking your help. I'm running a subprocess call from inside a software which has ...
2
votes
4answers
53 views

Python join list of strings with comma but with some conditions - code refractoring

Assume i have this list l: l = ['a', 'b', 'c', 'd', 'e'] I know i can join them using .join with comma separated as: s = ', '.join(l) >>> a, b, c, d, e But i want to respect these ...
0
votes
2answers
13 views

PyQt4.QtCore.QVariant object instead of a string?

I followed this example Key/Value pyqt QComboBox, to store ID value to a combo-box item using the code below. self.combox_widget.addItem('Apples', 'Green') indx = self.combox_widget.currentIndex() ...
0
votes
1answer
23 views

Remove background colour from image using Python/PIL

I've been trying to get this to work and am really having trouble, so would be very grateful for some help. Using the code below, I want to change the features with the specified RGB values to white, ...
0
votes
0answers
14 views

Raise event in Tkinter from command line (windows)

I'd like to use Tkinter to run in the background, so that I can do some operations that take a long time when my program starts up, and then call functions on demand. A smallish example of what I mean ...
0
votes
3answers
51 views

Length of a list of points [on hold]

For a given list of points that make a line I want to compute the length of it. For example for: [(1,0),(5,6),(9,6),(5,2)] these are just a list of connected points. How can I have an automated ...
0
votes
2answers
22 views

How to represent a linestring using a point class

I want to Implement a class for representing a linestring. I have a class called "Point" that represents a point with 2 coordinates and I want to use it for storing the internal vertices of the ...
0
votes
1answer
24 views

ImportError: No module named matplotlib.python-dateutil

I'm trying to use py2exe to convert my .pyw to executable file, and encountered this error - "ImportError: No module named matplotlib.python-dateutil" I've installed dateutil before trying to ...
0
votes
0answers
28 views

Python: Search API's, working code examples? [on hold]

I'm looking to pull very basic search results from a string but can't seem to find a simple way of doing it. I read the Google Search API has been deprecated, Yahoo charges out of the gate and pybing ...
0
votes
2answers
30 views

Different output format than expected

I have written code to read following text file Generated by trjconv : a bunch of waters t= 0.00000 3000 1SOL OW 1 -1.5040 2.7580 0.6820 1SOL HW1 2 1.4788 2.7853 ...
-3
votes
2answers
49 views

I cannot read negative values [on hold]

I have a data set as follows it includes some negative values. I have written codes to read those values. But when any negative numbers percent. It gives error. File format is as below 1SOL HW1 ...
0
votes
0answers
11 views

'mod_ty': Undeclared Identifier

While compiling an VC++2008 Project with python-2.7.6 as reference i get the following error Python27/symtable.h(55): error C2065: 'mod_ty': Undeclared Identifier Line 55/56 includes: ...
0
votes
0answers
11 views

How can I include PyQt4 as one of the required installs for my python module while packaging it using setuptools?

I have an application that I want to make a package and share it. This app of mine uses PyQt4 of version 4.10.3. Now, I add the following to the install_requires option in my setup.py file: ["pyqt4 >= ...
2
votes
1answer
33 views

Why are some of my files not available in the installation of my python module packaged using setuptools?

So I have made a small application that I typically want to package and share it with the world. I read the tutorials for packaging my app using setuptools. It was going well until I got stuck at one ...
0
votes
0answers
51 views

why python quitting unexpectedly while trying to import something

sometimes when I try to import some module or package my python quits unexpectedly , like not I tried import ansi2html and i got the below error and kicked out from python shell with segmentation ...
0
votes
1answer
26 views

Signal handling in python-daemon

I installed python-daemon and now I'm trying to get the signal handling right. My code: #!/usr/bin/env python # -*- coding: utf-8 -*- import signal, time, syslog import daemon def runDaemon(): ...
0
votes
1answer
22 views

Searching against a negative set of words

This is a followup to a question I had this morning - Using Beatiful Soup to get data from non-class section I am trying to take a set of information and search it against a set of keywords. If the ...
1
vote
1answer
28 views

How to get body when status is not 200?

I use something like this to send requests: from tornado import httpclient from tornado.httpclient import HTTPRequest client = httpclient.HTTPClient() request = HTTPRequest(url='http://google.com/', ...
4
votes
1answer
55 views

Need to read specific range of text file in Python

I need to read a text file after specific line let say line # 100. This line has specific number such as '255'. Then i want to read next 500 lines using for loop. in those 500 line i have some numbers ...
-3
votes
1answer
28 views

IndexError: list index out of range for working code [on hold]

Consider the code given: It shows list index out of range. enter code here for x in range(max_count): try: result = next(gen) assert len(result) == ...
1
vote
0answers
8 views

PyScripter with multiple version of Python on Windows

I've recently installed Python 3.3 in addition Python 2.7 on my Computer (Windows 7, 32-bit). Python 3.3 gives you the possibility of adding a "shebang line" at top of your .py files so when you ...
0
votes
1answer
23 views

write to csv from DataFrame python pandas

I wrote a program where i add two columns and write the answer to CSV file but I am getting error when I want to write only selection of columns . here is my logic: import pandas as pd df = ...
0
votes
1answer
16 views

Google App Engine: Using cron to expire (or 'unpublish') entities

I would like to mimic the 'published/unpublished' functionality of common CMS platforms like Wordpress or Drupal. So I have this Job(ndb.Model): class Job(ndb.Model): title = ...
0
votes
0answers
48 views

python exceptions.AttributeError: 'module' object has no attribute 'from_settingI

I am using scrapy 0.2 with python2.7 I want to know if the links, which i am scraping on now, have been scraped before. I searched a lot and I found this example how to filter duplicate requests ...

15 30 50 per page