KKitForma.

Language

EnglishEnglishTürkçeTurkishDeutschGermanTool unavailable · open catalogEspañolSpanishTool unavailable · open catalogFrançaisFrenchTool unavailable · open catalogPortuguêsPortugueseTool unavailable · open catalogItalianoItalianTool unavailable · open catalogNederlandsDutchTool unavailable · open catalogPolskiPolishTool unavailable · open catalogРусскийRussianTool unavailable · open catalogУкраїнськаUkrainianTool unavailable · open catalogSvenskaSwedishTool unavailable · open catalogNorskNorwegianTool unavailable · open catalogDanskDanishTool unavailable · open catalogSuomiFinnishTool unavailable · open catalogČeštinaCzechTool unavailable · open catalogRomânăRomanianTool unavailable · open catalogΕλληνικάGreekTool unavailable · open catalogالعربيةArabicTool unavailable · open catalogעבריתHebrewTool unavailable · open catalogفارسیPersianTool unavailable · open catalogاردوUrduTool unavailable · open catalogहिन्दीHindiTool unavailable · open catalogবাংলাBengaliTool unavailable · open catalogதமிழ்TamilTool unavailable · open catalogతెలుగుTeluguTool unavailable · open catalogमराठीMarathiTool unavailable · open catalogગુજરાતીGujaratiTool unavailable · open catalog简体中文Chinese SimplifiedTool unavailable · open catalog繁體中文Chinese TraditionalTool unavailable · open catalog日本語JapaneseTool unavailable · open catalog한국어KoreanTool unavailable · open catalogTiếng ViệtVietnameseTool unavailable · open catalogไทยThaiTool unavailable · open catalogBahasa IndonesiaIndonesianTool unavailable · open catalogBahasa MelayuMalayTool unavailable · open catalogFilipinoFilipinoTool unavailable · open catalogKiswahiliSwahiliTool unavailable · open catalogAfrikaansAfrikaansTool unavailable · open catalogMagyarHungarianTool unavailable · open catalogБългарскиBulgarianTool unavailable · open catalogHrvatskiCroatianTool unavailable · open catalogSrpskiSerbianTool unavailable · open catalogSlovenčinaSlovakTool unavailable · open catalogSlovenščinaSlovenianTool unavailable · open catalogLietuviųLithuanianTool unavailable · open catalogLatviešuLatvianTool unavailable · open catalogEestiEstonianTool unavailable · open catalogCatalàCatalanTool unavailable · open catalogEuskaraBasqueTool unavailable · open catalog
← All topics and search

Python

Python environments, data handling, imports and runtime errors.

50 troubleshooting guides · Page 1 / 3

  1. Why does a Python function remember items from the previous call?

    A mutable default argument is created when the function is defined, not each time it runs. A default list can therefore become accidental shared state.

  2. Why do Python callbacks created in a loop all use the last value?

    A closure normally looks up the captured variable when called. The loop has already advanced by then.

  3. Why does changing a nested list also change its shallow copy?

    A shallow copy duplicates the outer container while retaining references to its children. `copy = original[:]` does not isolate nested lists.

  4. Why does removing items while iterating over a list skip some matches?

    Removing an element shifts later elements left while the iterator continues forward. The next matching item can move behind the iterator.

  5. Why does assigning later in a function cause UnboundLocalError earlier?

    An assignment makes a name local throughout that function unless declared otherwise. Reading it before that local assignment has no value to read.

  6. Why is a Python generator empty on the second pass?

    A generator is a consumable iterator, not a replayable collection. Once exhausted, another loop has nothing left to retrieve.

  7. How do I distinguish a missing dictionary key from a stored None value?

    `mapping.get(key)` returns `None` both for a missing key and for an explicitly stored `None`. That loses information when null is meaningful.

  8. Why does assigning the result of list.sort turn my list into None?

    `list.sort()` changes the existing list and returns `None`. It is an in-place operation, not a sorted-value constructor.

  9. How can each dataclass instance get its own list field?

    A mutable field must be constructed per instance rather than reused as a class-level default. Dataclasses provide `field(default_factory=list)` for that purpose.

  10. Why does a local file named json.py break import json?

    Python searches import locations in order, so a project file can shadow a standard-library module with the same name. The traceback may misleadingly resemble a circular import.

  11. Why does pip install succeed but the running Python cannot import the package?

    The installer and application may use different interpreters or virtual environments. A successful installation does not prove it reached the interpreter running your code.

  12. Why does opening a relative file work in the terminal but fail in a scheduled job?

    Relative filesystem paths resolve from the process working directory, which a scheduler may choose differently from your terminal. They are not automatically relative to the source file.

  13. How do I fix a UnicodeDecodeError without silently losing characters?

    A decoder is reading bytes using an encoding that does not match the file. Ignoring errors removes evidence and can corrupt identifiers or names.

  14. Why does a CSV export contain extra blank rows on Windows?

    The CSV writer already manages line endings, and text-mode newline translation can interfere when the file is opened with default newline handling.

  15. Why can Python not subtract an aware datetime from a naive one?

    A naive datetime has no timezone interpretation, while an aware datetime identifies an offset. Python refuses to guess whether the naive value means local time or UTC.

  16. How do I represent the repeated hour when daylight saving time ends?

    A local wall-clock time may correspond to two instants during a backward clock change. A timezone name alone does not always identify which occurrence was intended.

  17. Why does Decimal created from a float still show unexpected digits?

    Converting a float to Decimal preserves the float’s binary approximation. It cannot reconstruct the decimal text that existed before that approximation.

  18. Why does Python json.dumps emit NaN that another parser rejects?

    Python’s JSON encoder allows non-finite floating-point values by default, although they are outside the strict JSON number syntax. Other implementations may reject them.

  19. How do I pass a filename containing spaces to subprocess safely?

    Shell command strings mix executable arguments with shell syntax. Quoting them manually becomes fragile, especially across operating systems.

  20. Why can a subprocess hang when both stdout and stderr are piped?

    A child can fill one pipe while the parent waits for data or completion elsewhere. The child then blocks before it can finish.

  21. Why does an async Python endpoint freeze other requests during file processing?

    Declaring a function async does not make its synchronous work nonblocking. CPU loops or blocking library calls still occupy the event-loop thread.

  22. What causes the warning that a coroutine was never awaited?

    Calling an async function creates a coroutine object; it does not run the function to completion. Dropping that object without awaiting or scheduling it triggers the warning.

  23. How should an asyncio task clean up when it is cancelled?

    Cancellation is delivered cooperatively at an await point. Swallowing it can break timeouts and structured-concurrency shutdown.

  24. Why can asyncio.wait_for take longer than its timeout?

    The timeout triggers cancellation, but `wait_for` can then wait for the awaited operation to finish cancelling. Slow cleanup or swallowed cancellation extends elapsed time.

Ask your own question · Sign in to post questions and answers.