756 Answered Questions for the topic Python
07/12/19
How to execute raw SQL in SQLAlchemy-flask app?
How do you execute raw SQL in SQLAlchemy?
I have a python web app that runs on flask and interfaces to the database through SQLAlchemy.
I need a way to run the raw SQL. The query involves...
more
07/12/19
Use python to calculate a special limit?
I want to calculate this expression:
(1 + 1 / math.inf) ** math.inf,
which should evaluates to e. However Python returns 1. Why is that?
=====UPDATE========
What I want to do here is to...
more
07/12/19
MATLAB Engine API for Python: changing parameters of the running simulation?
I am using the `MATLAB Engine API for Python`. I have a shared engine in a Python script and then another Python script connected to this shared engine. I would like to ask whether it is possible...
more
07/12/19
Python Tkinter: Attempt to get widget size?
I am trying to find the size of my window by using the `winfo_geometry()` function but it ends up returning `1x1+0+0`
I have also tried `winfo_height, winfo_width` but i keep getting `1`
### CODE...
more
07/12/19
How to perform OR condition in django queryset?
I want to write a Django query equivalent to this SQL query:
SELECT * from user where income >= 5000 or income is NULL.
How to construct the Django queryset filter?
...
more
Matlab - Iterating through an array and appending to a new one?
I got an array that is a audio recording, and I'd like to add some noise on it so later I can remove it in Simulink and compare the original to the one that I removed the noise.
My problem is that...
more
What's the best way to calculate a 3D (or n-D) centroid?
As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I'm doing it in a way that seems simple but naive -- by taking the average of each set of...
more
07/12/19
How to efficiently determine if a set of points contains two that are close?
I need to determine if a set of points (each given by a tuple of floats, each of which is in [0, 1]) contains two that are within some threshold, say 0.01, of each other. I should also mention that...
more
I would like to be able to compare values in one CSV with a nominal set of values in another?
I have been given the task of injecting faults into a system and finding deviations from a norm. These deviations will serve as the failures of the system. So far we've had to detect these faults...
more
Python Directory
06/27/19
How do I list all files of a directory?
How can I list all files of a directory in Python and add them to a `list`?
06/26/19
How can I change the default Python version on Snow Leopard?
I recently upgraded my Mac OS X 10.5 Leopard install to 10.6 Snow Leopard, and with that came an upgraded version of Python, 2.6.1 (instead if 2.5.1). Now when I type `python` in the Terminal i...
more
How to get the current time in Python?
What is the module/method used to get the current time?
Why is ''>0 True in Python?
In Python 2.6.4:
>> ''>0
True
Why is that?
Python Module
06/25/19
What is __init__.py for?
What is `__init__.py` for in a Python source directory?
06/23/19
python build a dynamic growing truth table?
My question is simple:
"how to build a dynamic growing truth table in python in an elegant way?"
for n=3
for p in False, True:
for q in False, True:
for r in False, True:
print '|{0} | {1} |...
more
06/23/19
Python class inherits object?
Is there any reason for a class declaration to inherit from ``object``?I just found some code that does this and I can't find a good reason why. class MyClass(object): # class code...
more
06/22/19
How do I add Python to the Windows PATH?
I want to be able to run Python commands from the Windows CMD. However, if I don't specify Python's full path for each command, I get an error saying "*Python is not recognized as an internal or...
more
06/22/19
Windows IDE for coding python?
PyCharm seems to be fine but I think it's not that good since is hard to step into and step over than Visual Studio. However Visual Studio seems to lack what PyCharm is able to do which is create a...
more
Python List
06/21/19
How do I check if a list is empty?
For example, if passed the following: a = []How do I check to see if `a` is empty?
06/21/19
What is the meaning of a single and a double underscore before an object name?
Can someone please explain the exact meaning of having leading underscores before an object's name in Python? Also, explain the difference between a single and a double leading underscore. Also,...
more
How do I download a file over HTTP using Python?
I have a small utility that I use to download a MP3 from a website on a schedule and then builds/updates a podcast XML file which I've obviously added to iTunes.The text processing that...
more
Python File
06/18/19
How do I remove/delete a folder that is not empty with Python?
I am getting an 'access is denied' error when I attempt to delete a folder that is not empty. I used the following command in my attempt: `os.remove("/folder_name")`. What is the most effective way...
more
Python Object
06/17/19
Calling a function of a module by using its name (a string)?
What is the best way to go about calling a function given a string with the function's name in a Python program. For example, let's say that I have a module `foo`, and I have a string whose...
more
06/15/19
Exact change in Python
Write a program with total change amount as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are dollars, quarters, dimes, nickels, and...
more
Understanding slice notation?
I need a good explanation (references are a plus) on Python's slice notation. To me, this notation needs a bit of picking up. It looks extremely powerful, but I haven't quite got my head around it.
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.