I have just started using python3.3. The shell looks like this:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print ("hello world")
It prints hello world correclty, but in the command line it shows error in line 1 (i.e Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32 ) declaring it as a syntax error.
What is the problem??
You are specifying the syntax incorrectly on the command line. The correct syntax is:
$ python3 -c 'print ("hello world")'
That's not an error. That's what appears when you open the interactive interpreter by typing $ python3, telling you what version of python you have and other details (such as the date).
Related
I'm trying to use .. in a Windows long filename within Python and it is producing unexpected results.
Here is the output from the Python REPL:
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.exists(u'\\\\?\\C:\\BitBucket\\crab6\\product\\installer\\windows\\..\\usage.txt')
False
>>> os.path.exists(u'\\\\?\\C:\\BitBucket\\crab6\\product\\installer\\usage.txt')
True
(I realize the path above isn't over 260 characters and therefore the long path syntax is unnecessary, but for the purposes of this post I've made it more manageable. The outcome is the same with very long paths.)
Has anyone else encountered this, and is it a purposeful limitation of long filenames?
Trying to run simple python file in python prompt but giving an error:
content of test.py
print("Trying to print this using .py file on anaconda prompt")
Running file from python prompt
(base) C:\Users\acharbha>python
Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python C:\Users\acharbha\Documents\python\test.py
File "<stdin>", line 1
python C:\Users\acharbha\Documents\python\test.py
^
SyntaxError: invalid syntax
>>>
To execute in shell: python test.py
To execute inside the interpreter: exec(open("test.py").read())
This should help:
How to execute a file within the python interpreter?
You are trying to run it within the python interpreter. So just exit that and run the command on the terminal.
When i try to run my code all i get is this:
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
RESTART: C:/Users/Owner/Documents/School Work/Computer Science/Python/Coding Practise/Fruit Machine.py
>>>
it doesnt run, it just tells me where my file is saved... please help.
It's likely that your code is running properly, but nothing in your code is outputting anything (i.e. you haven't put any prints or inputs). So your code is running as programmed, but if you're expecting something to be printed, you need to use the print and input statements.
The environment is Python 3.6 and win10 x64.
I wanted to output the string '123456\rabc' by using print(), the right result should be 'abc456', but I got different answers.
1. IPython:
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 5.3.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: print('123456\rabc')
abc456
In [2]:
2. python.exe
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:25:24) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print('123456\rabc')
abc456
>>>
3. Sublime Text3
print('123456\rabc')
I run the file test.py, and the result was this:
123456
abc
[Finished in 0.1s]
4. PyCharm 2017.2.3 x64
I still run test.py, the result was:
C:\Users\user\Anaconda3\python.exe C:/Users/user/Desktop/cv/test.py
abc
Process finished with exit code 0
So I don't know why these results are different.
How can I run scons on Windows 10 when Python 3.6.1 and Python 2.7.13 is installed? When typing python into my command window I get the following output:
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Since I personally use Python 3.6.x this is fine for me and I do not want to change this.
When typing py -2 into my command window I get the following output:
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
scons does not work with Python 3.x. It needs to be executed with Python 2.7.x. How can I "tell" scons to use Python 2.7.x?
When I just type scons into the command prompt I get the following output:
PS C:\dev\projectX> scons
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007050 (most recent call first):
Try Changing line 23 in scons.bat from:
python "%scriptname%" %*
to
py -2 "%scriptname%" %*
Note that work on getting SCons to run under both py 2 and py 3.5+ is mostly done and should be released in the next month (or so)
Before running scons in Powershell, amend the PATH environment variable to put your Python 2.7 installation at the front. Something like:
SET PATH=C:\Python27;%path%