🌐
Stack Overflow
stackoverflow.com › questions › tagged › python
Newest 'python' Questions - Stack Overflow
I'm trying a program in Python that starts with from cs50 import get_string s = get string("Do you agree? ") The problem is cs50 in my VS Code is showing an error/warning: import "...
🌐
Stack Overflow
stackoverflow.blog › python
python - Stack Overflow
April 30, 2026 - Standard operators make for clean, readable code. With dunder methods, you can add these operators to your own classes. ... Here's a collection of resources on how to get started using Python.
Discussions

Python Stack Overflow
Use a loop instead of recursion. More on reddit.com
🌐 r/learnpython
10
1
August 13, 2021
Python for beginners - Stack Overflow
Python programming: I need to write a program that takes two inputs of military time. For example,(0900,1700) and output the time differences of the two input in numbers in hours, minutes ... I have tried the code below, but the output was just my input. More on stackoverflow.com
🌐 stackoverflow.com
How to design code in Python? - Stack Overflow
I'm coming from Java and learning Python. So far what I found very cool, yet very hard to adapt, is that there's no need to declare types. I understand that each variable is a pointer to an object, but so far I'm not able to understand how to design my code then. More on stackoverflow.com
🌐 stackoverflow.com
Am i still a python programmer if use stack overflow a lot and finish projects?
You'd be a terrible developer if you didn't. More on reddit.com
🌐 r/learnpython
156
410
May 1, 2020
🌐
GitHub
github.com › drathier › stack-overflow-import
GitHub - drathier/stack-overflow-import: Import arbitrary code from Stack Overflow as Python modules. · GitHub
If that answer doesn’t have any valid python · code, it checks the next highest voted answer for code blocks. >>> from stackoverflow import quick_sort, split_into_chunks >>> print(quick_sort.sort([1, 3, 2, 5, 4])) [1, 2, 3, 4, 5] >>> print(list(split_into_chunks.chunk("very good chunk func"))) ['very ', 'good ', 'chunk', ' func'] >>> print("I wonder who made split_into_chunks", split_into_chunks.__author__) I wonder who made split_into_chunks https://stackoverflow.com/a/35107113 >>> print("but what's the license?
Starred by 3.7K users
Forked by 130 users
Languages: Python
🌐
GeeksforGeeks
geeksforgeeks.org › python › auto-search-stackoverflow-for-errors-in-code-using-python
Auto Search StackOverflow for Errors in Code using Python - GeeksforGeeks
July 23, 2025 - execute_return(cmd): On the first function, we are going to write code to read and run python file, and store its output or error. mak_req(error): This function will make an HTTP request using Stack Overflow API and the error we get from the ...
🌐
Reddit
reddit.com › r/learnpython › python stack overflow
r/learnpython on Reddit: Python Stack Overflow
August 13, 2021 -

Hello! I am new to python. I created a script/bot, and its function is work until closed.

That bot has a main() function that one way or another calls itself after a 1 minute timer.

After some time i noticed that it crashed and closed Tested again but now in Visual Studio Code and after 18 hours it crashed again with fatal error stack overflow.

Went in and created a separate script with a main function calling itself and after 1035 loops it caused stack overflow. Now 1035*1minute is about 18 hours.

How can i create an infinite script without causing stack overflow?

Thanks!

🌐
Stack Overflow
stackoverflow.blog › 2021 › 07 › 14 › getting-started-with-python
Getting started with... Python - Stack Overflow
July 14, 2021 - Some regard it as an ideal language ... mean all programs are visually consistent, and code written in Python is often more concise than the equivalent in other languages....
🌐
Stack Overflow
stackoverflow.com › questions › 18754276 › python-for-beginners
Python for beginners - Stack Overflow
Python programming: I need to write a program that takes two inputs of military time. For example,(0900,1700) and output the time differences of the two input in numbers in hours, minutes ex: pr...
🌐
Stack Overflow
stackoverflow.com › documentation › python › topics
Documentation - Stack Overflow
Stack Overflow | The World’s Largest Online Community for Developers
Find elsewhere
🌐
Python
peps.python.org › pep-0651
PEP 651 – Robust Stack Overflow Handling | peps.python.org
However, there is an expectation that any code that could run with the recursion limit set to the previous default value, will continue to run. Many operations in Python perform some sort of call at the C level. Most of these will continue to consume C stack, and will result in a StackOverflow exception if uncontrolled recursion occurs.
Top answer
1 of 6
32

