Building a Python Coding Environment in Windows
To be honest, my computer files are not organized. Yes, and you know what? Most of my scripts (Perl and Python) sits on one directory: C:\Perl64\scripts. And inside that directory, contains mixed files of Perl scripts, Python Scripts, output folders, text files, dictionaries, CSV files, etc. It’s sad that I can’t find the time motivation to organize my scripts.
Well, I came up with this pretty neat trick. I used it in Java, but for this post, I’ll be applying it in Python. I will place all of my Python scripts in my personal drive R:\ and under the folder R:\Python. Well, that sounds too simple doesn’t it? Let me expand the idea.
I’m on Windows, and yes I have ArchLinux on dual-boot, but I’ll apply this to Windows for now. One great reason why I love coding in Windows, is because I love Notepad++. Sadly, I’m not gifted with the ability to write code on Vim, or E-macs (I haven’t tried). And oh, my current Notepad++ style is Obsidian, and it’s just so comfortable to use.
Anyway, as I’ve mentioned, I’m on Windows. But for example I’m browsing on my favorite browser (Chrome), and I just had an idea for a neat, cool script. So I’ll fire up notepad++, change the language to Python, then fire up cmd, cd to my Python directory, and start to code (and debug). But wait, that sounds too long, well for me. It’s kind of boring that I have to do that repetitive process over and over again, every single day. Plus, the files is pretty much unorganized. What to do now? Well of course, hack it!
Now, let’s get back to the situation. Say I’m browsing the interwebs (with my favorite browser Chrome) and I got an idea for the script. I would normally open notepad++ first, but this time, I think it would be better to access the python directory first with cmd. The quickest way to access cmd, wherever you are, is by the Run Dialog (That’s Win+R for the noobs). Just type in cmd and you’re done. But I have to cd to my python directory, and re-enter the drive if it’s not on C:\, that’s 2 commands already! Now, we can fix this, and we need a script of course. For this one we can use a batch script. Now now, many people say that this is old school, but let’s face it, we’re on Windows.
@echo off echo. echo Time for some pure python awesomeness! echo. cmd /k "cd R:\Python && R:"
Save it with any filename you wish. For me, I saved it as pyc.bat in the Python bin folder (make the directory is included in your PATH directory), so I can just type pyc on the Run Dialog box.
We’re done on the cmd part, now for notepad++. For this, the script we’ll be using is a python script. And to start, create a new script located on the Python script folder.
#!/usr/bin/python
'''
This script is used to create new (organized)
Python scripts
'''
import os
import sys
def main(arg):
fdir = arg
arg += '.py'
#Create directory for the script.
os.mkdir(fdir)
#Create the file inside the directory
fo = open('%s\\%s' % (fdir, arg), 'w')
#Change or add your own lines if you want.
fo.write('#!/usr/bin/python')
fo.close()
#Open the script in Notepad++
#If your notepad++ installation directory is different,
#change it.
notepad = '"C:\\Program Files (x86)\\Notepad++\\notepad++.exe" '
os.system('%s%s\\%s' % (notepad, fdir, arg))
os.system('cmd /k "cd "%s"' % fdir)
if __name__ == '__main__':
main(sys.argv[1])
To use it, simple do something like:
R:\Python>new coolscript
And it will create a directory based on the parameter you passed, and a script inside it. And opens it in Notepad++, also it will make the cmd cd to the newly created directory. The only issue here is new.py is visible to the naked eye in the Python scripts folder. To hide the file, just do:
attrib +S +H +R new.py
And it will remain hidden (unless you chose to show system files in folder options). S means system, H means hidden, and R means read only.
TRIVIA: It’s how most malware hide themselves in Windows.
Now, we have a good, organized python coding environment in Windows. If you have any comments or suggestions, just drop a comment. Cheers!