This is a part of my homework assignment and im close to the final answer but not quite yet. I need to write a function that counts odd numbers in a list. Create a recursive function count_odd(l) which takes as its only argument a list of integers. The function will return a count of the number of list elemen…
Tag: python
SQLAlchemy: What’s the difference between flush() and commit()?
What the difference is between flush() and commit() in SQLAlchemy? I’ve read the docs, but am none the wiser – they seem to assume a pre-understanding that I don’t have. I’m particularly interested in their impact on memory usage. I’m loading some data into a database from a seri…
python: is it possible to attach a console into a running process
I just want to see the state of the process, is it possible to attach a console into the process, so I can invoke functions inside the process and see some of the global variables. It’s better the process is running without being affected(of course performance can down a little bit) Answer If you have a…
Python : terminology ‘class’ VS ‘type’
Just a simple question : when should I use the term ‘class’, and when should I use the term ‘type’ in Python ? is ‘class’ only for user-defined types, and ‘type’ for built-in types ? or now that everything is a type … should I use always ‘type’…
How do I convert a Python list into a C array by using ctypes?
If I have the follow 2 sets of code, how do I glue them together? How can I call the c_function with a contiguous list of elements in x? I tried to cast x to a c_void_p, but that didn’t work. I also tried to use something like but this gets a syntax error. The C code clearly wants the
Using a regular expression to replace upper case repeated letters in python with a single lowercase letter
I am trying to replace any instances of uppercase letters that repeat themselves twice in a string with a single instance of that letter in a lower case. I am using the following regular expression and it is able to match the repeated upper case letters, but I am unsure as how to make the letter that is being…
Interactively validating Entry widget content in tkinter
What is the recommended technique for interactively validating content in a tkinter Entry widget? I’ve read the posts about using validate=True and validatecommand=command, and it appears that these features are limited by the fact that they get cleared if the validatecommand command updates the Entry w…
Finding the most frequent character in a string
I found this programming problem while looking at a job posting on SO. I thought it was pretty interesting and as a beginner Python programmer I attempted to tackle it. However I feel my solution is quite…messy…can anyone make any suggestions to optimize it or make it cleaner? I know it’s pr…
Parsing the results of askopenfilenames()?
I’m trying to get a list of filenames from tkinter.filedialog.askopenfilenames() in Python 3.2. I was expecting the output to be a tuple (or maybe a list) with each element containing a filename. As far as I can tell, it’s returning a string with each element contained within curly-brackets {} lik…
How to update a plot in matplotlib
I’m having issues with redrawing the figure here. I allow the user to specify the units in the time scale (x-axis) and then I recalculate and call this function plots(). I want the plot to simply update, not append another plot to the figure. Answer You essentially have two options: Do exactly what you&…