Am observing issues printing in python when using os.listdir - python-3.x

I
am not able to understand why all below prints work when I comment the first one. But when I uncomment the first print(os.listdir....), I get an error from the interpreter: why is this so?
import os
print(os.listdir(r"\\ftlengnas.eng.test.net\CWCDevops$\Dms\Staging\APS\Roles\\")
print('c:\waste')
print(r'c:\waste')
print(r'c:\waste\\')
print("c:\waste\\")
OutPut:
print('c:\waste')
^
SyntaxError: invalid syntax
Process finished with exit code 1
I don't get any error when i comment the first print(os.listdir.....)

You are missing the last ) in that print statement.
print(os.listdir(r"\\ftlengnas.eng.test.net\CWCDevops$\Dms\Staging\APS\Roles\\")

Related

script crashing with error message: "couldn't execute bsub"

our IT updated LSF farm/OS and now our Tcl script does not work anymore: within our script we executing "bsub -q reg -R "rh70" csh_file" in a loop.
for unknown reason, at some point during the loop 'on 5th element' we are getting following error message: "couldn't execute bsub" as if command is unkown...
we don't understand why starting at some point in the loop the same command does not work anymore... can you help me understand this issue?
Thanks,
Chris
sript is supposed to work without any issue within foreach loop (as it was the case before IT update LSF/OS).

Why won't my batch file run? Syntax Error

I keep getting a syntax error against the "C" in "C:\Users".
`#! python3
print('Hello world')`
#C:\Users\AK\MyPythonScripts>py.exe hello.bat
# File "hello.bat", line 1
# #py C:\User\AK\MyPythonSctipts\hello.py %*
# ^
#SyntaxError: invalid syntax
I've tried adding "\". I can't figure it out. Following along in "Automate the Boring Stuff." (Lesson 22)
#I keep getting a syntax error against the "C" in "C:\Users".
`#! python3
print('Hello world')`
#C:\Users\AK\MyPythonScripts>py.exe hello.bat
# File "hello.bat", line 1
# #py C:\User\AK\MyPythonSctipts\hello.py %*
# ^
#SyntaxError: invalid syntax
I expect to run the batch file and added a "#pause" feature, but the program won't execute since "C" is an invalid syntax.
May not the perfect answer you are looking for, but let me share in general essense how you run a python script in windows.
Open Command line: Start menu -> Run and type cmd
Type: C:\python27\python.exe C:\Users\Awesome\Desktop\Adel.py
In your system, your python .exe location might a bit different or you could be using python3, but overall format is specify you python exe first followed by your script's full path (<python.exe> <python-script-full-path>
I figured it out! My command prompt path wasn't set properly. I went to "My Computer" -> right-click -> Properties -> Advanced System Settings and changed my environment variable.

after install ns2: syntax error near unexpected token 'You'

after install ns2 i meet this problem
IMPORTANT: command not found
bash: /home/tuanhoang/.bashrc: line 144: syntax error near unexpected token You'
bash: /home/tuanhoang/.bashrc: line 144:(1) You MUST put /home/tuanhoang/ns-allinone-2.35/otcl-1.14, /home/tuanhoang/ns-allinone-2.35/lib,
syntax error near unexpected token 'You'
I am using ubuntu 16.04. How can i solve this problem ? Thank all of you guys for your responds
This looks like some program has put a comment in your ~/.bashrc file without properly prefixing each line with #.
Read the comment in the file and follow its instruction. Then either remove it or comment it out properly by prefixing it with #.

Example cx_oracle does not work, python3.3

When I execute my file test_cx_oracle.py with a python 3.3 interpreter it errors with the following output.
**File "test_cx_oracle.py", line 3
**print con.version"**
^
SyntaxError: invalid syntax**
The contents of this file are as follows,
import cx_Oracle
con = cx_Oracle.connect('system/diamondmine#127.0.0.1/XE')
print con.version
con.close()
What does this error mean?
In python 3.x the the print statement has been replaced by a print function.
Since functions must be called by having a set of trailing () (which contain arguments to the function), you must add them to print calls in python 3.x. In the case of the print function the usual syntax is just to pass the value you wish to be printed to the print function directly.
With that in mind, changing line 3 to the following should correct your error.
print(con.version)

Whats wrong in this for loop?

There are few scripts getting called in my main script, one of which when executed separately executes well, but when executed from the main, gives an error as below,
((: s<=: syntax error: operand expected (error token is "=")
s is my variable in my for loop as,
for((s=1;s<=$someVar;s++))
I'm exporting this someVar from my main script, so that this script can use that var, however its already able to get the value of that var.
someVar is not set with a value.
I'm able to reproduce it with this:
for((s=1;s<=$someVar;s++)); do
:
done
Error output:
... 3: ((: s<=: syntax error: operand expected (error token is "=")
P.S. You're probably running Bash 3.x.

Resources