IndentationError in Python [closed] - python

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I am performing one python program and the part of the code is as follows
while 1:
data = conn.recv(BUFFER_SIZE)
if not data: break
print "received data:", data
com = "echo " + data
print com
conn.send(data)
conn.close()
but when i am trying to execute the code i am getting the following error.
File "server.py", line 17
com = "echo " + data
^
IndentationError: unexpected indent
I am not getting whats wrong with the code above.

check that you either consistently have tabs or spaces not a mix of both.

Related

Unexpected end of file error at comment line [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I was working on a problem and came across a syntax error for a print statement. I started commenting out lines and have an EOF error for a comment line. Any clue how to fix this EOF error for comments?
I've tried commenting out the lines, deleting the lines and typing them again in case I had a typo, and looking up similar solutions
Here is what I am currently trying to run:
# np_baseball is available
# Import numpy
import numpy as n
# Create np_height_in from np_baseball
np_height_in = np_baseball[0]
print(n.median(np_height_in))
# Print out the mean of np_height_in
print(n.mean(np_height_in)
#print(n.median(np_height_in))
# Print out the median of np_height_in
Here's the current error:
File "", line 12
# Print out the median of np_height_in
^
SyntaxError: unexpected EOF while parsing
print(n.mean(np_height_in)
is missing a closing ) . It should be:
print(n.mean(np_height_in))

SyntaxError on filename when trying to read file? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am trying to use machine learning to predict students' future grade, but am stuck at the beginning.
Seems like pandas.read_csv cannot read psv file, I got:
df = pd.read_csv(‘training.psv’)
^
SyntaxError: invalid character in identifier
How can I read psv file through python?
The problem is in the quotes symbol. You should either use ' or ".
Try:
df = pd.read_csv('training.psv')
pd.read_csv("training.psv", sep = "|", header = FALSE, stringsAsFactors = FALSE)
That should work

How to fix "unexpected indent" error on a python column that isn't indented [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
My terminal is producing the error "unexpected indent" at the start of my for loop, when it is not indented at all in my editor. How can I fix this? See code below:
wb = openpyxl.load_workbook(filename = 'BE110FinalProject.xlsx')
type(wb)
sheet = wb.get_sheet_by_name('Sheet1')
for row in sheet.iter_rows('K{}:K{}'.format(258,sheet.max_row)):
for cell in row:
if (cell.value):
numerator = float(cell.value.split(':')[1])
denominator = float(cell.value.split(':')[0])
japanOutput.write(numerator + '/' + denominator + '\n')
else:
japanOutput.write('\n')
You most likely have spaces instead of tabs.
Python tends to be picky when it comes to tabs and spaces.
One thing to try would be removing your indentations and making sure you use tabs.
I hope this helped!

python says variable name is a syntax error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Every time I try to run these first 2 lines in python, it says:
SyntaxError: invalid syntax
And highlights the name of the variable I'm trying to define (Yname).
These are the lines I'm trying to run:
print("Hello what's your name?")\
Yname = input("your name:")
It is because of the \ at the end of the first line.
in Python \ is the line continuation character. Python is trying to parse this as
print("Hello what's your name?")Yname = input("your name:")

python3-invalid syntax on a line that do not exist [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
python3-invalid syntax error
File "6_1.py", line 8
SyntaxError: invalid syntax
But there is no line 8. So what is the problem.
import zipfile,re
with ZipFile('../../下载/channel.zip') as myzip:
nothing = '90052'
rex = re.compile(r'\d+')
while True:
print(myzip.getinfo(nothing+'txt'))
nothing = re.findall(rex, myzip.open(nothing+'txt')[0]
No, but Python thinks there should be because line 7 is not complete:
nothing = re.findall(rex, myzip.open(nothing+'txt')[0]
# open 1 -------- open 2 ----- close 2 - ^ where is close 1?
There is a closing ) missing at the end.

Categories