This may be a confusing question. After writing a text file I would like to execute a command in Python which can open the text file created in a text viewing application, such as the default text editor supplied with Mac OSX. I was wondering how this could be done within the script...? I'd like to specify which program to open it in because the extension won't be automatically recognised.
Related
I took help from this website https://www.geeksforgeeks.org/make-notepad-using-tkinter/ and used the code to create a full-fledged text editor which was like the windows Notepad.
Now, I want to integrate a terminal into it so that it can run the programs there itself.
refer this:
os.system()
make sure to check the path of the file that you want to run
I use PythonWin as my main script editor.
To differentiate between scripts I use different extensions, *.py for Python 2 scripts and *.py3 for Python 3 scripts.
I have each extension opening in its appropriate version of PythonWin.exe through the HKEY_CLASSES_ROOT registry entries, so that's fine.
The problem is whenever I have PythonWin.exe version 2 running and I click on a *.py3 file it opens my script in the currently open version 2 version of PythonWin. Similarly if I have version 3 open and I open a *.py file it opens in the currently open version 3 PythonWin.
I am wondering if anyone else has had this issue and whether they have found any kind of descent work-around so each file extension opens in their respective version of PythonWin.
It turns out PythonWin.exe has some passable arguments to allow it to open more than one instance.
You can force it to open a new process by using the command
"C:\python27\Lib\site-packages\pythonwin\Pythonwin.exe" /new "%L"
Using this as the opening command in the registry entries for .py and .py3 would open each in their respective version of PythonWin.
The only disadvantage is that each time you open a new file, it will open a new PythonWin instance.
/new will also disable any Dynamic Data Exchange(Windows uses this to communicate between open applications) so the instance of PythonWin will never open any new files opened from Windows Explorer within it.
Once you have an instance open, you may as well just use the "Open" filemenu option to open new files, or just have multiple instances of each version of PythonWin open.
The thing in pythonwin.exe that looks for an existing instance and opens a *.py file in that instance is a protocol called a DDE(Dynamic Data Exchange) server. PythonWin opens one up every time it runs and when it detects a DDE server on the same channel, it passes the previous instance some python code to open the file and then terminates.
The easiest way to prevent PythonWin 2.7 from talking to PythonWin 3.9 is to have them open separately named channels to talk on.
Change the channel name in the intpyapp.py file.
Look for these two functions
def MakeExistingDDEConnection(self):
and
def InitDDE(self):
Change the channel name from "Pythonwin" to "Pythonwin37"(or something) IN BOTH FUNCTIONS
Delete any "intpyapp.pyc" files from your computer and try it out! You'll love it.
(*.pyc files store a compiled version of the code in the *.py file so no changes will be made to the running code until these are deleted)
If that still doesn't work, check out what command line is being used to run pythonwin.exe in the Windows registry
\HKEY_CLASSES_ROOT\Python.File\shell\open\command
and make sure there's no /new or /nodde parameters in the command line.
Here's an example of a good registry entry
"C:\python37\Lib\site-packages\pythonwin\Pythonwin.exe" "%L"
I have recently started using notepad++ for my coding in various different programming languages. In Python specifically, I have tried to open a basic text file (.txt), and print the text inside the file. If I run this file via just double clicking it (in Windows Explorer, not in Notepad++), it will run, and do exactly what I want it to do; print the contents of the text file. However, if I try and run it directly from Notepad++ with the line
C:\Python25\python.exe "$(FULL_CURRENT_PATH)"
then it comes up with an error telling me 'it cannot find the file specified'.
I am under the suspicion that it is using its own directory to try and find the files, so if that is the case is it possible to change it to the files directory?
C:\Python25\python.exe probably isnt your path to python ... I think you just copied it from somewhere
you should probably put the path to your python installation instead (I would guess its something like C:\Python27\python.exe
I am using Enthought canopy for data analysis. I didn't find any option to create a .py file to write my code and save it for later use. I tried File> New >IPython Notebook, wrote my code and saved it. But the next time I opened it within Canopy editor, it wasn't editable. I need something like a Python shell where you just open a 'New Window', write all your code and press F5 to execute it. It could be saved for later use as well. Although pandas and numpy work in canopy editor, they are not recognized by Python shell (whenever I write import pandas as pd, it says no module named pandas). Please help.
Umair, ctrl + n or File > Python File will do what you want.
Best,
Jonathan
Let me add that if you need to open the file, even if it's a text file but you want to be able to run it as a Python file (or whatever language format) just look at the bottom of the Canopy window and select the language you want to use. In some cases it may default to just text. Click it and select the language you want. Once you've done that, you'll see that the run button will be active and the command appear in their respective color.
I am trying to write the Python BPY -code inside Blender and noticed some editor -mode (source) and, instead of reinventing the wheel, I want to use my Vim -syntax-highlighting-etc inside Blender -text-editor. So how can I use Vim inside Blender?
You can write scripts either in an external text editor, or in
Blender's built in text editor. Move to a panel you wish to change to
be the text editor, click the editor select button and choose "text
editor" (shortcut) SHIFT+F11. Click the + New button at the bottom.
If you want, you can enable line numbers and syntax coloring with the
buttons at the bottom. Create a new script with File → New, paste the
code below into it, and save it. Or alternatively, paste the code
below into a file, and open that file with File → Open in Blender. As
name choose something with the extension .py, for example
wikibooks.py. Put it into Blender's user scripts path.
From the source you provided it looks to me that it doesn't matter what text editor you use as long as you save the python scripts to the file locations provided in that documentation (e.g. ~/.blender/scripts and other OS paths). Not very familiar with blender since I'm answering via the vim tag. Looks like there's potentially a plugin to use an external editor: http://www.blendernation.com/2011/08/02/edit-blender-text-files-using-external-text-editor-plug-in/. Also if you're on Mac then look into QuickCursor: http://www.hogbaysoftware.com/products/quickcursor/.