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
0answers
17 views

Python - Selenium - Webscrape Table

import time from selenium import webdriver from selenium.webdriver.common.keys import Keys from datetime import datetime, timedelta from tkinter import StringVar, messagebox, Entry, Tk ...
-2
votes
0answers
38 views

populate the dictionary values [on hold]

please help to fix the script. import shelve db = shelve.open('data') keys = ['id', 'type', 'number']; def outputDB(db): for record in db: print(record, ': ', db[record]) for ...
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 = ...
0
votes
0answers
18 views

Python 3 “The _imagingft C module is not installed”

I want to use django-simple-captcha in my web site. I went through installation guide in official site but captcha image doesn't load in borrowser and this error appears in console: 500 (INTERNAL ...
2
votes
1answer
29 views

python “__package__” attribute explained

I'm sorry if I raised a dumb question. All I want to know is what exactly does __package__ mean? Didn't find any explanation in the official doc, even on SO. If you could provide some examples I ...
2
votes
1answer
34 views

Use a metaclass only for subclasses

Is there a way in Python 3.2 or later to define a class whose subclasses should be created using a specific metaclass without the class itself being created using that metaclass? An example to ...
3
votes
2answers
46 views

Printing until a specific character position in python

First I apologize if this is a question that has been answered many times, I searched around a while for an answer, but much of what I found went over my head since I am just beginning to learn ...
1
vote
2answers
46 views

How do Arguments and Parameters Work in Python? [on hold]

I have looked all over Stackoverflow and I can't find an answer, and all the web tutorials just go right over my head. I have a functioning code that I don't understand import random import time def ...
-4
votes
1answer
50 views

How to restart code if input entered = 'y'

I'm making a Python software to encrypt/decrypt/brute force messages, but I need to know how to restart the code at the end, so like at the end it will ask you "Would you like to continue? y/n" If the ...
0
votes
2answers
55 views

invalid syntax on =? [on hold]

i am a beginner at python trying to make a very simple program using yes/no. it says that there is a syntax error on the first = in the line: if monkeya="yes" and monkeyb="yes": here's my entire ...
3
votes
4answers
54 views

Writing bits to a binary file

I have 23 bits represented as a string, and I need to write this string to a binary file as 4 bytes. The last byte is always 0. The following code works (Python 3.3), but it doesn't feel very elegant ...
0
votes
1answer
39 views

implement the dictionary entry

please help to fix the script. it should provide an opportunity to introduce a new element of the dictionary. keys = ['id', 'type', 'number']; rec1 = {'id': 1, 'type': 'c', 'number': 111} rec2 = ...
2
votes
2answers
58 views

Python2 “raise e[0], e[1], e[2]” and python3 version in one file

I've found that python 3 equivalent of: raise e[0], e[1], e[2] will look something like this: raise e[0](e[1]).with_traceback(e[2]) But I get either syntax error for the 1st (in python 3) or ...
0
votes
1answer
29 views

Can't get new line to work in python?

This is the code that i'm currently using to try to get a new line. Sadly it just rewrites the first line in the program. What is going on? If you can help I will be very thankful. import itertools ...
1
vote
1answer
46 views

exe file doesn't work properly (nothing happens)

When I compile my file (snake.py) to exe, the output file (exe file) doesn't work. I thought this may be as a result of the error that occurs during compiling: missing modules: ? _frozen_importlib ...
1
vote
3answers
37 views

Do python modules get imported twice?

If I have one file that runs import math, and a second file that also has import math AND which imports the first file, does that load the math module twice in memory?
0
votes
1answer
26 views

Virtualenv doesn't install pip

I have installed python3 via homebrew, updated pip & setuptools, installed virtualenv via pip. Now I'm trying to create a virtual env. Unfortunately, I can't get it to add pip to the virtualenv. ...
0
votes
1answer
17 views

reading data from stackoverflow rest api

