[issue38556] Walrus operator in list comprehensions [Python 3.8.0]

EGN report at bugs.python.org
Tue Oct 22 10:07:20 EDT 2019


EGN <pilatinum at gmail.com> added the comment:

from os import getcwd, listdir, rename
import re

[rename(f'{p}{n}', f"{p}{''.join([w[:3] if len(w) > 3 else w for w in re.split('[-_. ]', n)[:-1]])}.{n.split('.')[-1]}")
 for n in listdir(p := f"{getcwd()}\\{input('Folder: ')}\\")]

When I run this code, I'm getting:
  File "C:\Users\1\Desktop\sn.py", line 4
    [rename(f'{p}{n}',f"{p}{''.join([w[:3] if len(w)>3 else w for w in re.split('[-_. ]',n)[:-1]])}.{n.split('.')[-1]}") for n in listdir(p:=f"{getcwd()}\\{input('Folder: ')}\\")]
                                                                                                                                         ^
SyntaxError: assignment expression cannot be used in a comprehension iterable expression

Process finished with exit code 1

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38556>
_______________________________________


More information about the Python-bugs-list mailing list