Python: Running Code from Notepad++ to the Python Console [duplicate] - python

This question already has answers here:
How do you run a python script from within notepad++? [duplicate]
(6 answers)
Closed 6 years ago.
I'm attempting a small coding project; a simple encryption program. I was wondering if I would be able to directly run my Python code from Notepad++, or if there is a different program that could do this task (preferably free). Not that I have to have said feature, it would just make things easier for me.
Sorry if this was an off-topic question. If so, I sincerely apologize.
Thanks in advance!

Wing IDE and PyCharm (My favourite personally) are really powerful IDE's that can run and debug your application all inside the same environment. Alongside features like auto-completion, support for documentation, version control support right out of the box, and multiple build configurations (there's way more features to list here!), they make writing and testing code more efficient.
Otherwise, you can always run your code via a shell, though the back and forth makes workflow less efficient.
The community edition is free, and very powerful still:
https://www.jetbrains.com/pycharm/download/

If you want a text editor that will run the code directly, then try PyCharm.
Otherwise open up a command prompt, save the file (e.g. simplencrypt.py) and then run python.exe simplencrypt.py in the command prompt when you want to run it.
I don't think you will be able to run your code directly from Notepad++.

Related

Best way to write Python Scripts on a Mac (IDE?) [duplicate]

This question already has an answer here:
What IDE to use for Python? [closed]
(1 answer)
Closed 9 years ago.
I would love to find out what the best way to go about writing Python scripts on a Mac would be. I've gone through two ways (mind you, I'm trying to avoid using vim because I want an IDE rather bland text editor). I went through using PyDev in Eclipse (the more I went through their recommendations and steps, the more of a hassle everything seemed to be.. although I do have everything set up and it can compile.. I want to know if there's a better way. I'm not too fond of Eclipse as is) and I tried to set up Xcode through the following steps: Xcode4 to run Python scripts. The problem with the Xcode version, is I would have to consistently setup the project like this every time. That, and every time I compiled something that needed to create a file it didn't (say using the command conn = sqlite3.connect('list.sqlite3'). Is there a simple way to do this? I've been trying to follow various iOS tutorials that want me to use python scripts (which I'm not familiar with at all) such as raywenderlich.com and Oreilly tutorials. Can anyone provide some guidelines on the best way to go about this?
Personally, I prefer the one that is found on the official Python website, IDLE, which can be downloaded here. It is very easy to deal with, and with the Shell it offers an area to test things out on, it has more than Eclipse can offer- in my opinion. I'm sure that people would feel the complete opposite that I do, but with my experience, IDLE is the way to go.
I think PyDev in Eclipse is pretty good. For scientific programming I wrote the following installation guide:
http://hywelowen.org/installing-python-for-scientific-computing-on-osx/
Spyder appears to be a decent alternative, but I haven't used it myself.

Debugging IDAPython Scripts outside of IDAPro

I'm kinda new to scripting for IDA - nevertheless, I've written a complex script I need to debug, as it is not working properly.
It is composed of a few different files containing a few different classes.
Writing line-by-line in the commandline is not effective for obvious reasons.
Running a whole script from the File doesn't allow debugging.
Is there a way of using the idc, idautils, idaapi not from within IDA?
I've written the script on PyDev for Eclipse, I'm hoping for a way to run the scripts from within it.
A similar question is, can the api classes I have mentioned work on idb files without IDA having them loaded?
Thanks.
Now I may be wrong for I haven't written any IDA script for long time. But as far as I remember the answer to your first question is no. There is the part that loads the IDA script and prepare the whole environment so you could re implement it and create your own environment, however I would not recommend that.
What I can tell you is to consider running your script from command line if automation is what you are aiming for. IDA python (as well as any other IDA plugin) have a good support for running scripts from command line. For performance you can also run the TUI version of IDA.
There is also a hack for that enables you to launch a new python interpreter in the middle of the IDA script. It is useful for debugging a current state yet you will still need to edit the python file every time to launch the interpreter.
Here is the hack:
import code
all = globals()
all.update(locals())
code.interact(local = all)
Anyway - logs are good and debug prints are OK.
Good luck :)
We've just got a notice from one of our users that the latest version of WingIDE supports debugging of IDAPython scripts. I think there are a couple of other programs using the same approach (import a module to do RPC debugging) that might work.

