Is there any way to run one last command before a running Python script is stopped by being killed by some other script, keyboard interrupt etc.
Thanks for your help!
Basically, I've got a homework task of programming a text based battle simulator in Python. Obviously I've gone with pokémon...
I would like the enemy to be randomly selected, however I don't know how to randomly select from a list...
foo = ['a', 'b', 'c', 'd', 'e']
from random import choice
print choice(foo)
This is what I've been told to try but I've got no modules or anything imported...
How can I make this work,
appreciated.
Hello,
Lets say I have a time 04:05 and the timezone is -0100 (GMT)
I want to calculate the new time which will be 03:05
Is there any function in python to do that calculcation ?
Thanks
What is a good tool for PDF report generation in Python? I've checked out ReportLab, but it seems to be awfully low-level for what I want to do. My current hunch is to call TeX on the command-line and let it produce the PDF, but if there is something that is easier to work with (and looks professional - We'll send this to customers) I'd very much like a prod in the right direction.
I've finally figured out how to create a Python egg and gotten it to work. What do I do with it now? How do I use it? How do I ensure that everything was correctly included? (Simple steps please... not just redirection to another site. I've googled, but it's confusing me, and I was hoping someone could explain it in a couple of simple bullet points or sentences.)
A python program opens a new process of the C++ program and is reading the processes stdout.
No problem so far.
But is it possible to have multiple streams like this for communication? I can get two if I misuse stderr too, but not more. Easy way to hack this would be using temporary files. Is there something more elegant that does not need a detour to the filesystem?
PS: *nix specific solutions are welcome too
Hello,
how can I see if there is one active mic using python and windows 7?
I want to see if there is one wave in device ready to capture sound!
Thanks in advance :)
Hello,
My company wants to use Liferay for developing a portal and integrate Alfresco with it for document management.
But both Liferay and Alfresco are Java based and i would like to know if there are any alternatives to Liferay and Alfresco in PHP or Python.
Thank You
Which is the preferred way of defining class properties in Python and why? Is it Ok to use both in one class?
@property
def total(self):
return self.field_1 + self.field_2
or
total = property(lambda self: self.field_1 + self.field_2)
How do I learn where the source file for a given Python module is installed? (Is the method is different on Windows than Linux?)
(I want to look at the datetime module sources, but I thought I'd ask a more general question.)
ok so I am feeling a little stupid for not knowing this, but a coworker asked so I am asking here: I have written a python algorithm that solves his problem. given x 0 add all numbers together from 1 to x.
def fac(x):
if x > 0:
return x + fac(x - 1)
else:
return 0
fac(10)
55
first what is this type of equation is this and what is the correct way to get this answer as it is clearly easier using some other method?
With the IPTCInfo module under Python (http://snippets.dzone.com/posts/show/768 for more info) it's possible to read, modify and write IPTC info to pictures.
However, if a JPG doesn't already have IPTC information, the module simply raises an exception. It doesn't seem to be able to create and add this metadata information itself.
What alternatives are there? I've googled for the past hour but to no avail whatsoever.
I know that with an InnoDB table, transactions are autocommit, however I understand that to mean for a single statement? For example, I want to check if a user exists in a table, and then if it doesn't, create it. However there lies a race condition. I believe using a transaction prior to doing the select, will ensure that the table remains untouched until the subsequent insert, and the transaction is committed. How can you do this with MySQLdb and Python?
Is there a possibility to create any python object that will be not sortable? So that will be an exception when trying to sort a list of that objects?
I created a very simple class, didn't define any comparison methods, but still instances of this class are comparable and thus sortable. Maybe, my class inherits comparison methods from somewhere. But I don't want this behaviour.
I have the following structure in Python:
letters = [['a', 'b', 'c'], ['p', 'q', 'r', 's'], ['j', 'k', 'l']]
I would like to find all the possible combinations of letters in the order that they currently exist. For the example above this would be:
apj
apk
apl
aqj
aqk
aql
...
csk
csl
This seems like it should be a very simple thing to do but I cannot figure it out.
Hi all,
I am already familiar with python and socket usage and can send strings of text over these. But how would i go about sending, say, an MP3 file?
Perhaps by compiling a list of common errors or coding style differences PHP coders make when first starting out with Python, we can help to avoid headaches later on. (Or at least I can :).