Error: There is no viable alternative when typing 'for' Python

I have a strange problem

when I use the Netbeans IDE, this line:

total_stock = {items : 0 for items in product_stock} 

calls the syntax Error:

Syntax error: no viable alternative for input 'for'

But the same code works fine in the terminal and returns this

 >> {'rom_price': 0, 'rim_price': 0, 'ram_price': 0} 

I use python 2.7+ on the terminal and the python plugin Version: 0.107 and the Jython plugin Version: 2.12 Source: Python for netbeans 8.0

How to solve this problem?

+6
source share
1 answer

It seems that jython cannot do dictionary comprehension. As a workaround, use the dictionary constructor in combination with a generator.

 total_stock = dict((item, 0) for item in product_stock) 
+8
source

Source: https://habr.com/ru/post/973531/


All Articles