This is a very healthy question.

Duck typing

The first thing to understand about python is the concept of duck typing:

If it walks like a duck, and quacks like a duck, then I call it a duck

Unlike Java, Python's types are never declared explicitly. There is no restriction, neither at compile time nor at runtime, in the type an object can assume.

What you do is simply treat objects as if they were of the perfect type for your needs. You don't ask or wonder about its type. If it implements the methods and attributes you want it to have, then that's that. It will do.

def foo(duck):
    duck.walk()
    duck.quack()

The only contract of this function is that duck exposes walk() and quack(). A more refined example:

def foo(sequence):
    for item in sequence:
        print item

What is sequence? A list? A numpy array? A dict? A generator? It doesn't matter. If it's iterable (that is, it can be used in a for ... in), it serves its purpose.

Type hinting

Of course, no one can live in constant fear of objects being of the wrong type. This is addressed with coding style, conventions and good documentation. For example:

  • A variable named count should hold an integer
  • A variable Foo starting with an upper-case letter should hold a type (class)
  • An argument bar whose default value is False, should hold a bool too when overridden

Note that the duck typing concept can be applied to to these 3 examples:

  • count can be any object that implements +, -, and <
  • Foo can be any callable that returns an object instance
  • bar can be any object that implements __nonzero__

In other words, the type is never defined explicitly, but always strongly hinted at. Or rather, the capabilities of the object are always hinted at, and its exact type is not relevant.

It's very common to use objects of unknown types. Most frameworks expose types that look like lists and dictionaries but aren't.

Finally, if you really need to know, there's the documentation. You'll find python documentation vastly superior to Java's. It's always worth the read.

2 of 6
7

I've reviewed a lot of Python code written by Java and .Net developers, and I've repeatedly seen a few issues I might warn/inform you about:

Python is not Java

Don't wrap everything in a class:

Seems like even the simplest function winds up being wrapped in a class when Java developers start writing Python. Python is not Java. Don't write getters and setters, that's what the property decorator is for.

I have two predicates before I consider writing classes:

  1. I am marrying state with functionality
  2. I expect to have multiple instances (otherwise a module level dict and functions is fine!)

Don't type-check everything

Python uses duck-typing. Refer to the data model. Its builtin type coercion is your friend.

Don't put everything in a try-except block

Only catch exceptions you know you'll get, using exceptions everywhere for control flow is computationally expensive and can hide bugs. Try to use the most specific exception you expect you might get. This leads to more robust code over the long run.

Learn the built-in types and methods, in particular:

From the data-model

str

  • join
  • just do dir(str) and learn them all.

list

  • append (add an item on the end of the list)
  • extend (extend the list by adding each item in an iterable)

dict

  • get (provide a default that prevents you from having to catch keyerrors!)
  • setdefault (set from the default or the value already there!)
  • fromkeys (build a dict with default values from an iterable of keys!)

set

