In my Visual Code Studio running python3.6 - my code is saved as "Langemead12Test.py" w/ lines as:
!C:\Users\Bones\Anaconda3\python.exe
[1]def readFastq(SRR835775_1.first1000.fastq)
Red Error underline def [pylint] E0001:invalid syntax (, line 3).
In Anaconda command prompt running python3.6:
File "Langmead12Test.py", line 3
def readFastq(SRR835775_1.first1000.fastq)
^
SyntaxError: invalid syntax
Question(s): I'm a total newb here but I can't seem to understand why VCS throws an error under def and my anaconda command line prompt throws error at the . within the fastq filename. Are these independent errors or different representations of the same error? All thoughts and hints are welcome.
Background: I am attempting to execute exercise in ADS1: Practical: Working with sequencing reads. Ben Langmead's Youtube class on reading fastq files (filename = SRR835775_1.first1000.fastq).
You have 2 syntax error in one line:
1.Missing "" or this '' before and after your string
2.You forget to put ":" and the end of the line:
Correct syntax:
def readFastq(filename="SRR835775_1.first1000.fastq"):
Read this carefully please:
https://docs.python.org/3/tutorial/introduction.html#strings
https://docs.python.org/3/tutorial/controlflow.html#defining-functions
And after that read and learn everything from there:
https://docs.python.org/3/tutorial/index.html
Related
I'm trying to execute a visual basic script that is located in my personal macro workbook on an excel file that I'm creating. Here's what I have so far:
import os
import win32com.client
df2.to_excel("Apartments.xlsx")
xl=win32com.client.Dispatch("Excel.Application")
xl.Workbooks.open(filename="C:\Users\my\full\path\Apartments.xlsx", ReadOnly=1)
xl.Application.Run("Apartments.xlsx!create_chart.create_chart_proc")
It's throwing an error when opening the excel file on line 5, I have a feeling line 6 won't work either because it comes from my personal macro book. Anyone have ideas on how to get it to function?
PS. my module name is "create_chart" and my macro name is "create_chart_proc"
It would help if you said what error you are getting, and I know that this path
"C:\Users\my\full\path\Apartments.xlsx"
is not really what is in your code. But \ inside a string has a special meaning in Python (for example \n is a newline and \f is a formfeed). Whether your \ is interpreted as you intend depends on the character that comes after it. When you use Windows paths in Python it's generally less error-prone to use a raw string.
r"C:\Users\my\full\path\Apartments.xlsx"
When you get that line to work, if the next line gives trouble, then post that as a separate question.
I got the first part of the code to work simply running the code as follows:
xl.workbooks.open("C:\Users\my\full\path\Apartments.xlsx")
Posted a separate question to get the macro to work correctly.
I'm following this exactly but it is not working https://youtu.be/qHcHUHF_Qfo?t=438
I type the location in the run window:
C:\Users\Zachary lastName\mypythonscripts\hello.py
I get error message:
can't open file 'c:\users"Zachary': [Errno 22] invalid argument
The bat file is:
#py C:\Users\Zachary lastName\mypythonscripts\hello.py %*
#pause
I've searched everywhere and can't find an answer, I also edited the path environment variable so I can just type the name of the program in the run window but again I get the error. Any help is appreciated!
You have to enclose the path name in quotes because the space means a new argument is expected, and it's not finding the file:
#py "C:\Users\Zachary lastName\mypythonscripts\hello.py" %*
#pause
Now the file path should not interfere. Usernames with spaces can become a problem for paths as their space can cause issues. Just enclose it in quotes to convert to string.
I have the following python script which i want to run..
However, it keeps showing the error message on my command prompt whenever i attempt to run the script.
Error message:
File "xor.py", line 9
File = open(sys.argv[1], 'rb').read<>
SyntaxError: Invalid Syntax
The following is the command i executed in cmd:
python xor.py sample_output.txt 'what would the secret be?'
The following is the script:
# xor.py
import sys
from itertools import cycle
file = open(sys.argv[1], 'rb').read()
string = sys.argv[2]
sys.stdout.write(''.join(chr(ord(x)^ord(y)) for (x,y) in zip(file, cycle(string))))
You are not running the code you are editing, instead you are running a different file than the one you edited.
This is because there is no syntax error in the code that you have provided. However, there is a syntax error in the code in the error message:
File = open(sys.argv[1], 'rb').read<>
This ends with <>, not with (). I assumed this to be a transcription error, but you say that the error message really appears like this, although the code does not.
Hence: You are running a different file than the one you are editing.
You have .read<> when you probably intended .read()
First of all, "file" is already reserved; that is built-in keyword so unable to set as the name of variable.
And second, do not use <> instead of (). incorrect in grammar.
The problems might be clearly solved if you code like:
fd = open(sys.argv[1], 'rb').read()
I have tried to use this code: http://www.cgtk.co.uk/data/gemf/generate_efficient_map_file.py to create GEMF file from map tiles. Problem is, when I run this code with specific folder as a parameter, eg. "py generate_efficient_map_file.py Mapnik", I get error on line 6.
File "generate_efficient_map_file.py", line 6 file_size_limit = 2000000000L
And mistake is in word L. How to solve this, when there is a declaration error?
Thx
Try running it like this
python generate_efficient_map_file.py dirname
This works fine for me (no line 6 error - I don't have input data) on python 2.7.3. You can check your python version with
python -V
I have used python-mode's python-send-buffer(and similar ones) successfully in a different system in the past.
I don't get why I'm getting error here. And worse, googling doesn't help..
Below is the output when I try sending "from math import sqrt" to Python by C-c C-r
>>> emacs.eexecfile("/var/folders/qy/qyS-532mGoWXHKmsdumelk+++TI/-Tmp-/py1850AbJ")
File "/var/folders/qy/qyS-532mGoWXHKmsdumelk+++TI/-Tmp-/py1850AbJ", line 1
from math import sqrt
^
SyntaxError: invalid syntax
My system is mac snowleopard and emacs 23.3.1, python 2.6.1
http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/125d72278d513bea?pli=1 talks about ^M .
I added the proposed solution to my .emacs but no difference
(add-to-list 'process-coding-system-alist
'("python" cp1251-unix . cp1251-unix))
From the error message the problem is that you have inserted some whitespace in front of the line: the circumflex is pointing at a blank space. Indentation is significant in Python, you cannot start a script with an indented line.