Search Results
| Search type | Search syntax |
|---|---|
| Tags | [tag] |
| Exact | "words here" |
| Author | user:1234 user:me (yours) |
| Score | score:3 (3+) score:0 (none) |
| Answers | answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
| Views | views:250 |
| Code | code:"if (foo != bar)" |
| Sections | title:apples body:"apples oranges" |
| URL | url:"*.example.com" |
| Saves | in:saves |
| Status | closed:yes duplicate:no migrated:no wiki:no |
| Types | is:question is:answer |
| Exclude | -[tag] -apples |
| For more details on advanced search visit our help page | |
Results tagged with python
Search options not deleted user 110531
Python is a dynamically typed, high-level interpreted programming language. Its design focuses on clear syntax, an intuitive approach to object-oriented programming, and making the right way to do things obvious. Python supports modules and exceptions, and has an extensive standard module library. Python is general-purpose and thus used widely, from the web to embedded systems.
5 votes
What is the relationship between scope and namespaces in Python?
There is an excellent article on Python namespaces here. …
6 votes
Accepted
What argument passing mechanism does python use, and where is this officially documented?
In terms of official documentation, per the Programming FAQ: Remember that arguments are passed by assignment in Python. …
1 vote
Is it reasonable to use a decorator to instantiate a singleton in Python?
I think the simplest, most Pythonic way to implement a singleton class is with inheritance: class Singleton(object): _instances = {} def __new__(cls, *args, **kwargs): if cls not in …
4 votes
Accepted
What is ## used for?
The second hash therefore has no syntactic meaning in Python itself. … However, assuming you mean this specific "Interactive Editor for Python", one of its features is: Matlab-style cell notation to mark code sections (by starting a line with ##). …
2 votes
When and how should I use exceptions?
If I was writing a function def abe_is_alive(): I would write it to return True or False in the cases where I am absolutely certain of one or the other, and raise an error in any other case (e.g. …
2 votes
How would I change the precision of a variable in Python?
It is typical to compare floats using a tolerance, rather than by equality. This both avoids some of the issues with floating point arithmetic on computers and allows you to specify an appropriate lev …
7 votes
What exactly is this Python statement doing?
That is a list comprehension. Spread out a bit, it would look something like: h_data = [] for e in cube_edges: if cube_signs[e[0]] != cube_signs[e[1]]: h_data.append(estimate_hermite(f, d …
0 votes
Parent class using methods defined in child
One option is to make it clear to the IDE and your users that there is a method, but you can't use the base class version: class MyClass1(object): def func_2(self): raise NotImplementedE …
6 votes
Changing method signature while keeping backwards compatibility
In Python, it's "Easier to ask for forgiveness than permission" - it is common "Pythonic" practice to use exceptions and error handling, rather than e.g. if checking up-front ("Look before you leap") to …
12 votes
Accepted
Should I avoid using style like `for k, v in dict_sample.items()`?
I agree with you, and e.g. pylint would complain about those names too (albeit purely on a length basis). for k, v in ... gives the reader no helpful information about what they should be expecting …
1 vote
log method calls per object
Here is one way to do it, which increments a collections.Counter every time a callable attribute is accessed: class LoggingMixIn: def __init__(self, *args, **kwargs): self._log = Counter …
2 votes
Accepted
Could there be a use case for C# style auto-properties in Python
In Python, switching between an attribute and a property isn't a breaking change, it doesn't alter the interface at all, so there's not much point to an auto-property system. … Do you use the get/set pattern (in Python)? on SO. …