hiding python code [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do I protect python code?
How do I hide my python code, I don't want the code to be available to everyone to see.
I know python is interpreted, but is there a way, tool .. etc to allow someone to use the software without being able to see the code?
You can reduce it to pyc files, but that's not really like full compilation. Python isn't really designed to be able to 'hide' code. The only way to fully hide implementation details that I know of is to deploy all your core logic on a server and expose it as services to your distributed app.
Maybe Pyrex might help you. It is a python to C compiler ; it is intended to let you make modules available to python. That way, you could choose what to hide from the user (as it would be in an opaque module) and what to show.
You could probably (after talking with some lawyers) plaster your code with license info (legally) preventing 3rd parties from using your code in ways that you don't want...but as other have said, if the user can run your code on their machines, they can "see" it (if they're determined enough at least) -- even if bundled in an exe or in pyc files...
Compile it and/or create an executable file with it?
http://www.py2exe.org/

How can I compile a Pygame program to a Windows .exe [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How can I make an EXE file from a Python program?
I have found several links talking about what to do, but I am unsure of how to use them. They often say to just use the code, but they don't say if I should put it in the terminal or use it to make a program to run. Many recommend the use of py2exe but when I try to use it it will not run because it says I do not have python 2.6 in my registery. I am rather new to the more complicated side of programming and any help would be appreciated. I am running windows vista.
This is certainly a duplicate question, but I'd recommend using py2exe. We probably need more information on how or why you are failing.

Debugging Python code in Notepad++

I use Notepad++ for writing and running Python scripts. It is a great text editor, except for debugging. Is there a way to step through the code, use break points, view variable values etc. in Notepad++ like you can in Visual Studio?
Does such a plug-in exist? Not that I know of. I agree completely with qor72 on that note.
Is it possible to create such a plugin / functionality? Possibly.
After doing some quick digging, I did find a plugin that looks promising, Python Script. In short it allows you to run python scripts that can access the NPP modules (file menus etc...) as well as the Scintilla Methods which appear to give access to things like the markers on the pages.
To accomplish such a feat I could see the task being broken into a few large blocks (I feel a new open-source project coming on...)
Using Python Script, integrate the python debugger(PDB) as mentioned by Shashi.
Using the Scintilla Methods, add trace back calls where a NPP marker is placed
Redirect PDB outputs and process them to show where the file is stopped (again using the Scintilla methods).
While at the newly created breakpoint and using PDB determine all of the variables in the current namespace. Take this info and dump it to a CMD window, or if you want to get fancy some GUI created with Tk / wxPython
Closing Thoughts
While I think it's possible to create such a plug in, it would be quite an undertaking. Along that line, you might be better off trying to find a different editor that has this built into it already and just create macros (or whatever the IDE calls them) to add in the things you like most about NPP.
Please note that I am a daily user of NPP and have been for many years so I definitely understand why you'd like to have the functionally added to NPP. One of my favorite things about NPP is the speed in which it opens and searches files... moving to a bloated IDE, IMO, would not be worth it to me.
My current work flow is to do all of my editing in NPP and just double click to run the modules. If it fails or goes off in the weeds, I launch IDLE to debug it.
I really hope someone tells me I'm wrong (I'd love to have that feature in Notepad++) but, Notepad++ is designed as a programmers editor, not an IDE. While it has a lot of cool functionality, that level of debugging isn't part of the core tool.
Not seeing anything in the npp-plugins either.
I think python debugger
is the best option if editor is not providing facility :)
Quick guide:
from pdb import set_trace as bp
code
code
bp()
code
code
At the (Pdb) prompt, enter s to step, p foo to print foo, and c to continue executing the code until hitting another breakpoint.
Have you thought of using Komodo.
It's open source and has ports for Windows, Linux and MAC (I think).
This may be an alternative, and if you want some advice from notepad++ users, have a look at the following post on this very site:
Komodo Edit and Notepad++ ::: Pros & Cons ::: Python dev
Some npp users here seemed to have made the switch for python editing running etc...
personally don't know much about debugging on Komodo but as it's an IDE so would be surprised if you couldn't do it easily
I don't really see why Shashi's answer hasn't been upvoted. For the link that he has given supplies a way to step through python scripts as the OP has requested.
So for all who don't know about the pdb module, upon importing it the pdb.set_trace() function allows one to step through the area of code after it. And it is very much similar to the visual studios method of debugging. While you're stepping through the code you are able to input a variety of commands.
One of them is p <expression> and that allows the user to print the current state of variables within the local and global scope.
I know it's 11 years on, and I'm a bit late to the game, and I know it's not Notepad++ but please do consider Visual Studio Code.
It's free, easy to install (both the editor itself plus any python interpreters it uses) and it's widely used and nowhere near as bloated as it's Visual Studio counterpart. It also appears to be the IDE of choice for a lot of Cisco-related course material.
Write your code, click to the left of code pane to insert your breakpoints click the Debugger icon (highlighted), and you're away:

Categories