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
When i make error?
Don't see errors. Please, help me.
datafile = file('c:\\Users\\username\\Desktop\\test.txt')
for line in datafile:
if '5256' in line:
GLOBACCESS[jid]=100
reply('private', source, u'You license is valid!')
else:
reply('private', source, u'Incorrect password/jid')
Lines 2 and 3 are using spaces while everything else is using tabs. You always need to use the same, and should choose spaces per pep 8
Line 2 shouldn't be indented at all, with spaces or with tabs
for loop shouldn't be indented.
datafile = file('c:\\Users\\username\\Desktop\\test.txt')
for line in datafile:
if '5256' in line:
GLOBACCESS[jid]=100
reply('private', source, u'You license is valid!')
else:
reply('private', source, u'Incorrect password/jid')
Related
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
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!
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
So, I have a list of lists and trying to write the values to a file with tab delimited;
sorted_results=[
["test1", 01],
["test2", 02],
]
with open('outfile.txt', 'a') as write_file:
for i in sorted_results:
write_file.write("{}\t{}\n".format(i[0], i[1]))
The end result comes out as:
test1 01
test2 02
Values are space delimited not tab. What am I missing? If I add a space before \t then end result will have a space and a tab between the values.
You can read the file back in and inspect the resulting data.
>>> open('outfile.txt').read()
'test1\t1\ntest2\t2\n'
This shows that the tab character is indeed written to the file. If you are still in doubt use a hex editor to view the characters.
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
A problem exists in Python 2.7.11, with the print function:
elif e=="randomize w and x":
random=randint(int(w),int(x))
print random
elif e=="randomize w and y":
random=randint(int(w,int(y))
print random
The boldfaced print shows up as a syntax error, yet all 278 others in my program do not. Why this is, and how I fix it?
The problem is that in
random=randint(int(w,int(y))
a close parenthesis after w is missing, therefore Python thinks the expression continues on next line, but print at that point is a syntax error.
Your problem is not with the print statement, rather the line right before it. The line before hass inbalanced parenthesis:
random=randint(int(w,int(y))
Make sure you balance them out (add an extra ) at the end), and your error on the next line will disappear.
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
import random
for i in range(1,21):
print("%10d" %(random.randrange(1,7)),
if (i % 5 == 0):
print ("")
What is wrong in this code ?
I know basic python (almost), but i am not able to figure out what could be error in this program.
it is showing this error:
Syntax Error: invalid syntax at line 6 (if statement)
The fourth line is missing bracket .. Thanks all of you
You missed a right bracket )
print("%10d" %(random.randrange(1,7))),
would be correct
You're missing a ) before the last comma on line 4.
Your parenthesis on line 4 don't match. Because you have an unclosed paren, python doesn't report this syntax error until the colon on line 6 (python ignores line breaks as long as you are inside an enclosing set of parenthesis, brackets, or braces).