Perhaps you have the wrong kind of quote marks? Python only recognizes ASCII quote marks (either ' or "). This sometimes becomes a problem if using a rich text editors like Microsoft Word or copy/pasting code around different places. # SyntaxError total = 0 for line in open(’/home/values’): to… Answer from sweeneyde on discuss.python.org
🌐
Python.org
discuss.python.org › python help
Why is the print() not working! - Python Help - Discussions on Python.org
July 25, 2021 - Starting with Python, trying to do a sum inside a for loop and then print the total Outside of the for loop. Have the right indentation in place to do this but still print() returns a Syntax error! Please suggest where is this going wrong. File “”, line 3 print(total) ^ SyntaxError: invalid syntax ```py3 YOUR CODE GOES HERE total=0 for line in open(‘/home/values’): total=total + int(line.replace(‘,’,‘’)) print(total) ```
Discussions

Python 3.9, print(file1.read) with no output - Stack Overflow
I am using python 3.9.6 , pycharm community and python IDLE gave the same result, and the problem is , i assumed that if we passed th file.read() which is a string , the print command will be able to actually print it . More on stackoverflow.com
🌐 stackoverflow.com
July 31, 2021
Why won't my python code print anything? - Stack Overflow
A program I wrote wasn't printing anything when I executed it out of the terminal, so I tried the ran the following code import sys #!/usr/bin/python def main(argv): print "hell0\n" sys. More on stackoverflow.com
🌐 stackoverflow.com
Python 3.9 No Output to Console
The code below does not produce a result in the console. This is an exercise from the book Python Crash Course (I am total beginner). The code runs but nothing prints. I think it is related to the creation of a class. This is the first lesson that has a new class and an instance of that class. More on forum.sublimetext.com
🌐 forum.sublimetext.com
0
0
August 20, 2021
Syntax error on print with Python 3 - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Closed 9 years ago. Why do I receive a syntax error when printing a string in Python 3? More on stackoverflow.com
🌐 stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 68600763 › python-3-9-printfile1-read-with-no-output
Python 3.9, print(file1.read) with no output - Stack Overflow
July 31, 2021 - >>>file1 = open('t.txt', 'a') >>>file1.write('hahah') >>>file1.close() >>>file1 = open('t.txt', 'r') >>>file1.read() 'hahah' >>>print(file1.read()) >>>type(file1.read()) <class 'str'> ... After the first read(), you have read the entire contents of the file. Subsequent reads have nothing left to return.
🌐
Sublime Forum
forum.sublimetext.com › t › python-3-9-no-output-to-console › 60323
Python 3.9 No Output to Console - Technical Support - Sublime Forum
August 20, 2021 - The code below does not produce a result in the console. This is an exercise from the book Python Crash Course (I am total beginner). The code runs but nothing prints. I think it is related to the creation of a class.…
🌐
CodeRivers
coderivers.org › blog › python-print-function-not-printing
Python Print Function Not Printing: A Comprehensive Guide - CodeRivers
February 22, 2026 - A simple syntax error in the print() function call can prevent it from working. For example, forgetting the parentheses in Python 3 (although parentheses are optional in Python 2 for the print statement).
Find elsewhere
🌐
Quora
quora.com › What-is-the-reason-that-Python-3-wont-accept-old-print-function-style
What is the reason that Python 3 won't accept old print function style? - Quora
P.S. Fun fact: what looks like a function call in Python 2.7, most likely isn’t - the parentheses are probably just creating a tuple, it seems they’re not the same parentheses that are involved in function calls. But you can do: ... A better way to scale your website. Managed WordPress hosting that scales with you. Fast site, predictable costs — no surprises. ... Python 3 rejected the old print statement (print x, y) and replaced it with a print() function for principled language-design reasons aimed at consistency, clarity, and future extensibility.
🌐
Real Python
realpython.com › python-print
Your Guide to the Python print() Function – Real Python
June 25, 2025 - The code snippet above runs within an interactive Python REPL, as indicated by the prompt (>>>). Because the REPL executes each line of Python code immediately, you see a blank line right after calling print(). On the other hand, when you skip the trailing parentheses, you get to see a string representation of the print() function itself. As you just saw, calling print() without arguments results in a blank line, which is a line comprised solely of the newline character. Don’t confuse this with an empty string, which doesn’t contain any characters at all, not even the newline!
🌐
GitHub
github.com › spyder-ide › spyder › issues › 3437
Python 3 print function does not work properly in Python consoles · Issue #3437 · spyder-ide/spyder
September 20, 2016 - Description of your problem I am running python 2.7, but uses the print function from python3 in order to use the overwrite functionality. However this does not work porperly in the spyder console. What steps will reproduce the problem? ...
Author   Skottfelt
🌐
Python.org
discuss.python.org › python help
Python not printing - Python Help - Discussions on Python.org
August 24, 2021 - Hi I’m trying make a code where it prints the last lines of a file, and when i run the code, it runs fine but no output shows. I’m using the readline() command. Here is the code: with open(“MergeFiles.txt”) as File1: print("How many lines do you have?") File1Len = len(File1.readlines()) print("File 1 has: "+str(File1Len)+" Lines") print("File 1's last line is: "+File1.read(File1Len)) File1.flush() File1.close() with open ("MergeFiles2.txt") as File2: File2Len = len(File2.readlines(...
🌐
Stack Overflow
stackoverflow.com › questions › 47978601 › print-function-not-working-in-python3
python 3.x - print function not working in python3 - Stack Overflow
December 26, 2017 - import threading class PrimeNumber(threading.Thread): def __init__(self, number): threading.Thread.__init__(self) self.Number = int(number) def run(self): counter = 2 while counter*counter <= self.Number: if self.Number % counter == 0: promptLock.acquire() if(prompt):print() print( "%d is not prime number" % ( self.Number) ) if(prompt):print("number: ",end="") promptLock.release() return counter += 1 promptLock.acquire() if(prompt): print() print ("%d is a prime number" % self.Number) #strange line debug_line = 1 if(debug_line==1): if(prompt):print("number: ",end="") if(debug_line==2): if(prom
🌐
Sublime Forum
forum.sublimetext.com › t › new-to-python-print-command-not-working-in-terminal › 21103
New to python, "print" command not working in terminal - Technical Support - Sublime Forum
June 19, 2016 - I just started learning python and for some reason when I use the "print" command in python I get the time it took to complete the command but it doesn't print it in the terminal. I took a screenshot and hope someone can…
Top answer
1 of 2
1

Python is whitespace sensitive, but docstrings may prevent you from getting a proper error due to your indentation.

Looks like your code should be indented like this:

au = 1.49598e11                        #astronomical unit in meters
rx = au * np.asarray([.5,.8,.2])       #x-comp separation vector
ry = au * np.asarray([2.6,9.1,3.7])    #y-comp separation vector
rz = au * np.asarray([.05,.1,.25])     #z-comp separation vector
def svec(x,y,z):
    '''computes the magnitude and vector components of the distance between two particles.'''

    #for loop to compute vector components of separation between two particles
    rvec = []
    for i in range(3):
        if i < 2:
            vx = x[i]-x[i+1]
            vy = y[i]-y[i+1]
            vz = z[i]-z[i+1]
            rvec.append([vx,vy,vz])
        if i == 2:
            vx = x[0]-x[-1]
            vy = y[0]-y[-1]
            vz = z[0]-z[-1]
            rvec.append([vx,vy,vz])
    return rvec

comp1 = ['x-comp[m]','y-comp[m]','z-comp[m]']
r0 = rvec[0].insert(0,'particle 0->1')
r1 = rvec[1].insert(0,'particle 1->2')
r2 = rvec[2].insert(0,'particle 0->2')
print(tabulate(rvec,headers=comp1))
2 of 2
0

The indentation in your code sample seems off: you define a function but the function body is not indented. Can you make sure that the indentation in the pasted code matches what you're running?

This is important because if your print statement comes after the return statement in the function, it would explain why nothing is printed. (Unlike in some other languages, Python will not complain if you have unreachable code after a return statement.) But without seeing the actual indentation in your program, it's impossible for us to say.

EDIT: Now that the indentation has been fixed, I can confirm that the return statement will indeed prevent everything after it from being executed. Perhaps you meant to dedent all of the lines after the return statement?