Sets contain unique (no repitition) hashable objects (like strings and numbers). Thinking Venn diagrams? Want to know if a set of strings is in a set of other strings, or what the overlaps are (or aren't?)

  • union
  • intersection
  • difference
  • symmetric_difference
  • issubset
  • isdisjoint

And just do dir() on every type you come across to see the methods and attributes in its namespace, and then do help() on the attribute to see what it does!

Learn the built-in functions and standard library:

I've caught developers writing their own max functions and set objects. It's a little embarrassing. Don't let that happen to you!

Important modules to be aware of in the Standard Library are:

  • os
  • sys
  • collections
  • itertools
  • pprint (I use it all the time)
  • logging
  • unittest
  • re (regular expressions are incredibly efficient at parsing strings for a lot of use-cases)

And peruse the docs for a brief tour of the standard library, here's Part 1 and here's Part II. And in general, make skimming all of the docs an early goal.

Read the Style Guides:

You will learn a lot about best practices just by reading your style guides! I recommend:

  • PEP 8 (anything included in the standard library is written to this standard)
  • Google's Python Style Guide
  • Your firm's, if you have one.

Additionally, you can learn great style by Googling for the issue you're looking into with the phrase "best practice" and then selecting the relevant Stackoverflow answers with the greatest number of upvotes!

I wish you luck on your journey to learning Python!

🌐
Plain English
plainenglish.io › blog › 30-highest-voted-python-questions-on-stack-overflow
30 Highest-Voted Python Questions on Stack Overflow
Let's check out how deeply you know Python programming. What does the “yield” keyword do? Asked by: Alex. S. ... How do I merge two dictionaries in a single expression (taking union of dictionaries)? Asked by: Carl Meyer ... https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-a-list-of-lists Asked by: Emma
🌐
Codementor
codementor.io › python › tutorial › stack-overflow-python-expert-answers-questions
Python Q&A with #1 Stack Overflow Python Expert | Codementor
Python cannot optimize classes that don’t have assigned variables, as it cannot know what your class names refer to until you run the program. Class names themselves are dynamic, so the code could in principle swap out those names into something else.
🌐
Stack Overflow
stackoverflow.com › questions › tagged › python-3.x
Newest 'python-3.x' Questions - Stack Overflow
I've recently started coding with "Ursina" in Python and I have problems with the performance when I have plenty entities in the scene.
🌐
PyPI
pypi.org › project › stackoverflow
stackoverflow · PyPI
January 27, 2021 - If that answer doesn’t have any valid python · code, it checks the next highest voted answer for code blocks. >>> from stackoverflow import quick_sort, split_into_chunks >>> print(quick_sort.sort([1, 3, 2, 5, 4])) [1, 2, 3, 4, 5] >>> print(list(split_into_chunks.chunk("very good chunk func"))) ['very ', 'good ', 'chunk', ' func'] >>> print("I wonder who made split_into_chunks", split_into_chunks.__author__) I wonder who made split_into_chunks https://stackoverflow.com/a/35107113 >>> print("but what's the license?
🌐
IQCode
iqcode.com › code › python › stackoverflow
stackoverflow Code Example
stackoverflow.c stackoverflow.co using stackoverflow stack overvlow define what is stack overflow stackoverflow css stackoverflow. com stackoverflow browser stack on overflow define stack overflow my stackoverflow looks different site stackoverflow.com stack overflow website what's COM stackoverflow stack overflow site : stack overflow when was stackoverflow made stack overllflow what is stack overflow used for What is Stack Overflow? how does stack overflow work stack overflow&acute; stackoverflow js stack ovberflow stack overflow.org stackoverflow in js what does $.when() do stackoverflow st
🌐
Stack Overflow
stackoverflow.com
Newest Questions - Stack Overflow
I am making a calculator app in Python using Tkinter, but I need to make a preview too so the person can know what they are typing.
🌐
Kaggle
kaggle.com › datasets › stackoverflow › pythonquestions
Python Questions from Stack Overflow | Kaggle
October 8, 2019 - Full text of Stack Overflow Q&A about the Python programming language
🌐
LibHunt
libhunt.com › l › python › topic › stackoverflow
Top 11 Python stackoverflow Projects | LibHunt
Which are the best open-source stackoverflow projects in Python? This list will help you: rebound, stack-overflow-import, socli, only-stackoverflow, sotoki, codefree, and forumscraper.