Indentation error [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 8 years ago.
Improve this question
I receive an indentation error that I cannot figure out the reason.
The error is
('unexpected indent', ('C:/Hamid/Failure_index.py',15,1,'\tSDV2=xyList[0]\n')).
My code is
from abaqusConstants import *
from odbAccess import *
from visualization import *
#---------------------------------------------------------------------------
out_file= 'C:\Hamid\Stochastic\Python_script_for_Monte_Carlo_simulation\Microtensile/Failure_index.dat'
fid = open(out_file,'w')
for i in range(1,50):
odb_path = 'C:\Hamid\Stochastic\Python_script_for_Monte_Carlo_simulation\Microtensile/Microtens-'+str(i)+'_xs.odb'
session.openOdb(name=odb_path)
odb = session.odbs[odb_path]
session.viewports['Viewport: 1'].setValues(displayedObject=odb)
xyList = session.xyDataListFromField(odb=odb, outputPosition=INTEGRATION_POINT, variable=(('SDV2', INTEGRATION_POINT), ), elementSets=(' ALL ELEMENTS', ))
SDV2 = xyList[0]
fid.write(SDV2+'\n')
odb.close()
fid.close()

You are mixing tabs and spaces in your source code, and Python's algorithm for expanding tabs to spaces causes SDV2 = xyList[0] to be indented 8 spaces, not 4 like the other lines in the for loop.

Related

How do I integrate a Gaussian using Scipy? [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 1 year ago.
Improve this question
I can't think of what I might be doing wrong: This is the code I've been using, followed by the error I'm getting (thanks in advance for your time):
import scipy.integrate
import numpy as np
integrand= lambda x:((x**1)*(np.exp((-1*(x - 5)**2) / (2 * 10**2)))
intmom = scipy.integrate.quad(integrand, 1, 10)
print(intmom)
Error:
File "", line 3
intmom = scipy.integrate.quad(integrand, 1, 10)
^
SyntaxError: invalid syntax
You are missing a closing ) on the previous line it should be
integrand= lambda x:((x**1)*(np.exp((-1*(x - 5)**2) / (2 * 10**2))))
Output:
(47.53743192883985, 5.277715145894907e-13)

What can I do to fix this Syntax Error if I put everything in correctly? [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 2 years ago.
Improve this question
def infPi(num):
pi = 0
for i in range(num):
pi += (1/((2(i+1)-1)**2)
print(pi*4)
The syntax error is for the line with "Print(pi*4)"
There was a parenthesis missing at the end and a syntax error in the 4th line ( pi += (1/(2*(i+1)-1)**2) ) , try like this:
def infPi(num):
pi = 0
for i in range(num):
pi += (1/(2*(i+1)-1)**2)
print(pi*4)

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!

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.

Eulers method- velocity and position as a function of time for runner [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 5 years ago.
Improve this question
Acceleration in a given point is given by a=5-0.004364*v^2
I want to store all the values of v and x and a in lists so that I later can plot them as a function of time. Keep in mind I'm a beginner. This is my code so far:
x_val=0
x=[]
x.append(x_val)
v_val=0
v=[]
v.append(v_val)
a_val=5.0
a=[]
a.append(a_val)
h=0.1
while x_val <=100:
v_val += (a_val*h)
x_val += (v_val*h)
a_val=(5-0.004364*(v_val**2)
a.append(a_val)
v.append(v_val)
x.append(x_val)
I'm getting a syntax error on "a.append(a_val)": invalid syntax
What am I doing wrong here? Please help
There is closed parenthesis missing in the below line
`a_val=(5-0.004364*(v_val**2)`

Categories