Python Forum
print() statement not executing..
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print() statement not executing..
#1
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)
  
Reply
#2
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).
Reply
#3
I am using python 3.6.0, files got copied but the print function does not print on the console, no error displayed.
Reply
#4
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.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why doesn't this print statement work? stylingpat 10 5,780 Mar-23-2021, 07:54 PM
Last Post: buran
  Runs perfect in Python but fails to print last statement when converted to .exe. Help sunil422 3 2,840 Aug-13-2020, 01:22 PM
Last Post: deanhystad
  Taking brackets out of list in print statement pythonprogrammer 3 2,418 Apr-13-2020, 12:25 PM
Last Post: perfringo
  capture print statement written in Stored Procedure in SQL Server brijeshkumar_77 0 2,567 Feb-18-2020, 03:22 AM
Last Post: brijeshkumar_77
  printing a list contents without brackets in a print statement paracelx 1 2,147 Feb-15-2020, 02:15 AM
Last Post: Larz60+
  Embedding return in a print statement Tapster 3 2,295 Oct-07-2019, 03:10 PM
Last Post: Tapster
  Quotes and variables in print statement Mark17 4 3,064 Sep-13-2019, 04:07 PM
Last Post: Mark17
  Passing print output into another print statement Pleiades 6 3,166 Sep-08-2019, 02:37 PM
Last Post: Pleiades
  If statement won't print coreywratchford66 1 2,426 May-15-2019, 12:26 AM
Last Post: ichabod801
  if /else statement not executing correctly bluethundr 3 2,797 Apr-15-2019, 10:20 PM
Last Post: bluethundr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020