Python Forum
print() statement not executing.. - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: print() statement not executing.. (/thread-3142.html)



print() statement not executing.. - bmohanraj91 - May-01-2017

Hi guys,

I am pretty new to program, I have written a program that copies files from one directory to other, issue is not in that. Issue is with the print statement, python not able to pick the print statement and execute it. Happy if solved


import sys
import os
import shutil

args = sys.argv[1:]
if not args:
  print("Type Destnination and source file")
  sys.exit(1)

Dest_dir = args[0]

Source_dir = args[1]

print("hello\n")

filenames = os.listdir(Source_dir)

def copy_to(abs_path,Dest_dir):
  if not os.path.exists(Dest_dir):
    os.mkdir(Dest_dir)

  shutil.copy(abs_path,Dest_dir)
  

for fname in filenames:
  file_path = os.path.join(Source_dir,fname)
  abs_path = os.path.abspath(file_path)
  copy_to(abs_path,Dest_dir)
  



RE: print() statement not executing.. - buran - May-01-2017

you talk about print statement, but actually in your code you have print function. Which python version do you use - in Python2 it's statement, in Python3 - it's function.
Also - do you get any error (if so - post full traceback in error tags) or simply nothing happens?
for me - using both python2 and python3, your code works fine (tested without args - so it print Type Destnination and source file as expected).


RE: print() statement not executing.. - bmohanraj91 - May-01-2017

I am using python 3.6.0, files got copied but the print function does not print on the console, no error displayed.


RE: print() statement not executing.. - Ofnuts - May-01-2017

If you don't give arguments, do you see the "Type Destnination and source file" message? The print statement is likely executed, but the output of the program (its stdout stream) is rerouted to someplace that you can't see.