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
7 views
python iterate over and select values from nestedarrays
I have several multidimensional arrays that have been zipped into a single list and am trying to remove values from the list according to a selection criteria applied to a single sub-array. ...
0
votes
0answers
6 views
Actively Scanning for Different File Date in Python
I am trying to make a Python script that actively scans a log for new credentials and fixing them (Ettercap outputs, etc.), but I'm not getting the output I want. I am a complete noob at while loops, ...
0
votes
3answers
21 views
Python: Identical strings (or numbers) with unique ids?
Python is wonderfully optimized, but I have a case where I'd like to work around it. It seems for small numbers and strings, python will automatically collapse multiple objects into one. For example:
...
0
votes
0answers
5 views
Draw moving polygons with matplotlib
I have many polygons whose vertices moves every time step of a simulation, and after all the new polygons form are calculated they have to be plotted to a matplotlib fig.
When the code was static, i ...
0
votes
0answers
4 views
Using Flask-Admin ImageUploadField with SQLAlchemy
Okay, so I asked this question before but I failed miserably of explaining the problem and what I want, so here I go again.
The end result that I want: User chooses an image while filling out the ...
0
votes
0answers
18 views
Python while loop not executed until 'try'
I got a very simple python while loop here:
def run(self):
while True:
self.__main_thread.ask('wake',{})
time.sleep(0.25)
The 'ask' function will not be executed until I change ...
0
votes
1answer
10 views
How to generate CSV formatted data from python?
After running a python program, I obtain a list of numeric data. How can I format the data in CSV?
Goal:
I hope to format it so that I can reuse the CSV-formatted data in Mathematica.
1
vote
1answer
9 views
How to execute CASCADE on delete?
I have this model in Django, where a person has the same information from the user provided by Django plus a little bit more information. When I create a new person it requires to create a new user ...
0
votes
0answers
5 views
Django cursor initialization
What would be the difference in using the following two cursors -- that is, how does django 'initialize' its cursor and connection?
(1) Django default
from django.db import connection
conn = ...
0
votes
0answers
3 views
wxPython Treebook Images
In this official treebook tutorial they use the images module. I can't find it. Can someone give me a link or example how how to actually add things to the listbook? I want to eventually display ...
0
votes
0answers
4 views
How to include a multi-index when creating a pandas dataframe with .concat
I want to create a pandas dataframe from a list of series using .concat. The problem is that when one of the series is empty it doesn't get included in the resulting dataframe but this makes the ...
0
votes
0answers
6 views
Clarification on the statement if request.Post: in django
Suppose I have a view like this:
def home(request, redir_url, template = 'example/home.html')
if request.session["profile_name"] and request.session["token"]:
return ...
0
votes
0answers
4 views
IPython - get value for checkbox widget before cell finishes execution?
I have the following IPython cell:
from IPython.html import widgets
from IPython.display import display
checkbox = widgets.Checkbox(description="A", value=False)
display(checkbox)
raw_input("Hit ...
2
votes
0answers
16 views
Improving the algorithm to distinguish the different types of table
I have two tables with the following structures where in table 1, the ID is next to Name while in table 2, the ID is next to Title 1. The one similarity between the two tables are that, the first ...
1
vote
0answers
6 views
Add child classes in SQLAlchemy session using parent constructor
I have a class inheritance scheme as layed out in http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#joined-table-inheritance
from sqlalchemy import Column, Integer, String, ForeignKey
from ...
1
vote
1answer
10 views
what does NDB stand for in python datastore?
I can't believe wiki doesn't have this answer. I'm looking for NDB with respect to the google cloud platform and python, not non-directional beacon.
...
1
vote
1answer
11 views
append to instance list with multiprocess
I have a class that has a list for one of its attributes. After instantiating the class, I would like to do some calculations then append the results (which are lists themselves) to the list. I'm ...
0
votes
0answers
3 views
Interpreting cProfile results: total vs. cumulative time in small function
Most of my Python program is spent in a method called _build_userdbs. I'm using the awesome tool SnakeViz which helps interpreting the results. There's a screenshot below.
So right now, in that ...
0
votes
2answers
24 views
Creating custom “list” attributes
I am trying to create functions for the property list. How do you create the attribute function for something like this?
list([1,2,3,4,5]).even()
should return:
[2,4]
The method should be easy ...
0
votes
2answers
15 views
How to compare 2 files in Python while ignoring lines with comments (i.e line start with #)
I've got two files and its content looks like below`
# version 17.3
# Config info for 0092
# Data for sgs
# State : NA
# Length : NA
# Generated on Wed Apr 29 10:30:12 2015
...
1
vote
2answers
21 views
How to sort through a list of strings and a list of numbers which are related, in python?
I am basically making a program which is like a Student Grade application. It basically starts of in input mode and asks you for your name,age, science grade, maths grade and English grade. Then ...
-3
votes
0answers
27 views
Syntax error with Python code [on hold]
This is a code for finding the root of the equation f(x) = exp(-x) - x in iteration method. When it runs, it shows the error,
File "fixedpointiteration.py", line 7
i = i+1
^
SyntaxError: invalid ...
0
votes
0answers
5 views
wxPython Notebook Pages
I'm trying to add code to a notebook page. It works fine in a frame, but in a notebook page derived from Panel it does not. I need some help understanding panel and help fixing my code. Here is the ...
-1
votes
1answer
31 views
Compare two nested lists and append a third list based on nested values - Python
Nested list A = [[1, 110, 150, 3], [5, 95, 155, 1], [4, 115, 195, 4], [2, 105, 205, 2]]. I am trying to give a score to each of these individual lists which is calculated as score = number of ...
0
votes
0answers
11 views
Dynamically Loading a C++ class via Python capsules
This question is mostly academic.
It stems from some design questions I came across while working on wrappers for an existing C++ project.
When working with C/C++ extensions for Python, it is ...
0
votes
0answers
2 views
Unable to provision an AWS SQL Server RDS instance in Multi AZ using boto
I'm trying to provision an SQL Server Standard Edition AWS RDS instance which is mirrored across two AZs using boto's rds2.
Whenever I call the create_db_instance method in ...
0
votes
0answers
2 views
How to use subdirectories with Ruffus pipelines
The Ruffus pipeline documentation seems to assume that one's code and data are in the same directory. All the examples have input and output file specifiers without any relative paths. How should one ...
0
votes
0answers
25 views
Unintended Hebrew characters being read in Python from txt file
I'm getting a strange error when I try to read a list from a txt file. It looks like a series of six Hebrew characters. I've read about the Bush hid the facts bug, but setting the encoding to utf-8 ...
0
votes
1answer
15 views
Pandas dataframe insert rows
I got a problem dealing with dataframe.
I want to insert rows in DF and modify its related values:
for example I have
time value
0 10:00 2
1 11:00 4
2 12:00 6
3 13:00 8
...
0
votes
0answers
5 views
pySerial permissions to toggle?
I'm using pySerial to stage some scripted events in navigating menus. I'm connected to a PoE, with my scripts goal of turning off one of its Ethernet ports. I navigate just fine through menus but once ...
4
votes
3answers
28 views
Why can't you reference modules that appear to be automatically loaded by the interpreter without an additional `import` statement?
When you start your Python interpreter it appears that some modules/packages are automatically imported during the startup process:
python
Python 2.7.6 (default, Jan 13 2014, 14:59:37)
...
...
1
vote
4answers
53 views
Is there an efficient alternative for growing dictionary in python?
I am reading a large text corpus in xml format and storing counts of some word occurrences in a dictionary where a key is a tuple of three elements {('a','b','c'):1}. This dictionary continuously ...
-9
votes
3answers
44 views
tuple vs. list keys in python dictionaries [on hold]
Assuming no downstream tuple requirements, what are the benefits, if any, of using tuples as dict keys as opposed to lists?
For example
thedict[('a','b','c')] = { ... }
vs.
...
0
votes
1answer
7 views
Are IPython engine's independent processes?
From the IPython Architecture Overview documentation we know that ...
The IPython engine is a Python instance that takes Python commands over a network connection.
Given that it is a Python ...
0
votes
3answers
26 views
Reading mulitple data from a text file
I am trying to read two pieces of data from a single text file. Here is how the file looks:
PaxHeader/data-science000755 777777 777777 00000000262 12525446741 015207 xustar00armourp000000 000000 18 ...
0
votes
1answer
8 views
ValueError in matplotlib when using \: LaTeX horizontal spacing
See MWE below:
import matplotlib.pyplot as plt
import matplotlib.offsetbox as offsetbox
fig = plt.figure()
ax = fig.add_subplot(111)
text1 = r'$a\,=\,{}\pm{}$'.format(0.01, 0.002) # Works.
text2 = ...
1
vote
1answer
18 views
Python -Get the body of an multipart email
i get an email with the following code:
m = imaplib.IMAP4_SSL(MailReceiveSRV)
m.login(MailReceiveUSER, MailReceivePWD)
m.select("Inbox")
status, unreadcount = m.status('INBOX', "(UNSEEN)")
...
0
votes
0answers
14 views
Hierarchical Django URLs for Objects with Parents
I have a Django app which allows me to build simple pages. Currently I allow a page object to have a parent, which is a ForeignKey to another page, as long as the parent page does not have a parent of ...
1
vote
2answers
19 views
Global Seed for Multiple Numpy Imports
Assume that I have a Python project structure as:
main.py which imports random_initialization.py
main.py which imports sample_around_solution.py
Both random_initialization and ...
0
votes
1answer
35 views
python, square finder, memory error
I've been working on a problem to find whether or not a given integer n is a perfect square. Although the algorithm works, I get a MemoryError. How should I rephrase this code bit?
Thanks in advance.
...
0
votes
2answers
46 views
creating a new variable using the def command in python
I am trying define a command that creates a new variable based on one of the arguments given for the command. For example:
def NewEntry(Variable,Variable_Entry,Column,Row):
Variable = StringVar()
...
1
vote
1answer
26 views
Install PIL without pypi
I need to install pillow (PIL fork) using either easy_install or source. Due to the restrictions on the computer at school I'm using, I can't access python.org, or pip. I have a portable python ...
0
votes
0answers
7 views
How to create a UUID from a known hex string and store it in MongDB using pymongo?
I need to convert some hex strings that I have into UUIDs, and store them in MongoDB.
I tried the following:
import pymongo
import uuid
[...]
document = { '_id': 123, 'my_uuid': ...
0
votes
0answers
6 views
Differences between each F1-score values in sklearns.metrics.classification_report and sklearns.metrics.f1_score with a binary confusion matrix
I have (true) boolean values and predicted boolean values like:
y_true = [True, True, False, False, False, True, False, True, True,
False, True, False, False, False, False, False, True, False,
...
0
votes
0answers
16 views
modifying django modelform select set
I created model with choices option:
SERVICE_CHOICES = (
('Apps', 'Apps'),
('Ask', 'Ask'),
('Auth', 'Auth')
class InputsModelExtended(models.Model):
service = ...
0
votes
1answer
13 views
use python requests to post a html form to a server and save the reponse to a file
I have exactly the same problem as this post
Python submitting webform using requests
but your answers do not solve it. When I execute this HTML file called api.htm in the browser, then for a second ...
0
votes
2answers
44 views
Remove repeating spaces manually in a string
I have a question about a certain piece of code. I was doing an exercise in python about strings. I had come up with the correct logic but, for some reason, the output inside the for loop is not ...
0
votes
2answers
23 views
Python - ValueError: invalid literal for int() with base 10: '15.5'
primera_nota = raw_input("Dame tu primera nota: ")
segunda_nota = raw_input("Dame tu segunda nota: ")
tercera_nota = raw_input("Dame tu tercera nota: ")
cuarta_nota = raw_input("Dame tu cuarta nota: ...
3
votes
2answers
40 views
Python - extracting particular numbers from each line in a file
I have a text file which has 1000's of lines of text but I'm interested in only find certain lines in the big text file and extracting some interesting numbers from those lines. Below is the sample ...
1
vote
2answers
12 views
Scrollbar to scroll Text widget, using Grid layout, in Tkinter
I am trying to use the grid layout manager in Tkinter to create a dialog box.
I want the Text area at the bottom to have a scrollbar. Unfortunately I can not figure out how to make the scrollbar be ...