I tried run this code but I have an error:
a4 local variable referenced before assignment
a1 = '/fr/store/a'
try:
a2 = '/fr/store/b/collection/3432'
a2_store = "store"
a3 = a2.split ("store/")
a4 = a3[0]
if a2_store in a2:
print ('a2')
except:
if a4 not in a1:
print ('a1')
If an exception is raised before a4 = a3[0]
is executed (for example, if a3[0]
raises an IndexError
), then a4
is, indeed, not defined.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.