Tagged Questions
-1
votes
1answer
34 views
Python function is not working in large files
This code is not processing full file, it is not transliterating full file only 3 sentences in the file. It is crashing in the case of big files also.
I am trying read and convert a large file using ...
0
votes
0answers
15 views
Using multimethod to force a function input type to be a class within itself
I am trying to create a simple library to handle matrices and vectors. To do this I have created a class vec and inherited a vec2, vec3, and vec4 class from it. In these classes I would like to force ...
0
votes
0answers
11 views
Upload a file to Sugarcrm
I am having trouble uploading a file, from a form to Sugarcrm.
I am using this tutorial, which states that the following code should update an account:
#2 - UPDATE AN EXISTING ENTRY
sugarcrm_conn= ...
0
votes
0answers
27 views
Where is the mistake in coding permutation test in python?
I'm using Python 3.4.1 and try to rebuilt a permutation test with itertools.
Popular code for this, found over here is this:
from itertools import combinations as comb
def permutationTest(a, b):
...
-1
votes
0answers
12 views
Python Tkinter ttk use in class
I'm trying to implement ttk with a grid, much like this tutorial.
The code I have right now is working good, and I should say I'm a beginner in Python, but I need help how to create a grid to place ...
3
votes
1answer
17 views
Starmap modifying a parameter before passing it in?
I have a strange bug that I'm encountering when trying to use multiprocessing.Pool.starmap. The minimum code needed to reproduce the bug is here :
from multiprocessing import Pool
# Ignore the fact ...
0
votes
2answers
23 views
Inputting textfile into list of class objects, then output the list contents
As part of my current project, I am trying to load the contents of a text file into a list of class objects, then output the objects. On a cursory look my instructor said my code looked fine, but ...
0
votes
2answers
35 views
Easy building a dictionnary of dictionnaries or dictionnaries of
With python3, I must build a dictionnary of dictionnaries of dictionnaries of ... of lists.
I'm wondering if there is a better way to do what the code below does (it looks like garbage code...)
ret ...
-3
votes
2answers
24 views
Keep getting ValueError when running while loop
My code gives me the error "ValueError: need more than 1 value to unpack" when running the infinite while loop with getting questions untill the user types no to break out of it. Any clue 1 more value ...
1
vote
1answer
21 views
Pillow : How to get Image Object from a raw file
How can I get a raw file into an Image Object of Pillow python library ?
when i try the following code :
path = '/Users/me/Desktop/SonyRX100III_raw.ARW'
img = Image.open(path)
I get this error
...
-6
votes
1answer
19 views
How to define a class in Python 3.4? [on hold]
How to define a class in Python 3.4?
I've tried this one:
Class NewClass{
int i;
}
but that does not work. The compiler says "unresolved reference".
I dont understand it. Thank you...
-2
votes
1answer
11 views
I am using shelve to append and add to dictionaries, but it won't work
import shelve
name = input('Please enter your name: ')
reg = input(Please enter the registration plate: ')
speed = input(Please enter the speed: ')
Dictionary = {name:{reg:speed}}
db = ...
1
vote
2answers
25 views
Block execution until condition
I am using eventlet and have two main process running. One of the process acts as a producer and the other as consumer. The problem is that instead of using queue from eventlet package I want to use a ...
1
vote
4answers
33 views
Unable to import wxPython using Python 3
I installed wxPython 3.0.1.1 but I'm unable to import wx using Python 3.4.1:
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 00:54:21)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type ...
0
votes
1answer
17 views
Can I use multiprocessing.Pool in a method of a class?
I am tring to use multiprocessing in my code for better performance.
However, I got an error as follows:
Traceback (most recent call last):
File "D:\EpubBuilder\TinyEpub.py", line 49, in ...
-4
votes
1answer
22 views
How to deploy a django website on google app engine?
I have a website written in Django now I want to migrate to google app engine. What is the easiest way to deploy Django app on google app engine with minimal changes, my database is in postgresql. ...
0
votes
2answers
23 views
Class accepts varying arguments Python
How would a class accept varying arguments?
For example, if I had a class like this
class Shape(object):
def __init__(self, sides):
self.sides = sides
If I call this as Shapes(3), the ...
0
votes
1answer
14 views
Need Help Updating Screen
I am working on making a game that creates a world and has entities that move in it. Before I implement movement, I was wondering how I could update the screen differently than reprinting the world ...
0
votes
0answers
18 views
can you use a variable for to name a variable in python [duplicate]
so I want to make minesweeper but can't make a grid, I was wondering, can you do something similar (but working) to this
listthing = []
x = 'x'
listthing.append(x)
y = 1
listthing.append(x)
...
0
votes
0answers
13 views
Trouble making geopy understand a list of locations
I'm trying to write a greedy algorithm that takes the a list of cities, a given city as a starting point, and successively finds the closest city in an attempt to travel to them all using the shortest ...
0
votes
2answers
23 views
Return one string on multiple lines
I am trying to get the function get_histogram to return a string that takes a character and creates a separate line for each integer in a list.
def get_histogram(list1, char):
output = ""
...
0
votes
2answers
14 views
argparse : ValueError whe using --help or -h option with nargs
Whe using argparse I get this weird ValueError for help option.
All other options work fine. Only the help option is not working, which is weird.
Here is the error message:
...
0
votes
2answers
18 views
Python - Selecting All Row Values That Meet A particular Criteria Once
I have a form set up with the following fields: Date Time, ID, and Address. This form auto assigns each entry a unique id string (U_ID) and then this data is later output to a csv with headers and ...
0
votes
2answers
21 views
How do i move all the numbers to allign with the columns
CANOEING = 3.5068
HIKING = 6
ROLLER_BLADING = 7.5068
TAE_KWON_DO = 10.3014
TAI_CHI = 3
body_mass = float(input("Enter your body mass: "))
canoeing = 0
hiking = 0
roller_blading = 0
tae_kwon_do = 0
...
2
votes
2answers
53 views
Python sorting a text file?
So I know how to import a texfile and sort numbers such as:
1
6
4
6
9
3
5
But I don't know how to sort a data that looks like:
Merchant_9976 20122
Merchant_9977 91840
Merchant_9978 92739
...
-1
votes
3answers
39 views
Reading a text file into list in python
I'm trying to learn python. This is a little test program that I made to read a text file into a list. This is the text file:
42 1
35 5
50 2
41 6
42 3
48 4
And this is my codes:
score = [];
for i ...
-5
votes
1answer
20 views
How do I make a button in python operate a counter?
How do I write a program in Python that shows a window with a button and a label. I want the label to update each time the button is pressed and show how many times it has been pressed.
This code will ...
1
vote
0answers
17 views
Unable to display PIL Image inside Canvas
I'm trying to display a PIL.Image inside a tkinter.Canvas:
from tkinter import *
from PIL import Image, ImageTk
root = Tk()
root.geometry('500x400')
canvas = Canvas(root, width=500, height=400)
...
1
vote
2answers
32 views
Printing a dictionary after using sorted(dict.values(), …)
I'm attempting to print out a dictionary of dictionaries in Python 3.4. The dictionary is filled by a text parser that is parsing requirement text files. Each requirement (the keys) added to the ...
-1
votes
1answer
26 views
Python3 how do i login to a web page? [on hold]
I'm wondering how you can login to a wepage like Facebook, Twitter, Gmail etc and then get back information if the login was succesfull or not in Python 3.
Example code:
url = ...
-1
votes
2answers
35 views
Dictionaries: How to get duplicate input by the user and count how many times it was entered?
names = []
print("Duplicate names won't be in the list!") # reminder
while True:
userInput = input("Enter a name: ")
if userInput == "": # condition to terminate loop
print("You've ...
-1
votes
0answers
18 views
python idle show window without mainloop
I'm python nooby. Im trying to show a window and output to it without issuing the 'mainloop' command (ie carry on with script). I'm using Python 3.4.1, idle 3.4.1, tkinter 8.3.1. Here is a script I've ...
0
votes
1answer
13 views
PySide - resetting the mainwindow central widget from within the central widget
I'm trying to create a GUI window which opens with a central widget showing several options to choose from. Each option replaces the central widget with a new window based on the users choice. Similar ...
0
votes
1answer
45 views
How can I put one value in another list?
My program needs to accept inputs from the user, but the input is like Ted,24 , so every input will be separated by comma and I know putting them in a list will be a great idea but I also need to get ...
0
votes
2answers
29 views
check whether an element have attribute or not python3
I am using python3.4 and parsing an xml file by etree.
some of the node have attribute "meaning" and some of them have attribute "role" and some have both.
these nodes may have other attributes but ...
0
votes
1answer
38 views
Is there any way to “call a function” in python without incurring the usual performance hit?
I realize that sounds like a strange question, but someone might know a way around this, and that would be great. So here goes:
If I do something like:
%%timeit somelist[42]
Then I get times in ...
-1
votes
2answers
40 views
how to create a loop that ends with “done” python 3.4
Im trying to create a program that uses a list to store the names of some notable celebrities. I need to to use a loop to prompt the user for the names and to add them to the list. When the user ...
-1
votes
3answers
26 views
Is there a cost to using functools.partial()?
The higher-order function functools.partial() can create a new function as follows:
newf(arg1) = functools.partial( f, arg1, val )
which is obviously equivalent to just saying
def newf(arg1): ...
0
votes
0answers
30 views
.txt read to change global varibles
So I'm having player input there name. Then it is written to a file. then file is opened read then global variable is changed to what was in said file. This is eventually going to get worked into a ...
0
votes
1answer
6 views
Reverse Indexing w/ Step
I want to get every second digit from a string from right to left.
My code is:
def getDigit(creditCard):
for i in creditCard[::-2]:
print(i)
print(creditCard[::-2])
...
1
vote
1answer
28 views
Create scrollbar only when text length greater than text area
Here is some simple code:
from tkinter import *
from tkinter import ttk
rootwin = Tk()
roomtext = Text(rootwin)
roomtext.pack(side = 'left', fill = "both", expand = True)
rtas = ...
0
votes
1answer
24 views
Why is it true that string.encode('utf-8') != bytes(map(ord, string))?
What encoding do we consider bytes(map(ord, string)) is using? Why is it sometimes true that string.encode('utf-8') != bytes(map(ord, string))?
I ran into this problem when having client side ...
2
votes
0answers
29 views
Which 2to3 fixers output valid Python 2 code?
2to3 is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code
Consider the forty fixers listed at ...
1
vote
1answer
30 views
How does inheritance work with kwargs in Python 3?
Considering the following sample code:
#!/usr/bin/python3
class Parent:
def __init__(self, **kwargs):
# Expect data1, data2
self.values = kwargs
# Accessor method to set ...
-6
votes
2answers
53 views
Write a Python program that repeatedly asks the user to input coin values until the total amount matches a target value
Write a Python program that repeatedly asks the user to input coin values until
the total amount matches a target value. The target value is a randomly
generated integer between 1 and 99 ...
0
votes
1answer
15 views
Pillow OSError when loading into tkinter using Python 3.4
I am loading an image from a server, and I keep getting this error when I use Base64 on the data.
Here's my code:
import tkinter as tk
from PIL import ImageTk
root = tk.Tk()
import urllib.request
...
-3
votes
2answers
47 views
Why does my window reopen when closed?
I was testing my friend's Tkinter code, and came across this bizarre behaviour.
When I use the Windows 'X' button (top-right of window) to close this Tk window (class/method?), it closes, then ...
0
votes
1answer
9 views
Do I need to transform nominal variables to be distinct fields for sklearn random forest? [duplicate]
This is a sample of dataset I'm using to look at lapsed customers. I've converted categorical values to be numbers. However I believe that sklearn random forest will treat these fields as discrete ...
1
vote
0answers
37 views
Using for loops in python to print out a calorie burnt table
So I have this problem that requires me to print out a table of calories burnt according to body weight for several different times from 15 minutes to 90 minutes growing in the interval of 15 minutes.
...
0
votes
1answer
12 views
Encrypting unicode strings with pyaes
The following code works well:
import os, pyaes
key = os.urandom (16)
aes = pyaes.AESModeOfOperationCTR (key)
encrypted = aes.encrypt ('Hello world')
aes = pyaes.AESModeOfOperationCTR (key)
decrypted ...