Python Forum

Full Version: print() statement not executing..
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
  
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).
I am using python 3.6.0, files got copied but the print function does not print on the console, no error displayed.
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.