output file cannot be found

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

output file cannot be found

Ichiro
Hi,

I wrote the translator for the NestedCall in Python and tried to output the assembly file. The execution on the command prompt succeeded but I could not find the assembly file.

Just to check if I did wrong on the command prompt, I executed a simple python file called 'write.py' (attached one), which writes some words on a text file (I named text3.txt). The execution was done, but there was no file created on the designated folder.

The execution code was 'python write.py text3.txt' on the command prompt and I confirmed the current directory.

Could you give any clue to find the cause?

Thanks
write.py
Reply | Threaded
Open this post in threaded view
|

Re: output file cannot be found

WBahn
Administrator
Take a few steps back.

Instead of trying to get a command line argument AND using it to open a file AND writing to the file AND closing the file AND then looking of the end result that will be there only if all of these things succeed, check each step along the way.

First, don't use a command line argument. Just hard code a simple file name such as "junk.txt'. If that shows up, you know the problem is with successfully getting the command line argument. Put in a print statement to print the value of the filename you are getting from the command line. Is it what you expect? Are there any issues such as a tab or newline embedded in it?

If it doesn't work, there's a problem with something after that (you may still have an issue with the command line argument, but if you do, it's in addition to another problem).

Also, put your code in a try block and if there's any exceptions thrown, print out the exception message. This may not get you anywhere since it seems your program's not throwing any exceptions as it is.

You might also instrument your code by putting in simple print statements that confirm that it is, in fact, running and getting past each of the statements.
Reply | Threaded
Open this post in threaded view
|

Re: output file cannot be found

Ichiro
Thank you for your reply.

It turned out that I haven't installed Python3.7 yet on my new PC (I installed Spyder though). I found it when I instrumented a code that just simply put the print function and did not get any result on the command prompt.

I appreciated your advice so that I learned the bugging method: break down the possible causes and confirm them step by step.


Reply | Threaded
Open this post in threaded view
|

Re: output file cannot be found

WBahn
Administrator
Great!

Learning how to solve the problem is far more valuable than solving the problem. It's wonderful that you recognize this.