Home:ALL Converter>Not able to write output of python script to text file in Windows

Not able to write output of python script to text file in Windows

Ask Time:2018-09-08T14:16:28         Author:Akash

Json Formatter

I am using a python script to extract the tweets from twitter. I want to write the output into a text file.

When I run the .py file from Anaconda command prompt, it shows me the output in the command prompt. But when I try to write the same output to a file, it doesn't write anything.

C:\Users\akjain>python c:\Akash\TweetExtract.py >> twitter_data.txt

I have tried to open the Ananconda as an Administrator too. Also created the text file in the same folder where I have python script before running the script. I also tried the below code but this also did not work.

C:\windows\system32>python c:\Akash\GartnerTweetExtract.py > c:\Akash\twitter_data.txt

Edit:

Code to print the ouput to command prompt which is inside my python script is as follows:

#This is a basic listener that just prints received tweets to stdout.
class StdOutListener(StreamListener):

    def on_data(self, data):
        print (data)
        return True

    def on_error(self, status):
        print (status)

Any help would be really appreciated.

Regards, Akash

Author:Akash,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52232592/not-able-to-write-output-of-python-script-to-text-file-in-windows
shahidammer :

So my best guess is that you are facing permission issues. Why don't you copy the file to C:\\Users\\akjain> and run \n\npython TweetExtract.py > your-file.txt\n",
2018-09-08T07:34:23
yy