The second argument must be a string, so just put quotes around it:
cmd.label('CAs', '"%s%s" % (one_letter[resn],resi)')

This also works:
cmd.label('CAs', 'f"{oneletter}{resi}"')

Cheers,
  Thomas


On Fri, Jul 8, 2022 at 6:09 PM sunyeping via PyMOL-users
<pymol-users@lists.sourceforge.net> wrote:
>
> Dear all,
>
> I want to label residues with the resn+resi, and I tried the following command
>
> one_letter ={'VAL':'V', 'ILE':'I', 'LEU':'L', 'GLU':'E', 'GLN':'Q', \
> 'ASP':'D', 'ASN':'N', 'HIS':'H', 'TRP':'W', 'PHE':'F', 'TYR':'Y',    \
> 'ARG':'R', 'LYS':'K', 'SER':'S', 'THR':'T', 'MET':'M', 'ALA':'A',    \
> 'GLY':'G', 'PRO':'P', 'CYS':'C'}
>
> select CAs, obj & n. CAs
> label CAs, "%s%s" % (one_letter[resn],resi)
>
>
> These work find. However, when I write these in a script and the last two 
> commands are written as:
>
>     cmd.select('CAs', 'obj & n. CAs')
>
>     cmd.label('CAs', "%s%s" % (one_letter[resn],resi))
>
> it gives the following error:
>
>     NameError: name 'resn' is not defined
>
>
> So could anyone tell me how to correctly use the cmd.label command?
>
> Thank you very much in advance
>
>
> _______________________________________________
> PyMOL-users mailing list
> Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
> Unsubscribe: 
> https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe


_______________________________________________
PyMOL-users mailing list
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net
Unsubscribe: 
https://sourceforge.net/projects/pymol/lists/pymol-users/unsubscribe

Reply via email to