Skip to content

nf encode

Add the nf_autoid coding cookie to one or more Python source files.

Synopsis

nf encode [FILES]...

What It Does

nf encode rewrites each resolved Python file so it starts with:

# coding: nf_autoid

If the file already starts with a shebang, the command preserves it on line 1 and places the encoding cookie on line 2.

If the file already has an encoding cookie in the first two lines, nf encode leaves it alone by default. Use --force to replace that existing cookie with nf_autoid. Files that are already encoded are left unchanged.

Accepted Path Forms

The command accepts:

  • explicit file paths
  • directories, which recurse into *.py files
  • quoted globs, including recursive globs

Examples:

nf encode app.py
nf encode scripts/
nf encode "pkg/*.py"
nf encode "examples/**/*.py"
nf encode --force legacy/*.py

Important Limits

  • nf encode does not add #!/usr/bin/env python3
  • it only changes the source encoding cookie
  • Python supports one active source encoding per file, not a chain of codecs
  • existing encoding cookies are preserved unless you pass --force

If you need multi-step preprocessing, compose that pipeline inside one codec or one import hook rather than trying to stack multiple coding: declarations.

Typical Workflow

Use nf encode when you want to opt files into the nf_autoid codec without editing each file by hand.

After that, standard nf CLI workflows already register the codec before importing encoded modules.