The steady path to Python mastery

Learn Python with spaced repetition and boost your productivity

    143

    cards

    89

    reviews
    today

    788

    reviews
    all time


    Try it

    Are you ready to master Python?

    Join the waitlist and we'll you when Python cards goes live.

    What are pathlib pure paths?


    Pure paths allow you to manipulate paths without any input/output operation.

    In which two main scenarios are PurePaths useful?


    They are useful:

    • To manipulate Windows paths on a Unix machine or vice versa.
    • To make sure that your code manipulates paths without actually accessing the OS.

    What path does a PureWindowsPath point to if it is instantiated without any parameter?

    What is the output of the following code?

    
    
      
      
    
    
    
    >>> from pathlib import PureWindowsPath
    >>> PureWindowsPath()
    PureWindowsPath('.')
    

    It points to the current working directory.

    What happens if you try to instantiate a WindowsPath on a Unix-based machine?

    
    
      
      
    
    
    
    
    
      
      
    
    
    
    
    
      
      
    
    
    
    
    
      
      
    
    
    
    
    
      
      
    
    
    
    >>> from pathlib import WindowsPath
    >>> WindowsPath()
    Traceback (most recent call last):                                  
      File "<stdin>", line 1, in <module>                               
      File "/usr/lib/python3.8/pathlib.py", line 1044, in __new__       
        raise NotImplementedError("cannot instantiate %r on your system"
    NotImplementedError: cannot instantiate 'WindowsPath' on your system
    

    It doesn't work, it raises a NotImplementedError exception.

    You cannot use concrete paths for the wrong OS.

    The same thing happens if you try to use PosixPath on a Windows machine.

    nomenclature

    What is the / operator called? For example in:

    from pathlib import Path
    Path("directory") / "file.txt"
    

    It's called the slash operator. It allows you to join paths.

    How can you access the different components of a Path?

    
    
      
      
    
    
    
    >>> from pathlib import Path
    >>> path = Path("/home/user/file.txt")
    >>> print(p.parts)
    ('/', 'home', 'user', 'file.txt')
    

    PurePath.parts

    How do you get the last path component of a path?

    
    
      
      
    
    
    
    
    
      
      
    
    
    
    >>> PurePosixPath("/home/user/file.txt").name
    'file.txt'
    PurePosixPath("/home/user/").name
    'user'
    

    Using PurePath.name.

    What does POSIX mean?


    POSIX stands for Portable Operating System Interface, it is a family of standards that defines system and user-level APIs, command line shells, and utility interfaces for software compatible with variants of Unix.

    Operating systems such as Linux, MacOS and FreeBSD are POSICX compliant.

    How do you get the file extension of the final component of the path?

    
    
      
      
    
    
    
    >>> PurePosixPath("my/library/setup.py").suffix
    '.py'
    

    Using PurePath.suffix.

    How can you represent a Windows path with forward slashes?

    
    
      
      
    
    
    
    >>> from pathlib import PureWindowsPath
    >>> p = PureWindowsPath('c:\\windows')
    p.as_posix()
    >>> 'c:/windows'
    




    The decks

    A Tour of the Standard Library (0 cards)
    Free

    The Python standard library is big, but how big is it? Did you know you can do low-level network communications with socket? And measure the execution time of code with timeit? Have you ever analyzed the syntax tree of a Python code with ast or drawn a plot with turtle? It even has a full sqlite3 implementation!

    Get a grasp of all the functionality just one import away.

    pathlib in depth (139 cards)
    Free

    The pathlib library offers the most convenient way of managing files and file paths in Python. Learn its full power and master its API.

    F-strings like a pro
    Coming soon

    Collections
    Coming soon

    Peter Norvig's pytude tricks
    Coming soon

    If you have ever read Peter Norvig's code from his pytudes, you will agree that his code is odd, surprisingly clear and insultingly concise.

    In this deck, we have collected dozens of tricks in Pytudes so you can come closer to his genius.

    Nomenclature
    Coming soon

    Learn the concepts and words of Python: type hints, context managers, methods, comprehensions, generic functions…

    Knowing the words is a first step towards a complete mental model of Python.

    Built-ins
    Coming soon

    Built-in functions are always available in Python without needing to import them. We are talking about print, range, enumerate, but also isinstance, map and staticmethod.

    The list is short, but holds huge power.

    Built-in exceptions
    Coming soon


    It's easy

    Get daily reminders and build the habit of reviewing your cards.

    It's fun

    Keep your streak and learn bit by bit.

    It works

    Feel your knowledge growing and be amazed by your progress.


    Our secret sauce: the cards


    Built in public

    Check my Youtube channel to see how the site and the decks are built.


    Join the waitlist

    Be the first to know when Python.cards is ready.

      Frequently Asked Questions

      Can you really learn Python without writing code?

      Of course not. Python.cards is not a replacement for coding, it's a shortcut to level up your Python skills.

      Are you planning to support other languages?

      Yes. I'm working on Rust.cards, following the same philosophy as Python.cards.

      What spaced repetition algorithm does Python.cards use?

      We use the classic Anki algorithm, which is a modified version of SM-2. We have actually open sourced our implementation of the algorithm as the Python module simple-spaced-repetition. You can find the code on Github.