When I run the following game I get an error "Unexpected Indent" but when you look at the code it's perfectly correct.
The error occurs at del evilGuy[-1]. The indentation is correct still I get this error.
EDIT
The code has been changed a bit. Even now the error occurs at : del evilGuy[-1] showing unexpected indentation.
def evilMove(evilGuy):
evilCoords=[]
#deadZones=[]
#Returns either -1, 0 or 1
randomMovex=random.randrange(-1,2)
randomMovey=random.randrange(-1,2)
newCell={'x':evilGuy[0]['x']+randomMovex,'y':evilGuy[0]['y']+randomMovey}
if (newCell['x']<0 or newCell['y']<0 or newCell['x']>cellSize or newCell['y']>display_height/cellSize):
newCell={'x':display_width/(2*cellSize),'y':display_height/(2*cellSize)
del evilGuy[-1]
evilCoords.append(newCell['x'])
evilCoords.append(newCell['x'])
deadZones.append(evilCoords)
evilGuy.insert(0,newCell)
Solved
The error was a missing '}' in the function evilMove.
Solutiuon is give below.
def evilMove(evilGuy):
evilCoords=[]
#deadZones=[]
#Returns either -1, 0 or 1
randomMovex=random.randrange(-1,2)
randomMovey=random.randrange(-1,2)
newCell={'x':evilGuy[0]['x']+randomMovex,'y':evilGuy[0]['y']+randomMovey}
if (newCell['x']<0 or newCell['y']<0 or newCell['x']>cellSize or newCell['y']>display_height/cellSize):
newCell={'x':display_width/(2*cellSize),'y':display_height/(2*cellSize)} # Here It's missing '}'
del evilGuy[-1]
evilCoords.append(newCell['x'])
evilCoords.append(newCell['x'])
deadZones.append(evilCoords)
evilGuy.insert(0,newCell)
This pb exist from the number of white space
in your code delete the space before def, and add three space before ''', your code will be (just copy and paste) :
def evilMove(evilGuy): # here delete spaces
evilCoords=[]
#deadZones=[]
#Returns either -1, 0 or 1
randomMovex=random.randrange(-1,2)
randomMovey=random.randrange(-1,2)
newCell={'x':evilGuy[0]['x']+randomMovex,'y':evilGuy[0]['y']+randomMovey}
''' # here add spaces
if (newCell['x']<0 or newCell['y']<0 or newCell['x']>cellSize or newCell['y']>display_height/cellSize):
newCell={'x':display_width/(2*cellSize),'y':display_height/(2*cellSize)
'''
del evilGuy[-1]
evilGuy.insert(0,newCell)
Related
Below is my hello apps view.py
***def hello(request):
num_visits = request.session.get('num_visits',0)+1
request.session['num_visits'] = num_visits
if num_visits > 4 : del(request.session['num_visits']
return HttpResponse(';view count ='+str(num_visits))***
after compile, check below error appear on shell:
Syntax Error - Invalid Syntax
Can any expert provide some guidance ?
del doesn't take arguments in parenthesis, it's an operator.
Change this line:
del(request.session['num_visits']
to:
del request.session['num_visits']
And it should work.
thank you for the respond, i managed to address the problem, there was a missing ")" at the del line.
I am trying to get ryu to run, especially the topology discovery.
Now I am running the demo application for that under ryu/topology/dumper.py, which is supposed to dump all topology events. I am in the ryu/topology direcory and run it using ryu-manager dumper.py. The version of ryu-manager is 2.23.2.
Shortly after starting it gives me this error:
/usr/local/lib/python2.7/dist-packages/ryu/topology/switches.py:478: UserWarning:
Datapath#ports is kept for compatibility with the previous openflow versions (< 1.3).
This not be updated by EventOFPPortStatus message. If you want to be updated,
you can use 'ryu.controller.dpset' or 'ryu.topology.switches'.
for port in dp.ports.values():
What's really weird to me is that it recommends to use ryu.topology.switches, but that error is triggered by line 478 of that very file!
The function in question is this:
class Switches(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION, ofproto_v1_2.OFP_VERSION,
ofproto_v1_3.OFP_VERSION, ofproto_v1_4.OFP_VERSION]
_EVENTS = [event.EventSwitchEnter, event.EventSwitchLeave,
event.EventPortAdd, event.EventPortDelete,
event.EventPortModify,
event.EventLinkAdd, event.EventLinkDelete]
DEFAULT_TTL = 120 # unused. ignored.
LLDP_PACKET_LEN = len(LLDPPacket.lldp_packet(0, 0, DONTCARE_STR, 0))
LLDP_SEND_GUARD = .05
LLDP_SEND_PERIOD_PER_PORT = .9
TIMEOUT_CHECK_PERIOD = 5.
LINK_TIMEOUT = TIMEOUT_CHECK_PERIOD * 2
LINK_LLDP_DROP = 5
#...
def _register(self, dp):
assert dp.id is not None
self.dps[dp.id] = dp
if dp.id not in self.port_state:
self.port_state[dp.id] = PortState()
for port in dp.ports.values(): # THIS LINE
self.port_state[dp.id].add(port.port_no, port)
Has anyone else encountered this problem before? How can I fix it?
I ran into the same issue (depending on your application, maybe it's not a problem, just a warning that you can ignore). Here is what I figured out after a find . -type f | xargs grep "ports is kept"
This warning is triggered in ryu.topology.switches, by a call to _get_ports() in class Datapath of file ryu/controller/controller.py.
class Datapath(ofproto_protocol.ProtocolDesc):
#......
def _get_ports(self):
if (self.ofproto_parser is not None and
self.ofproto_parser.ofproto.OFP_VERSION >= 0x04):
message = (
'Datapath#ports is kept for compatibility with the previous '
'openflow versions (< 1.3). '
'This not be updated by EventOFPPortStatus message. '
'If you want to be updated, you can use '
'\'ryu.controller.dpset\' or \'ryu.topology.switches\'.'
)
warnings.warn(message, stacklevel=2)
return self._ports
def _set_ports(self, ports):
self._ports = ports
# To show warning when Datapath#ports is read
ports = property(_get_ports, _set_ports)
My understanding is that if the warning is from ryu.topology.switches or ryu.controller.dpset, you can ignore it; because those two classes handle the event for you. But if you use Datapath directly, port status is not updated automatically. Anyone correct me if I'm wrong.
class Switches(app_manager.RyuApp):
#......
#set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER)
def port_status_handler(self, ev):
I have encountered that problem before but I just ignored it and so far every thing has been working as it was expected.
If you are trying to learn the topology I would recommend using ryu.topology.api. i.e.
from ryu.topology.api import get_switch, get_link
There is this tutorial. However there are some of the stuff missing.
Here is what I have so far: Controller.py
In the Controller.py the two functions get_switch(self, None) and get_link(self, None) would give you list of links and switches.
So I am trying to set up a small script in Python's IDLE. The IDLE syntax check tells me this code has a syntax error:
from ftplib import FTP
import os
def ftpconnect(address, username, password):
ftp_connection = 0
ftp = FTP(address)
try:
ftp.login(username, password)
print(ftp.getwelcome())
if ftp.getwelcome() == '220 FTP Connected!':
return 1
else:
return 0
print(ftpconnect('10.10.10.xxx', 'xxx', 'xxx'))
The syntax error comes anywhere that I try to get out of the "try" statement, here being the "else:" line. I've looked around and it seems like I have the right syntax...any thoughts?
Thanks! I'm running Python 2, not 3.
In addition to the problem with my syntax (missing except statement entirely), my ftp attempt statement was outside of the try block. Since I was not "try"ing it, it failed anyway.
I'm new to Python but known to MEL.
At the moment I try to create a menu for my specialization project (quick rigging tool).
I'm getting this error every time while I can't find a logical explanation for it.
The error is a unexpected indent, it appears in a def to create a menu.
I really try to get this thing of the ground, thanks in advance :)
The code:
#Python script: Autorig v0.0.1
#Interface
import maya.cmds as cmds
#Create main window
#
class AR_OptionWindow(object):
def __init__(self):
self.window = 'ar_optionsWindow'
self.title = 'Options Window'
self.size = (546, 350)
self.supportsToolAction = False
def commonMenu(self):
self.editMenu = cmds.menu(label = 'Edit')
self.editMenuSave = cmds.menuItem(
label='Save Settings'
)
self.editMenuReset = cmds.menuItem(
label='Reset Settings'
)
self.editMenuDiv = cmds.menuItem(d=True)
self.editMenuRadio = cmds.radioMenuItemCollection()
self.editMenuAction = cmds.menuItem(
label='As Action',
radioButton=True,
enable=self.supportsToolAction
)
self.editMenuTool = cmds.menuItem(
label='As Tool',
radioButton=True,
enable=self.supportsToolAction
)
self.helpMenu = cmds.menuItem(label='Help')
self.helpMenuItem = cmds.menuItem(
label='Help in %s'%self.title
)
def create(self):
if cmds.window(self.window, exists=True):
cmds.deleteUI(self.window, window=True)
self.window = cmds.window(
self.window,
title=self.title,
widthHeight=self.size
)
cmds.showWindow()
I'm getting the following error:
# Error: unexpected indent
# File "<maya console>", line 30
# self.editMenuTool = cmds.menuItem(
# ^
# IndentationError: unexpected indent
#
Your indentation is a mix of tabs and spaces, which can lead to unexpected behavior. This is due to the somewhat arcane rules that determine how tabs are interpreted:
First, tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight (this is intended to be the same rule as used by Unix). The total number of spaces preceding the first non-blank character then determines the line’s indentation. Indentation cannot be split over multiple physical lines using backslashes; the whitespace up to the first backslash determines the indentation.
In this image, tabs are arrows and spaces are dots. Your self.editMenuAction = line effectively has 12 spaces of indentation. Your self.editMenuTool = line effectively has 16.
According to PEP 8, you should exclusively use spaces for indentation.
I am trying to implement a hash function and here is my code:
import BitVector
import glob
path = '/home/vguda/Desktop/.txt'
files=glob.glob(path)
hash = BitVector.BitVector(size = 32)
hash.reset(0)
i = 0
for file in files:
bv = BitVector.BitVector( filename = file )
while 1 :
bv1 = bv.read_bits_from_file(8)
if str(bv1) == "":
break
hash[0:8] = bv1 ^ hash[0:8]
hash >> 8
i = i+1
hash_str = ""
hash_str = str( hash )
text_file = open("/home/vguda/Desktop/result.txt ","w")
text_file.write("Hash Code is %s" %hash_str)
text_file.close()
print hash
print (i)
The displayed error is:
"bash: syntax error near unexpected token `('
First, perhaps this happened in copy and paste, but your indenting in your loop is all messed up, I'm not sure which blocks go where.
When you run things in the shell, you need to either tell python to run it:
python myscript.py
Or, put the following line as the first thing in your program to tell bash to run it as a python program:
#!/usr/bin/python
Currently, bash is trying to run your python program as a bash script, and obviously running into syntax errors.