Using Python shutil.copy to overwrite a file gives asyntax error - syntax

I am trying to overwrite one .png file with another using shutil.copy, but I keep getting a syntax error. The line in question is-
shutil.copy("/var/www/vk7krj/running/yoga.png", "/var/www/vk7krj/running/run4.png")
and the error is-
File "./latlong4.py", line 63
shutil.copy("/var/www/vk7krj/running/yoga.png","/var/www/vk7krj/running/run4.png")
SyntaxError: invalid syntax
with an up-arrow under the l in shutil
I have "import shutil" and also "from shutil import copyfile" in the head of the file.
Several hours of google searching has turned up nothing, so any assistance would be great.

Problem solved- turns out the error was incorrect indentation in an if-else earlier in the script- corrected that and the syntax error went away.

Related

How can I handle the error in load_svmlight_file?

when I run this code in mac:
x_train, y_train = load_svmlight_file("mq2008.train")
I get this error in bash:
-bash: syntax error near unexpected token `('
and if I run it in shell, I face this error:
NameError: name 'load_svmlight_file' is not defined
How can I solve this problem?
Welcome to StackOverflow!
IMO, you have a Python code and trying to replicate its output. If so, you should first load all Python-related imports first. This is what it means to NameError here, Python interpreter is not able to understand what it is, because this function is not part of its existing definitions it has.
If I may suggest, please spend some time to get the hands-on-learning of Python.

UTF-8 encoding error using Pandoc filters

I have been having trouble when converting a Markdown file to PDF using pandoc-eqnos filter. I typed in command line:
pandoc --filter=pandoc-eqnos file.md -o file.pdf
And get the following error message:
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\Scripts\pandoc-eqnos-script.py", line 1
SyntaxError: Non-UTF-8 code starting with '\xed' in file C:\Users\User\AppData\Local\Programs\Python\Python37-32\Scripts\pandoc-eqnos-script.py on line 1, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details
Error running filter pandoc-eqnos:
Filter returned error status 1
Installed pandoc-eqnos filter using pip. I sincerely don't know what is causing this error. Any suggestion will be appreciated. Thanks.

x=random.random(), TypeError:'module' object is not callable

I have tried to debug this program but I don't know what the error refers to. When I run my code I get this error.
enter image description here
here is my code that you can refer to:
import urllib
fh=urllib.urlopen("http://www.py4inf.com/code/romeo.txt")
for line in fh:
print line.strip()
any help will be apprriciated
the bug was that in my folder I had named a file "random.py" and used "import random " in this file. So I changed the name of the file and re-ran my code.It worked. It was a silly mistake on my part.

VBScript Expected End 800A03F6

I am getting this error while trying to run a VBScript (note this is not in a web environment - just running a VBScript on Windows):
Line: [Last line]
Error: Expected 'End'
Code: 800A03F4
Source: Microsoft VBScript compilation error
I think it is an If statement that is not closed correctly with an "End If," but I've gone through every instance of "If" in the code and cannot find the error. Any tips or tools that could help me figure out where/why this error is occurring?
There was an "Else If" - there should be no space there: "Elseif"
http://www.w3schools.com/asp/asp_conditionals.asp
Hopefully this will help someone out in the future.
In VBScript If is not the only token that requires an End. Also look for Function's and Sub's without their appropriate end statements.

Shoes packager problem

I used packager to make an executable file for the following code:
Shoes.app do
stack :margin => 10 do
#edit = edit_box :width => 1.0 do
#para.text = #edit.text
end
#para = para ""
end
end
then I got error message:
Error in C:/Program Files/Common Files/Shoes/0.r1134/lib/shoes.rb line 394utf.rb: 10:
compiler error
utf.rb: 10: Invalid char '\377' in expression
utf.rb: 10: Invalid char '\337' in expression
utf.rb: 10: Invalid char '\337' in expression
utf.rb: 10: Invalid char '\331' in expression
utf.rb: 10: Invalid char '\377' in expression
utf.rb: 10: Invalid char '\270' in expression
utf.rb: 10: Invalid char '\304' in expression
Could someone give me a hand?
BR,
DorianG
Might be something here wherein saving the file in BOM-less UTF-8 is suggested.
I had similar problems, but saving in Unix format made it work for me.
Though, another problem seems to be that the packaged .exe somehow caches the code to execute. If I change the source code, run packager to recreate the exe, and then starts the exe again, nothing seems to have happened to it. Even deleting the .exe before, or moving the source to another folder doesn't seem to solve the problem.
The only solution seems to be to rename the source file. The packager then correctly creates a new .exe with the updated code.
Has anyone had problems like this, or know of a solution? Is there perhaps a temp folder where the packager stores files, which then can't be overwritten so that the "first version" is always used? I've looked into the source code of the packager, but couldn't find anything there...
Christian
I couldn't find a way to produce a working .exe too. Tried saving the source in all possible Unicode encoding variations but still nothing. Shoes r1134. I think I red somewhere this needs to be fixed in the already long awaited next Shoes release ...
I had the same issue when using vim on windows.
I found that it does work if you use notepad and save it as the default "ANSI"
I'm also getting "Invalid char '\377' in expression". I'm saving as UTF-8 (UNIX LF) so that's not the problem, it's because I'm using underscore ('_') in my app-names. Apparently you can't use the shoes-packager on files with underscore in the name which is annoying as underscore is the ruby-convention...

Resources