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
It's my first request here, I hope you'll could help me.
I try to explain this particular situation.
Files that use are bases for launch a neuronal simulation and they were for Python 2. Using an Atom's plug-in, I fixed manually any Indent errors and details.
But for this error I can't find a solution.
Traceback (most recent call last):
File "./protocols/01_no_channels_ais.py", line 4, in <module>
from Purkinje import Purkinje
File "/Users/simonet/Desktop/purkinjecell/Purkinje.py", line 202
listgmax = []
^
SyntaxError: invalid syntax
From file Purkinje
self.subsets_cm = np.genfromtxt("ModelViewParmSubset_cm.txt")
for cm in self.subsets_cm:
for d in self.ModelViewParmSubset[int(cm[0])]:
d.cm = cm[1] * 0.77/1.64
self.dend[138].cm = 8.58298 * 0.77/1.64
self.subsets_paraextra = np.genfromtxt("modelsubsetextra.txt", dtype=[('modelviewsubset','f8'),('channel','S5'),('channel2','S5'),('value','f8')])
for para in self.subsets_paraextra:
for d in self.ModelViewParmSubset[int(para[0])]:
d.insert(para[1])
exec('d.gmax_'+para[2]+' = '+str(para[3])
listgmax = [] ############ PROBLEM WOULD BE HERE ##############
for d in self.ModelViewParmSubset[2]:
d.gmax_Leak = d.gmax_Leak/2
self.dend[138].insert('Leak')
self.dend[138].gmax_Leak = 1.74451E-4 / 2
"listgmax" is a unique term in this code. I can't understand where is the problem.
If I delete it, the problem continue in the next line with the same error of Sintax.
Can you help me?
Thanks a lot for your time.
Hope I was clear.
The error is simple, you forgot the closing brackets on the line above, so just say:
exec('d.gmax_'+para[2]+' = '+str(para[3]))
This should fix the errors. Keep in mind for such SyntaxError: invalid syntax the problem mostly is you missing to close brackets or something.
If any doubts or errors, do let me know
Cheers
You're missing a closing parenthesis in the line prior. It should be:
exec('d.gmax_' + para[2] + ' = ' + str(para[3]))
The Python interpreter is reporting the error on the next line because that's the soonest it can tell you didn't just continue the same expression there. In general, with syntax errors, good to look above if you don't find the error exactly where reported.
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 months ago.
Improve this question
I've started to learn python about 4 days ago. To practice, I've decided to make a program that calculates combinations.
Here is the code:
print('Insert values for your combination (Cp,n)')
def combin(exemplo):
print('insert p value')
p = int(input())
print('insert n value')
n = int(input())
exemplo = [p,n]
#"fator" is a function defined earlier in the program. It basically calculates the factorial of a number
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))
print(res)
teste = []
combin(teste)
After running this, the following error has ocurred:
print(res)
^
SyntaxError: invalid syntax
>>>
However, I can't see what I'm doing wrong here. I figured that I probably would have problems with the math and the functions, but I can't figure out what's up with the syntax in this case.
Hey nothing to worry about, its just a typo with missing parenthesis
hope you find the solution :)
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))
Hey in the following line:
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1])*fator(exemplo[1]))
you are missing a closing bracket.
You didn't close all of your parenthesis in the res line. Try this:
res = int(exemplo[0]/(fator(exemplo[0]-exemplo[1]))*fator(exemplo[1]))
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 am a complete beginner in Python, having used R quite a lot before.
I am trying to write a multiline string which is very straightforward in R but I receive an error that stumps me, I have googled around everywhere but the suggested solutions have not worked.
When I try to use parentheses as I have seen suggested:
multiline = ("Hello,"
" my name is"
" James")
I receive:
multiline = ("Hello,"
File "<ipython-input-56-f67f7efad636>", line 1
multiline = ("Hello,"
^
SyntaxError: unexpected EOF while parsing
Similarly I tried triple quotes, also suggested:
multiline = """Hello,
my name is
James"""
I receive:
multiline = """Hello,
File "<ipython-input-58-0879a928a2ee>", line 1
multiline = """Hello,
^
SyntaxError: EOF while scanning triple-quoted string literal
I am sure I will be missing something blindingly obvious to more experienced Python users but any help would be greatly appreciated.
Thanks very much
Apparently, this is neither an issue with python, ipython or spyder. The mistake is using the incorrect command to run your code. You probably used Run Selection or Current Line, while the cursor was in the first line of the multiline strings. This command doesn't consider the context, so it essentially pastes the line into the interpreter and runs. Your first error was caused by python not finding the closing parentheses. Your second error is python not finding the closing triple quotes. In spyder, one typically makes code cells with #%% and runs them with CTRL+ENTER or SHIFT+ENTER. That should fix your problem.
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
This is very much a dumb thing to ask, however I'm new to Python. I just installed googletrans from PyPI and I wanted to make a program that runs a phrase through a set of translations to make the phrase come out as broken English. However, I get a Syntax error! I can't figure it out and I've Googled everywhere. Please help!
from googletrans import Translator
import os
translator = Translator()
def addToClipBoard(text):
command = 'echo ' + text.strip() + '| clip'
os.system(command)
one = (translator.translate(input("ENTER PHRASE"))
two = (translator.translate(one, dest='sp'))
three = (translator.translate(two, dest='ch'))
four = (translator.translate(three, dest='fi'))
five = (translator.translate(four, dest='ja'))
result = (translator.translate(five))
addToClipBoard(result.text)
print("Copied succesfully. Closing now...")
exit()
You're missing a bracket at the end here:
one = (translator.translate(input("ENTER PHRASE")) # <- missing bracket
# should be
one = (translator.translate(input("ENTER PHRASE"))) # <- see the extra bracket
I recommend using a linter, like pylint. Linters catch syntax/style errors for you. If you use a text editor like vscode or pycharm, it's really easy to have it work in the background while you code so you can fix your syntax errors while coding.
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 4 years ago.
Improve this question
I'm attempting to bulk-download some csv files from a website. I've included a generic form of the first few lines of code I'm using below.
import urllib3
import os.path
def downLoadToDir(save_path,foo):
http = urllib3.PoolManager()
os.makedirs("".join(save_path, foo)
# Set up url and path for download
VarUrl = "".join("http://url.com/ajax/exportKR2CSV.html?t=", foo)
VarPath = "".join(save_path, foo, '/',foo, '.csv')
Ideally this should set up a folder under the specified filepath, and set up two variables I use later. However, I keep getting this error:
File "url_download.py", line 10
VarUrl = "".join("url.com/ajax/exportKR2CSV.html?t=", foo)
^
SyntaxError: invalid syntax
Based off of other examples I've seen online, this seems correct to me. Nothing seems to make it happy. Where am I going wrong? Thanks
You're missing a right parenthesis at line:
os.makedirs("".join(save_path, foo)
Also, the join method takes only one list argument, and you are passing two arguments here. You should make the two strings a list before passing to join as one argument:
os.makedirs("".join([save_path, foo]))
The same issue goes for the following lines that also use join.
You are not closing the bracket on line 7. Python is still looking for the close bracket and the "" is not what the compiler expects to see.
use os.makedirs("".join(save_path, foo))
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
im writing the code below:
def add_to_index(index,keyword,url):
i=0
while i<=len(index):
if keyword in index[i]:
index[i][1].append(url)
else:
index.append([keyword,[url]])
i=i+2
Im curious because when I define the index as
index = []
gives me the error list out of range, whats makes sense because there is no entry in my list, but when I define the index as
index=[['udacity',['http_qualquer'],['udacity',['http_any']]]
the error is:
Traceback (most recent call last):
File "vm_main.py", line 33, in <module>
import main
File "/tmp/vmuser_azqmlozsjr/main.py", line 18
def add_to_index(index,keyword,url):
^
SyntaxError: invalid syntax
And there is no error in the syntax of this specific line, if the syntax was wrong the error should have appeared when the index was empty.
use index this one
It should end with four brackets
check that number of open brackets should match number of closed brackets
index=[['udacity',['http_qualquer'],['udacity',['http_any']]]]