How to setup Visual Studio Code for debugging beem on windows?

in #beem7 years ago (edited)

Installing Visual Studio Code

At first we need to download Visual Studio Code

image.png

Setup Python

Please follow all steps from my last post:
https://hive.blog/beempy/@holger80/how-to-setup-a-minimal-python-for-using-beempy-on-windows

There is now a python environment in C:\beem\env or any other path (just replace this path by the correct one). The beem package is installed.

Setup Visual Studio Code

We need to install a extensions for using python:
Open the extensions tab (or press Ctrl + Shift + X)
Enter ms-python.python in the search field and install the python extension

image.png

In the next step we setup our python interpreter.
Open the settings tap (or press Strg+,) and enter pythonPath in the search field. Enter the pyth to the python.exe in the Python Path field. In my case, I installed an environment in C:\beem\env, so my path is C:\beem\env\Scripts\python.exe. Replace the path to the python.exe with the one on your PC.

image.png

It is also possible to edit the settings.json (by pressing Edit in settings.json in the Settings tab:)

"python.pythonPath": "C:\\beem\\env\\Scripts\\python.exe"

Replace the path to the python.exe with the one on your PC.

image.png

There may be a prompt, if we want to install the pylint package:
image.png

In my case, installation failed with:
image.png

and I installed it manually by opening the powershell and entering the following commands:

cd C:\beem
.\env\Scripts\activate
pip install pylint

Debugging a beem python script

Create a new file (Ctrl+N) and copy the following into it:

from beem import Steem
from beem.account import Account

if __name__ == '__main__':
    stm = Steem()
    acc = Account("holger80", steem_instance=stm)
    print("My vote power: " + acc.vp)

Store the file as py_test.py.

image.png

We will now run the script without debugger (Ctrl+F5 or using the menu: Debug/Start without Debugger). The script crashes with a error message:

    print("My vote power: " + acc.vp)
TypeError: can only concatenate str (not "float") to str

Now we will investigate. We enter a breakpoint at line 7 by pressing left to the line number.

image.png

We start the script with Debugging (F5) and click on the DEBUG CONSOLE:

image.png

Now we can investigate the error in the debug console:

At first we check acc.vp by writing it into the terminal:

image.png

So this works, now we enter the string inside the print command:

"My vote power: " + acc.vp

image.png

The problem is that the + does not work with a Float and a String. We try to fix it in the debug console by entering:

"My vote power: %.2f" % acc.vp

image.png

This works and we can fix the script.

We replace the line with

print("My vote power: %.2f" % acc.vp)

save the script and press restart:
image.png
It stops at the breakpoint and we can press F5 for continue.
Now everything runs through!

Sort:  

although all this coding stuff is way above me, I value tutorial type post being published on steem. Nice work

Hi @holger80!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 7.393 which ranks you at #60 across all Steem accounts.
Your rank has not changed in the last three days.

In our last Algorithmic Curation Round, consisting of 244 contributions, your post is ranked at #4.

Evaluation of your UA score:
  • Your follower network is great!
  • The readers appreciate your great work!
  • Good user engagement!

Feel free to join our @steem-ua Discord server

This post has been just added as new item to timeline of beem on Steem Projects.

If you want to be notified about new updates from this project, register on Steem Projects and add beem to your favorite projects.

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

Congratulations @holger80! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

You made more than 700 comments. Your next target is to reach 800 comments.

Click here to view your Board
If you no longer want to receive notifications, reply to this comment with the word STOP

To support your work, I also upvoted your post!

Do not miss the last post from @steemitboard:

Valentine challenge - Love is in the air!

Support SteemitBoard's project! Vote for its witness and get one more award!

Hi, @holger80!

You just got a 3% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

This post has been included in the latest edition of SoS Daily News - a digest of all you need to know about the State of Steem.

Oh yes, i did it :-) Thanks for getting this first step done!!!

I was looking like crazy to find your steemmonster api. The thing is that when i visit github and i click on your name, this steemmonster api does not appear in your projects. I found it now but now i am looking for something which you call beem.api, baby steps are small but hey, really thank you, i am already proud to be standing now.