call a variable of a string

I am working on a python hangman game and have my graphics based on a variable, lives, so when you have 1 lives, the corresponding picture appears. i put my graphics into definitions and want to call them from that. Here's my code so far: if life== 1

Could someone explain how the offset is used in this code?

I'm solving sample problems while simultaneously trying to learn Python %\ ... but the problem book I got has problems and solutions in Java, so I'm trying to convert back and forth between the two languages. I just learned how bit shifting works and

Rank of a permutation

so there was a question I wasn't able to solve mainly because of computing power or lack thereof. Was wondering how to code this so that I can actually run it on my computer. The gist of the questions is: Let's say you have a string 'xyz', and you wa

Xlwings runpython installation fails

I'm trying to use xlwings on mac (10.11.5) with Excel 2016 for Mac (Version 15.23.2), but I get stuck pretty fast. When I run xlwings runpython install I get the following error: $ xlwings runpython install Traceback (most recent call last): File "/u

Empty string instead of an unmatched group error

I have this piece of code: for n in (range(1,10)): new = re.sub(r'(regex(group)regex)?regex', r'something'+str(n)+r'\1', old, count=1) It throws the unmatched group error. But if it is unmatched, I want to add empty string there instead of throwing a

How to draw the table 1d C as surface in python

Say I have a one-dimensional array of size NxN in C which I think of as a two-dimensional array, i.e. every N entries, a new row begins. I would like to visualise this array by laying it onto a plane and then treating every entry as the height of the

Python Regex - find a string pattern in a word

I'm getting false positives in python for the following example. I'm trying to find if a key word exist in a string. The problem is that the string has words connected by usually an underscore or hyphen so I only want positive result if the keyword e

Applying the if statement for the pandas column

I have a Probability column, some of the values are greater then 1. I am trying to iterate over every row of that column and change values to 0.99 for all > 0.99. Also I need to see if column 1 is equal to column 2. If yes Probability must be 0. And

Naive Bayes: Unbalanced Test Data Set

I am using scikit-learn Multinomial Naive Bayes classifier for binary text classification (classifier tells me whether the document belongs to the category X or not). I use a balanced dataset to train my model and a balanced test set to test it and t

Flask-Admin Displaying the Many-to-Many Field

I develop an application using Flask. I use Postgres db (psycop2), SQLAlchemy and Flask-Admin for admin interface. And I got a problem and can't find a solution. I have many-to-many relationship between articles and tags tables it's clear. In the Fla

Django WSGI Apache VirtualHost, returning a 404 error

Ubuntu 12.04 Apache 2.2.2 Python 3.2.3 Django 1.6.1 I followed directions at Using mod_wsgi to Serve Applications on Ubuntu 12.04, for setting up a WSGI for my Django on Apache. Problem is, the VirtualHost domain is now returning a confusingly weird

Cython command to force explicit declaration of all variables

In Cython it is known that an undeclared variable type carries more overhead that slows down the whole process. If this unknown variable type is used inside a nested loop like: def test(b, c, m, n, p): ctype double a for i in range(m) for j in range(

Python help! If / else statement

I have been learning python through code academy. It asked me to create a if else statement that prints the users input, but if there is no input print "empty". I did pass the tutorial but when there is a user input it prints both the users inpu

Optimize the solution for Project Euler 12 (Python)

I have the following code for Project Euler Problem 12. However, it takes a very long time to execute. Does anyone have any suggestions for speeding it up? n = input("Enter number: ") def genfact(n): t = [] for i in xrange(1, n+1): if n%i == 0:

Python dynamic execution

I have a list of dictionary items stored in variable List_dicts, and I have to write a selected list of items from the above list into a file. given below my python function: def write_items(List_dicts,key_list): #List_dicts contains the list if dict

Python Regex with IMDB Top 250 list

I'm kind of just getting started with Python, and I'm trying to match the top 250 movies on IMDB with this malfunctioning code: import urllib2 import re def main(): response = urllib2.urlopen('') html = en

Creating PDF files in Python with Pisa / xhtml2pdf

I know there are a lot of questions based on pdf creation in Python but I haven't seen anything based on creating pdfs with Pisa or xhtml2pdf. Here is my code. pisa.pisaDocument(cStringIO.StringIO(a).encode('utf-8'),file('mypdf.pdf','wb')) and then p

Python dictionary with variables as keys

I'm a Python newbie trying to parse a file to make a table of memory allocations. My input file is in the following format: 48 bytes allocated at 0x8bb970a0 24 bytes allocated at 0x8bb950c0 48 bytes allocated at 0x958bd0e0 48 bytes allocated at 0x8bb

Problem when processing static files in Django

I have my css file in /var/www/media/static/style.css and added (r'^media/(?P<path>.*)$', 'django.views.static.serve',{'document_root': '/var/www/media/static'}), to my urls but when I go to http://localhost:8000/media/style.css I get: "Page no

How to group tkinter?

I am distributing an app that uses the Python/C API. I have all standard python modules in which is basically an archive of the Lib folder in the python install directory. Here is the problem - most common modules like sys and io work fi

3D Math Library for Python

i'm looking for a 3d math library in python or with python bindings. it needs to handle rotation, translation, perspective projection, everything basically. what im NOT looking for is a library aimed at drawing on the screen, googling for hours only