Skip to content
Advertisement

Tag: python

Confusion about scoping in python classes

I am currently reviewing the python tutorials of python.org. I come from C++ and in the Classes tutorial (https://docs.python.org/3/tutorial/classes.html) I see that the scoping is similar to that in C++. It says the following about scoping and nesting: “At any time during execution, there are at least three nested scopes whose namespaces are directly accessible: – the innermost scope, which

Django Unit Test – IDs of created objects

Sample models.py models.py Suppose that I have written unit test/s: I was wondering if it’s safe to assume that the id’s of the created objects in setUp() method will always start at id 1 and so on and so forth? If not, is there a specific reason why if the test database is always destroyed after running all tests? Answer

boto3 s3 Object expiration “MalformedXML” error

I’m trying to set the lifecycle configuration of a subdirectory in Amazon S3 bucket by using boto3 put_bucket_lifecycle_configuration. I used this code from aws documentation as referece: I removed Transitions and added Expiration, to better fit my purpouses. Here is my code: The error I’m receiving is: What could be causing this error? Answer I followed @Michael-sqlbot suggestion and found

ModuleNotFoundError: No module named ‘sympy’

I’m on MacOSX Mojave 10.14.6 on a MacBook Pro 2015. So I pip installed sympy, right? I head over to my shell, run python3, and do: Just to be sure, I pip installed again just to make sure. My pip list also includes sympy as sympy 1.4. What’s wrong here? Is there another setup step I’ve missed? Answer Apparently all

Annotate 3D scatter plot on pick event

I want to show annotations on a 3D scatter plot when the user clicks on a point. The code I have shows the annotation once I move the plot after I click on a point. How can I make the annotation appear as soon as the user clicks on a point, without having to move the plot? Answer Add fig.canvas.draw_idle()

Get total amount of free GPU memory and available using pytorch

I’m using google colab free Gpu’s for experimentation and wanted to know how much GPU Memory available to play around, torch.cuda.memory_allocated() returns the current GPU memory occupied, but how do we determine total available memory using PyTorch. Answer In the recent version of PyTorch you can also use torch.cuda.mem_get_info: https://pytorch.org/docs/stable/generated/torch.cuda.mem_get_info.html#torch.cuda.mem_get_info

Match non-capturing group multiple times

I tried really hard to make a good title, but I’m not sure if I’m asking this right. Here’s my best attempt: I’m using Python’s flavor of regex I need to match numbers using named groups: but should not match: my best attempt so far has been: I’m using [sa-z] instead of a word-boundary because 15×20 are two different values.

Advertisement