-2

I am using Notepad++ as an editor and I am running Python 3 from Notepad. This is the code:

import sys

def write():
    print ("Creating new file")
    name = 'NewFile.txt'
    file = open(name,'w')
    file.close()
write()

The problem is not the code itself, I think. When I run the code from Windows PowerShell like this: python code.py, it works fine and creates the file, but this is creating the file using Python 2.7. I need to use Python 3.

When I run Python 3 from Notepad++ the file won't be created.

I tried running Python 2.7 from Notepad++ but it just doesn't work. I run it like this:

C:\Python27\python.exe -i "$(FULL_CURRENT_PATH)"

or with Python 3 I run it like this:

C:\Python35\python.exe -i "$(FULL_CURRENT_PATH)" .

I also run Notepad++ as administrator.

I think I could solve this by running Python 3 alongside Python 2 in PowerShell, but I don't know how and the answers to these questions do not work for me:

I am open to changing my editor (Notepad++) or any solutions really.

So, how can I make Notepad++ create a new file? Or How can I make Python 3 run in PowerShell? Or Which editor could I use to fix this? Or maybe my code is just wrong.

Edit: When I say it doesn't work I mean that the file will not be created even tough my code runs (no error msg).

To be clear, what you're describing seems to be: a) when you run your file manually from the command prompt, it gives the expected results; b) when you run it instead through Notepad++, you don't see any evidence that it runs at all. Is that right?.

Yes, that's right. I'm also not sure what is the interactive interpreter.

5
  • 2
    What do you mean "doesn't work"? Does your program throw an error? Does a kitten dance across your screen? Be specific. Commented Oct 27, 2015 at 22:22
  • To be clear, what you're describing seems to be: a) when you run your file manually from the command prompt, it gives the expected results; b) when you run it instead through Notepad++, you don't see any evidence that it runs at all. Is that right? Commented Oct 27, 2015 at 22:40
  • In particular, since you're already running Python with -i, does the interactive interpreter appear when you run it from notepad++? Commented Oct 27, 2015 at 22:55
  • What result do you get when you run both statements without -i from PowerShell? Your code works just fine for me in both Python 2.7 and 3.5. Commented Oct 27, 2015 at 23:41
  • When I run it without the -i it just dosn't create the file. Commented Oct 27, 2015 at 23:44

2 Answers 2

0

Most likely the file is being created, but not in the place where you expect it. You define the file without a path, so it's created in the current working directory. Check the program directory or the system directory for the file.

Specify output files with the full path to avoid this issue:

import sys

def write():
    print ("Creating new file")
    name = 'C:/path/to/NewFile.txt'
    file = open(name,'w')
    file.close()
write()
Sign up to request clarification or add additional context in comments.

1 Comment

THIS IS IT. Thank you.
0

I think the problem is related to the encoding of your input file. When you open the file, put an encoding option to match your editor.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.