I have gotten myself into some python indenting mess. I am not a Python person but had to edit a couple of lines now a big mess. Tried notepad++ the indenting looks perfect to me, but it does not compile - keeps giving IndentationError: unexpected indent I dont know what the expectation is tabs/sapces - the columns are aligned corrctly.
Google/Stackoverflow suggested try using reindent. I have python 2.7 (its in the path) it contains reindent (uncompiled). Tried to run the command a few ways, used absolute paths etc, but did not work- cant find reindent:
>python -m C:\Python27\Tools\Scripts\reindent -d C:\Cassandra228\
apache-cassandra\pylib\cqlshlib\copyutil.py
c:\python27\python.exe: No module named C:\Python27\Tools\Scripts\reindent
How do I fix this.
Thanks
I currently solved my issue using the special character view in notepad++. There were tabs etc - once I got rid of them the code compiled.
I will check out sublime text - looks like it has better options.
Nonetheless how do we use the python reindent (or do we use it at all for this type of situation)
Thanks all,
Related
Venv File I have a project that utilizes YoloV5, OpenCV, as well as many other python libraries. After finally finishing work on the project, I wanted to share it with my teammates. However, I was unable to get my code to run anywhere other than my machine. There was a Venv file that was generated automatically somewhere along the way, either by my IDE or a jupyter notebook. I tried giving out this file to others, but it is not only massive (~1GB), but it also didn't work. I will consistently get syntax errors that do not exist in my environment. For example, I will get:
"SyntaxError: Non-ASCII character '\xf0' in file detect.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
"
If I remove that line, I get:
" File "detect.py", line 120
model.warmup(imgsz=(1 if pt else bs, 3, *imgsz)) # warmup
^
SyntaxError: invalid syntax
"
Mind you, none of these errors exist in my environment.
I have tried looking up various commands to somehow link the venv file to the environment or to the python file. I thought that, perhaps, python wasn't looking for the file, so it wasn't using it. I also tried installing other packages and installing all the dependencies manually. However, none of these things worked. I am a little lost on where to go from here, I have heard of tools like Conda, which apparently might help manage things like this, but I am wondering if anyone could give advice on how to proceed, or maybe if anyone else has personally used YoloV5 and encountered this problem themselves
I tried this code, following along with a tutorial:
my_name = 'Zed A. Shaw'
print(f"Let's talk about {my_name}.")
But I get an error message highlighting the last line, like so:
print(f"Let's talk about {my_name}.")
^
SyntaxError: invalid syntax
Why?
If you get an error like this from someone else's code, do not try to fix it yourself - the other project simply does not support your Python version (One example: Using pytesseract on Python 2.7 and Windows XP). Look for an alternative instead, or check the project's documentation or other support resources for a workaround.
In particular, the built-in pip package manager has an issue where newer versions of pip require a newer Python version, so old installations cannot upgrade pip past a certain point. See Installing pip is not working in python < 3.6 or Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}") for details.
If an external tool warns about the problem even though Python supports the feature, update the tool. See Getting invalid syntax error when using Pylint but code runs fine for an example.
This question is specifically about the situation where any attempt to use f-strings fails (the ^ in the error message will point at the closing quote). For common problems with specific f-string syntax, see How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?, f-string formula inside curly brackets not working, Discord.py - SyntaxError f-string: empty expression not allowed, How to use newline '\n' in f-string to format output in Python 3.6?.
For details on alternate approaches to string formatting, see How do I put a variable’s value inside a string (interpolate it into the string)?.
I think you have an old version of python. try upgrading to the latest version of python. F-string literals have been added to python since python 3.6. you can check more about it here
This is a python version problem.
Instead of using
print(f"Let's talk about {my_name}."
use
print("Let's talk about {}.".format(my_name))
in python2.
Your code works on python3.7.
Check it out here:
my_name= "raushan"
print(f"Let's talk about {my_name}.")
https://repl.it/languages/python3
Python Interpreter causes the following issue because of the wrong python version you calling when executing the program as f strings are part of python 3 and not python 2. You could do this python3 filename.py, it should work. To fix this issue, change the python interpreter from 2 to 3.
f-strings were added in python 3.6. In older python versions, an f-string will result in a syntax error.
If you don't want to (or can't) upgrade, see How do I put a variable inside a String in Python? for alternatives to f-strings.
I think this is due to the old version. I have tried in the new version and the executing fine. and the result is as expected.
I believe the problem you are having here is down to you using python 2 without realizing it. if you haven't set it up on your machine to have python 3 as your default version you should execute python3 in your terminal instead of the standard 'python' command.
I had this problem so hopefully, this answer can be of help to those looking for it.
I think they had typed
python file.py
to run the program in the Mac or linux that runs the python 2 version directly because OS defaultly contain python 2 version, so we needed to type
python3 file.py
That's the solution for the problem
python2 and python3 running command
I tried this code, following along with a tutorial:
my_name = 'Zed A. Shaw'
print(f"Let's talk about {my_name}.")
But I get an error message highlighting the last line, like so:
print(f"Let's talk about {my_name}.")
^
SyntaxError: invalid syntax
Why?
If you get an error like this from someone else's code, do not try to fix it yourself - the other project simply does not support your Python version (One example: Using pytesseract on Python 2.7 and Windows XP). Look for an alternative instead, or check the project's documentation or other support resources for a workaround.
In particular, the built-in pip package manager has an issue where newer versions of pip require a newer Python version, so old installations cannot upgrade pip past a certain point. See Installing pip is not working in python < 3.6 or Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}") for details.
If an external tool warns about the problem even though Python supports the feature, update the tool. See Getting invalid syntax error when using Pylint but code runs fine for an example.
This question is specifically about the situation where any attempt to use f-strings fails (the ^ in the error message will point at the closing quote). For common problems with specific f-string syntax, see How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?, f-string formula inside curly brackets not working, Discord.py - SyntaxError f-string: empty expression not allowed, How to use newline '\n' in f-string to format output in Python 3.6?.
For details on alternate approaches to string formatting, see How do I put a variable’s value inside a string (interpolate it into the string)?.
I think you have an old version of python. try upgrading to the latest version of python. F-string literals have been added to python since python 3.6. you can check more about it here
This is a python version problem.
Instead of using
print(f"Let's talk about {my_name}."
use
print("Let's talk about {}.".format(my_name))
in python2.
Your code works on python3.7.
Check it out here:
my_name= "raushan"
print(f"Let's talk about {my_name}.")
https://repl.it/languages/python3
Python Interpreter causes the following issue because of the wrong python version you calling when executing the program as f strings are part of python 3 and not python 2. You could do this python3 filename.py, it should work. To fix this issue, change the python interpreter from 2 to 3.
f-strings were added in python 3.6. In older python versions, an f-string will result in a syntax error.
If you don't want to (or can't) upgrade, see How do I put a variable inside a String in Python? for alternatives to f-strings.
I think this is due to the old version. I have tried in the new version and the executing fine. and the result is as expected.
I believe the problem you are having here is down to you using python 2 without realizing it. if you haven't set it up on your machine to have python 3 as your default version you should execute python3 in your terminal instead of the standard 'python' command.
I had this problem so hopefully, this answer can be of help to those looking for it.
I think they had typed
python file.py
to run the program in the Mac or linux that runs the python 2 version directly because OS defaultly contain python 2 version, so we needed to type
python3 file.py
That's the solution for the problem
python2 and python3 running command
Since a while I have not use Gundo. Today, I have an error in my code and would like to go back on other "branch" using Gundo. But when I start Gundo, I have this error message : Gundo requires Vim to be compiled with Python 2.4+ and Gundo is not working anymore. Can someone help please ?
It seems that Gundo can't work without python 2.4. The workaround I found is to use undotree git repos here. It is cool because it recognizes my gundo log, so that I don't loose anything.
I want to use pep8 as my makeprg in order to check and fix my code compliance to PEP8 (Style guide for python code).
I used the command :set makeprg=pep8\ --repeat\ %, and when I do :make it works, the error list is populated and I can use :cn, :cp and :copen to navigate and see the error list in the QuickFix window.
But as soon as I change something in my python source file the errorlist becomes empty, the QuickFix window loses its content and I cannot navigate the list anymore.
I suspect that this is caused by PyFlakes, a Vim extension that highlights Python errors on-the-fly.
How can I fix it?
pyflakes has an option that should solve your problem, just put this in your ~/.vimrc :
let g:pyflakes_use_quickfix = 0
This actually stops pyflakes from using (and breaking) the quickfix window, that is good enough for me.
See this vim extension