Tagged Questions
Python is a dynamically and strongly typed programming language whose design philosophy emphasizes code readability. Two significantly different versions of Python (2 and 3) are in use. Please mention the version that you are using when asking a question about Python.
1
vote
3answers
23 views
How to efficiently catch an exception and check if argument is not None
Imagine that you have a function that in some error cases gives exceptions and in some returns None (it was not designed by me and I need to use it). Now, you need to handle these errors, but in an ...
0
votes
0answers
8 views
django-rest-framework with optional image upload
I have the following model where an image might be uploaded or not. I want people to upload an image but not see the image option when they view the post via the API
class Post(models.Model):
...
0
votes
0answers
15 views
python -m details in debugger
I'm trying to understand the steps that are involved when invoking the -m option. Using the debugger, I see that directly after my __init__.py is run, I'm taken to a set of pkgutil steps and then I ...
0
votes
0answers
16 views
Python How do you mock a function which has decorator apply to it in a unit test?
@transaction.commit_manually
def main_function():
....
How to overcome the transaction decorator in unittest test module. Can someone help me here on how to patch/mock transaction decorator or mock ...
0
votes
0answers
9 views
How Do I Set the Class Name of a Python wxWidgets Application Window?
I need to set the class name of a Python wxWidgets application window on Linux (Ubuntu). By default it is set to "python."
I have tried calling the SetClassName method on the app and main window ...
1
vote
1answer
26 views
The flow of a Recursive Call
I looked for answers for this question but most were given in programming languages other than Python.
Now in this code:
def f(n):
if n==0:
return 1
...
0
votes
0answers
19 views
Minimization values for a function
I have got function - non linear(I thk), and a set of variable
S={(x1,y1),(x2,y2)...}.
The objective is to find the value for x and y such that
sum of( max(|x-xi|,|y-yi|)) for each (xi,yi) ...
0
votes
5answers
34 views
Import all classes without specifying each one of them in python
i'm new to python and just created a few classes in a file called sample.py
class Student:
Name = ''
Age = ''
Gender = ''
class Employee:
EmpName = ''
EmpAge = ''
...
4
votes
0answers
27 views
Numba slow when assigning to an array?
Numba seems to be a great solution for accelerating the execution of numeric code. However, when there are assignments to an array Numba seems to be slower than standard Python code. Consider this ...
1
vote
1answer
10 views
Google App Engine database check if row exists by field
Using Google App Engine with python and their database, and trying to simply see if a given row already exists.
result = db.GqlQuery(
"SELECT phone WHERE phone = :1", ...
0
votes
0answers
10 views
Working with set_index in Pandas DataFrame
Using an imported CSV file, I indexed the DataFrame like this...
rdata.set_index(['race_date', 'track_code', 'race_number', 'horse_name'])
This is what a section of the DataFrame looks like...
...
1
vote
3answers
34 views
How to print out the results:
I am trying to print this code but I keep getting errors when I use the print command in Python 2.7
So I pretty much understand how the interpreter reads and executes this program. What would be the ...
3
votes
0answers
24 views
Saving dictionaries to file (numpy and Python 2/3 friendly)
I want to do hierarchical key-value storage in Python, which basically boils down to storing dictionaries to files. By that I mean any type of dictionary structure, that may contain other ...
-2
votes
0answers
38 views
why exec can't acquire the result of python command
the test.py will return a filename like this(in terminal is ok):
sudo python test.py
2013_8_2-10_22_35.info
PHP codes:
exec("sudo python test.py",$rst_arr,$return_var);
...
0
votes
1answer
15 views
'dict' object has no attribute 'widgetName' error tkinter python3
First the code:
main.py
import string
from app import App
group1=[ "spc", "bspc",",","."]#letters, space, backspace(spans mult layers)
# add in letters one at a time
for s in string.ascii_lowercase:
...