i need to identify who raise an exception to handle better str error, is there a way ?
look at my example:
try:
os.mkdir('/valid_created_dir')
os.listdir('/invalid_path')
except OSError, msg:
# here i want i way to identify who raise the exception
if is_mkdir_who_raise_an_exception:
do some things
if is_listdir_who_raise_an_exception:
do other things ..
how i can handle this, in python ?
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
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.)
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.
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.
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)
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
Hello:
I'm looking for an easy-to-use graphics lib for python that can output to screen as well as pdf. So, I would use code to draw some stuff (simple prims like ovals, rectangles, lines and points) to screen and then when things look good, have it output to pdf.
Make sense?
Thanks!
Blue
Perhaps by compiling a list of common errors or coding style differences PHP coders make when first starting out withPython, we can help to avoid headaches later on. (Or at least I can :).
For a long time I was using Python 2.5 to do all this fine but recently upgraded to 2.7 since building stuff for 2.5 is a real pain. I also updated mod_wsgi to 3.3 for Python 2.7.
Everything is working fine with Apache + mod_wsgi on CentOS and also in the Django runserver on both Windows and CentOS, but not with Apache + mod_wsgi on Windows.
Whenever I try to access a page in my Django app I get the following (note that Apache starts fine):
ImportError at /
DLL load failed: The specified module could not be found.
Which is caused by things like:
from Crypto.Cipher import AES
Etree and others cause the exact same error and it is not limited to any specific packages. Anything with pyd files fails.
Googling around suggests reinstalling Python "for all users", but the installer doesn't give you that option anymore anyway. For good measure I've tried reinstalling Python 2.7 as an administrator and also told it to register itself as the default version of Python but neither helped.
I think the solution might have something to do with:
The fact that I have 2.5, 2.6 and 2.7 installed on this machine and mod_wsgi might be loading the DLLs for 2.5 instead of 2.7.
Something to do with WSGIPythonPath, which I usually don't need to set.
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.
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?
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.
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.)
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.
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
I have been able to read an excel cell value with xlrd using column and row numbers as inputs. Now I need to access the same cell values in some spreadsheets that were saved in .ods format.
So for example, how would I read the value stored in cell E10 from a .ods file from python?
With a scripting language like python (or php), things are not compiled down to bytecode like in .net or java.
So does this mean that on every request, it has to go through the entire application and parse/compile it? Or at least all the code required for the given call stack?