Playing around with the raspberry pi and python. so bear with me :) When trying to decode the response data from the stackoverflow api I keep on receiving the error utf-8 codec can't decode byte 0x8b ...
0
votes
1answer
13 views

Converting SQL data into a QTextDocument and then outputting a pdf

I am trying to add a way to export data from an sqlite3 database into a pdf document. In the book rapid gui programming with python and Qt it says that I can export QTextDocuments as pdf files. ...
0
votes
0answers
20 views

Python 3, converting string to bytestring

I'm trying to create a function that will XOR two bytes in python 3. This works, and I get a string that looks like a bytes out of it, but it says it isn't bytes (if I print it it doesn't have the b ...
1
vote
1answer
32 views

What is the convention in referring to a non-overridden superclass method from within the subclass?

Which of these is preferred? I believe they are identical in outcome. self.inheritedMethodName(arguments) Or: ParentClass.inheritedMethodName(self, arguments) I am aware there is also: ...
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 ...
-1
votes
0answers
20 views

A multicolumns listbox with tkinter and Python 3.3 [on hold]

I'm trying, as the title explains, to make a multicolumns listbox with tkinter and Python 3.3. I'd like something that looks like the following: How can I do it ? Thank you in advance
0
votes
1answer
27 views

Raspberry Pi Digital interface python error [on hold]

I created a python script for my Raspberry pi. It interfaces with a digital interface that plugs into the pi's GPIO pins. Though when i run the pi I get this error below. Though when i add """ to ...
0
votes
2answers
23 views

Having trouble running a python program on CMD on windows

Here is the program. It works great on the IDLE but, it crashes after asking if you know the password length. I can't seem to figure out want i'm missing. I would love any help. import itertools ...
3
votes
3answers
67 views

Is a bad practice to use accent in python class name?

I'm developing an app in Python3 and need to create a class that represent a diary, weel, I want to name it in my language, and it have an accent, is it a bat practice? May I have problems because ...
2
votes
1answer
27 views

Force all iterations on an iterable

I've written a for-loop using map, with a function that has a side-effect. Here's a minimal working example of what I mean: def someFunc(t): n, d = t d[n] = str(n) def main(): d = {} ...
0
votes
3answers
34 views

concurrent.futures.ThreadPoolExecutor.map is slower than a for loop

I am playing with concurrent.futures.ThreadPoolExecutor to see if I can squeeze more work out of my quad-core processor (with 8 logical cores). So I wrote the following code: from concurrent import ...
0
votes
1answer
33 views

out of box example does not work on python 3.3 expected bytes str found

from rsa import * def main(): (bob_pub,bob_pri)=newkeys(512) message ='Number of bits needed to represent a integer' crypto = encrypt(message,bob_pub) message1 = ...
0
votes
2answers
36 views

remove items from 2 dictionaries python 3

I have the following dictionaries: a = {'f': 2, 'u': 210, 'the': 100, 'too': 300, 'my': 199, 'is': 2466, 'and': 3787} b = {'f': 9, 'u': 17, 'o': 14, 'the': 23, 'yy': 7, 'and': 12} I want to remove ...
0
votes
0answers
33 views

Weird error that comes up during python program run

Whenever I run my program I get this error. Do you know what this means? This happens when the turtle.clear() function is called File "C:\Python32\lib\turtle.py", line 2642, in clear ...
0
votes
1answer
16 views

Insert and update with core SQLAlchemy

I have a database that I don't have metadata or orm classes for (the database already exists). I managed to get the select stuff working by: from sqlalchemy.sql.expression import ColumnClause from ...
0
votes
1answer
28 views

When to use x.__lshift__ and x.__pow__ [on hold]

I am currently studying the methods for each built-in function, many apply to other functions. I came across 2 methods withing the bool() function: x.__lshift__ and x.__pow__. Now, x.__lshift__(y) ...
0
votes
1answer
21 views

Circle and line collision detection in python tkinter

I writing a python program in which a circle bounces off of user drawn lines. There are multiple circles that bounce off the wall. For each one, the shortest distance from the center of the circle and ...
0
votes
2answers
30 views

Consolidate values in CSV with Python 3

I have a csv with two lonely columns. I built them using a Python dict. Column A is word, Column B is a number FRUIT INVENTORY Apple 2 Orange 5 Grape 1 Orange 2 Kiwi 3 Apple 4 As you ...
0
votes
0answers
29 views

PyGame: Sprites In Same List Collision / Smooth Movement

I am making a space survival game, and it has multiple enemies (only meteors currently though more coming soon) and I am trying to make them collide with each other so they don't cluster up together ...
0
votes
4answers
32 views

Python nested select on named property

I have a set of lists such that I have an array of something like this class engine: engines = [] def __init__(self): this.modules = [] class module: def __init__(self,flag): ...
4
votes
1answer
44 views

How do I allow more simultaneous socket connections?

I'm attempting to implement the Reactor pattern in Python. I think I have a pretty decent start using multiprocessing and select.select. However, I'm trying to stress-test my server, so I wrote a ...
5
votes
3answers
53 views

Workaround for equality of nested functions

I have a nested function that I'm using as a callback in pyglet: def get_stop_function(stop_key): def stop_on_key(symbol, _): if symbol == getattr(pyglet.window.key, stop_key): ...
2
votes
1answer
35 views

Filtering of structured array via bit-wise operation (bitmask) on column data

I have a structured array. One column (event_type) is a bitfield. I would like to filter the data via the event_type. Previously I used filter() but it produces a list that would need to be back ...
1
vote
1answer
52 views

Getting number of lines in a text file without readlines

Let's say I have a program that uses a .txt file to store data it needs to operate. Because it's a very large amount of data (just go with it) in the text file I was to use a generator rather than an ...
0
votes
1answer
23 views

Python - tkinter - How to move messagebox to foreground

from tkinter import messagebox Tk().withdraw() acceptInput=messagebox.askquestion("Input Assessment","do you accept this input?") The askquestion window box is appearing in the background rather ...
0
votes
3answers
70 views

append/insert a value/string to a list element dynamically in Python?

my_list = ['cat','cow','dog','rabbit'] but what I want is to append/insert a character(or string) to one or more element(not all). something like my_list = ...
-1
votes
0answers
49 views

python----How to make a variable to change in global

Below is my code. It's simple. I want nothing1 to change. But at present it doesn't change. You can also help write a new one liking using while/for. import re import urllib.request reg = ...
0
votes
3answers
27 views

Changes in re module between Python 2 and Python 3

I am running my unit test suit with python3.x on a code that was developed under python2.x. All unit tests passed under python2.x but not for python3.x. It seems there is some change in the ...
-3
votes
0answers
63 views

remove space from list of lists in python [on hold]

a= ['Business', 'Food/Clothes', 'Fun', 'Politics', 'Starting_with_Apolog', ['NNP', 'MD', 'NN', 'NNP'], ['NNP', 'NN', 'NNP'], ['PDT', 'MD', 'NN', 'NNP'], ['PRP$', 'MD', 'NN', 'NNP'], ['UH', 'MD', ...
-3
votes
2answers
55 views

Removing single quotes when writing dict to CSV in Python

I've been searching for hours and can't find an answer to what should be a very simple question. I have a dict... {'apples' : 'red', 'pears' : 'green', 'bananas' : 'yellow'} When I try to write ...
3
votes
1answer
46 views

Difference in type() and hasattr() between Python 3 and Python 2

When I am trying to check type of class declaration in Python 3 and Python 2, I get strange results, as followings show, >>> #python 2.7.6 >>> class MyClass: ... pass ... ...
0
votes
3answers
29 views

Character encoding with Python 3

If I run print(chr(244).encode()) I get the two-byte result b'\xc3\xb4'. Why is that? I imagine the number 244 can be encoded into one byte!

15 30 50 per page