{"library":"scanf","title":"Python scanf","description":"The `scanf` library provides a pure-Python implementation of the C-style `scanf` function for parsing strings based on format specifiers. It allows users to extract data of various types from input strings, similar to its C counterpart. The current version is 1.6.0. It has a relatively low release cadence but remains actively maintained with recent commits.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install scanf"],"cli":null},"imports":["import scanf","from scanf import scanf"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import scanf\n\n# Example 1: Basic string and integer parsing\nname, age = scanf.scanf(\"Name: %s Age: %d\", \"Name: Alice Age: 30\")\nprint(f\"Parsed - Name: {name}, Age: {age}\")\n\n# Example 2: Parsing a more complex string with mixed types\n# %[^,] is a scanf-specific specifier meaning 'read until a comma'\ninput_data = \"Product: Laptop, Price: 1200.50, Quantity: 2, ID: xyz123\"\nformat_str = \"Product: %[^,], Price: %f, Quantity: %d, ID: %s\"\n\n# scanf.scanf returns a tuple of parsed values or None if no match.\nresult = scanf.scanf(format_str, input_data)\n\nif result:\n    product, price, quantity, product_id = result\n    print(f\"\\nParsed data from complex string:\")\n    print(f\"  Product: {product}\")\n    print(f\"  Price: {price:.2f}\")\n    print(f\"  Quantity: {quantity}\")\n    print(f\"  ID: {product_id}\")\nelse:\n    print(\"\\nFailed to parse the input string. Check format string and input data.\")","lang":"python","description":"This quickstart demonstrates how to use `scanf.scanf()` to parse strings. It shows basic type extraction and a more complex scenario using C-style format specifiers, including `%[^,]` to read until a delimiter. It also illustrates checking for `None` as `scanf.scanf` returns `None` on no match.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}