A friend sent me some Tkinter/Tix code, but it was for Python 2: I have Python 3, I have no Tix installed, and program crashes. After some searching I’ve changed the code to: Thats what I found on the internet. I have no idea if this is a right approach. But code still does no run it crashes on I
Tag: python-3.x
Remove comma and change string to float
I want to find “money” in a file and change the string to float , for example, I use regular expression to find “$33,326” and would like to change to [33326.0, “$”] (i.e., remove comma, $ sign and change to float). I wrote the following function but it gives me an error Can you help me debug my code? Answer
How can I simulate 2.x’s tuple unpacking for lambda parameters, using 3.x?
In Python 2, I can write: But that is not supported in 3.x: The straightforward workaround is to index explicitly into the tuple that was passed: This is very ugly. If the lambda were a function, I could do But because the lambda only supports a single expression, it’s not possible to put the x, y = p part into
Why is my Project Euler problem #1 code returning the wrong result?
Problem 1 Project Euler, which asks you to find the sum of all multiples of 3 or 5 below 1000, so 3 + 5 + 6 + 9, etc. The correct answer is 233168 but my code is returning 266333. I’m not looking to use a different method, I’m wondering why this code isn’t working as is, from the debugging
Install opencv for Python 3.3
Is OpenCV still not available for Python 3.3 and do I really have to downgrade to Python 2.7 to use it? I didn’t find much about it on the internet, only some posts from 2012 that OpenCV wasn’t yet ported to be used in Python 3.x. But now it’s 2014 and after trying to install the latest OpenCV 2.4.x and
how to make each key-value of a dictionary print on a new line?
If I have a given dictionary like this: how do I make each key-value print on a new line? well its long but here is the code I’m using to get this dictionary. I pretty much added each key-value to the dictionary. So i figured out the shortest word and then I added that to the dictionary. I noticed it
Create a typewriter-effect animation for strings in Python
Just like in the movies and in games, the location of a place comes up on screen as if it’s being typed live. I want to make a game about escaping a maze in python. At the start of the game it gives the background information of the game: Under the variables, I tried to do a for loop for
Using len for text but discarding spaces in the count
So, I am trying to create a program which counts the number of characters in a string which the user inputs, but I want to discard any spaces that the user enters. Using this, I can get the number of the characters in each word, without spaces, but I don’t know how to add each number together and print the
Mergesort with Python
I couldn’t find any working Python 3.3 mergesort algorithm codes, so I made one myself. Is there any way to speed it up? It sorts 20,000 numbers in about 0.3-0.5 seconds Answer You can initialise the whole result list in the top level call to mergesort: Then for the recursive calls you can use a helper function to which you
How to properly use the “choices” field option in Django
I’m reading the tutorial here: https://docs.djangoproject.com/en/1.5/ref/models/fields/#choices and i’m trying to create a box where the user can select the month he was born in. What I tried was Is this correct? I see that in the tutorial I was reading, they for some reason created variables first, like so Why did they create those variables? Also, the MONTHS_CHOICES is in