pythonic

How to copy a variable number of elements in a list to a uniform list and store in MySQL using Python the most efficient way?

This is a sample list (each line has variable elements) : ['1', 'Tech', 'Code'] ['2', 'Edu'] ['3', 'Money', 'Sum', '176'] I have to insert this into a MySQL table which has 4 columns (max num. of elements in a value in a list). How to do this efficiently? I have a feeling my solution is the least efficient! Here is my solution : f...

Python Check if all of the following items is in a list

I found, that there is related question, about how to find if at least one item exists in a list: http://stackoverflow.com/questions/740287/python-check-if-one-of-the-following-items-is-in-a-list But what is the best and pythonic way to find whether all items exists in a list? Searching througth the docs I found this solution: >>> l =...

What practices would you consider "pythonic"?

If you google for "pythonic" you will mostly find the same three examples. There are a lot of questions here on stackoverflow that ask for how this and that can be done in a pythonoic way, so a collection of some nice pythonic code examples would be nice! ...

[Opinion] Accessing private variables when there's a getter/setter for them

I have a question about righteous way of programming in Python... Maybe there can be several different opinions, but here it goes: Let's say I have a class with a couple of private attributes and that I have implemented two getters/setters (not overloading __getattr__ and __setattr__, but in a more “Java-tistic” style): class MyClass: ...

"Caching" attributes of classes in Python

I'm writing a class in python and I have an attribute that will take a relatively long time to compute, so I only want to do it once. Also, it will not be needed by every instance of the class, so I don't want to do it by default in __init__. I'm new to Python, but not to programming. I can come up with a way to do this pretty easil...

Python - How to use underlying object's constructor as class method?

Please forgive the bad title - I had a hard time trying to think of a concise way to explain this. I have a Python class that will have some underlying objects of other classes. I want to be able to create these underlying objects via a method of the original object. Let me try to explain better with an example: class Foo: def __in...

Cant determine whats causing an regex error, and would like some input on the efficiency of my program

Nearing what I would like to think is completion on a tool I've been working on. What I've got going on is some code that does essentially this: open several files and urls which consist of known malware/phishing related websites/domains and create a list for each, Parse the html of a url passed when the method is called, pulling out a...