Skip to content

Instantly share code, notes, and snippets.

@jiridanek
Created September 9, 2025 11:49
Show Gist options
  • Select an option

  • Save jiridanek/30de0133f69ae93d739cb008b05c2a9d to your computer and use it in GitHub Desktop.

Select an option

Save jiridanek/30de0133f69ae93d739cb008b05c2a9d to your computer and use it in GitHub Desktop.

Python reading

Problem 1

for i in range(1, 10):
    print(i)
else:
    print("else")

Problem 2

# language=yaml
manifest_file = """\
---
kind: ImageStream
metadata:
  name: nginx-app
  namespace: openshift
spec:
  lookupPolicy:
    local: false
---
kind: Deployment
# ...
"""

# using pyyaml library
import yaml  # (1)

# imagestream is the first document in the yaml file
#imagestream = yaml.safe_load_all(manifest_file)[0]  # this would not work (2)


imagestream = next(yaml.safe_load_all(manifest_file))  # this does! why? (3)

Part 1

Part 2

Part 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment