VSCode: show entire variable in debug console - python

when debugging python code in VSCode, how do i show the entire variable. As you can see from the image below, i am printing out the variable 'x'..but not all of it's values shows in the debugging console. it is cut off and followed by an elipse indicating there is more:
While I know I can use the '>' to show a list of each item in the set in this case, is there a way to print the entire variable as a string in the debug pane/console - much like we would be able to if we were using the command line for our venv?

for item in set(x):
print(item)

You should be able to click the > sign to the left of the variable result to expand it.

I made a simple replay. You can find the variable on the left side after using debug:
You can copy it like the following picture:
you can paste the copied content:

Related

how to get the return of pywhatkit.info() method into a variable

I am trying to get the output of the function into a variable instead of just putting it into the console
output = pywhatkit.info(search, lines=15)
but it is not working,
it just displays the texts in the cmd console instead of putting the result into the variable.
any kind of help is much appreciated
If you look at the source code, you could see that pywhatkit.info function is just delegating it's parameters to wikipedia.summary and displaying it's result to the console.
def info(topic,lines=3):
'''Gives information on a topic from wikipedia.'''
spe = wikipedia.summary(topic, sentences = lines)
print(spe)
So if you want to get the result of pywhatkit.info into a variable all you need to implement the following
output = wikipedia.summary(search, sentences=15)

In SikuliX, type(variable) always types the variable then presses enter automatically. How do I avoid pressing enter?

Sorry if this is really basic, I cannot find a workaround. I have a variable called doc that stores the number 510 that was copied from an excel cell.
I need to type it in a field, but I need to continue typing in another field on the same page afterwards.
My code has:
type(doc)
The log shows:
[log] TYPE "510#ENTER."
The full code looks like this:
type(doc)
wait(1)
type(Key.DOWN)
type(Key.BACKSPACE+Key.BACKSPACE+Key.BACKSPACE+Key.BACKSPACE)
wait(1)
type(code)
However, I can't get to the type(code) because it switches page before I get there...
Using paste() maybe solved your issue here but this is not the right way to do that as Sikuli does not automatically presses any buttons.
Your problem is probably with the doc variable itself. In your case, you probably just copied the new line character with your variable from excel and that's why Sikuli is hitting Enter. To avoid that, try stripping the new line from your variable prior to typing it, like this:
doc.rstrip()
Then do your usual type(doc) and it should be fine.
Another thing that works is: doc.strip()
It turns out sikuli writes /n after strings, so strip removes that /n.

gitpython to check for if there are any changes in files using PYTHON

I am experimenting with gitpython and I am new to it. I am trying to detect if there are any changes staged for commit.
Currently, I have a function that looks like this:
def commit(dir):
r = Repo(dir)
r.git.add(A=True)
r.git.commit(m='commit all')
But this is just the code to commit the directory. I wanna do something like, if there are changes, then display some message, else, display another message.
Anybody have any idea how do I do it in python ?
You can check for all unstaged changes like this:
for x in r.index.diff("HEAD"):
# Just print
print(x)
# Or for each entry you can find out information about it, e.g.
print(x.new_file)
print(x.b_path)
Basically you are comparing the staging area (i.e. index) to the active branch.
To get a definitive list of what's changed (but not yet staged):
# Gives a list of the differing objects
diff_list = repo.head.commit.diff()
for diff in diff_list:
print(diff.change_type) # Gives the change type. eg. 'A': added, 'M': modified etc.
# Returns true if it is a new file
print(diff.new_file)
# Print the old file path
print(diff.a_path)
# Print the new file path. If the filename (or path) was changed it will differ
print(diff.b_path)
# Too many options to show. This gives a comprehensive description of what is available
help(diff_list[0])
I found the diff object to be very useful and should give any info you require.
For staged items, use repo.index
From my testing, I found that the previous answer gave a diff output the wrong way round (ie. added files would show up as deleted).
The other option is repo.git.diff(...) which I found less useful as it gives long text strings for output rather than objects that can be easily parsed.

Having trouble playing music using IPython

I have the lines of code
import IPython
IPython.display.Audio(url="http://www.1happybirthday.com/PlaySong/Anna",embed=True,autoplay=True)
And I'm not really sure what's wrong. I am using try.jupyter.org to run my code, and this is within if statements. The notebook is also taking in user inputs and printing outputs. It gives no error, but just doesn't show up/start playing. I'm not really sure what's wrong.
Any help would be appreciated. Thanks!
First you should try it without the if statement. Just the two lines you mention above. This will still not work, because your URL does point to an HTML page instead of a sound file. In your case the correct URL would be 'https://s3-us-west-2.amazonaws.com/1hbcf/Anna.mp3'.
The Audio object which you are creating, will only be displayed if it is the last statement in a notebook cell. See my Python intro for details. If you want to use it within an if clause, you can use IPython.display.display() like this:
url = 'https://s3-us-west-2.amazonaws.com/1hbcf/Anna.mp3'
if 3 < 5:
IPython.display.display(IPython.display.Audio(url=url, autoplay=True))
else:
print('Hello!')

Spyder does not show lists and arrays in variable explorer

i don't really know why, but Spyder is not able to show lists or arrays in the variable explorer anymore. Do you have the same problem, any fixes? I have that problem on two computers.
Example:
CSV = []
for x in os.listdir(location):
if x.split(".")[-1] =="CSV":
CSV.append(location+x)
CSV = np.array(CSV)
Thank you very much!
Menu (Tools->Preferences->Variable Explorer) Shortcut (Ctrl+Alt+Shift+P)
Disable all the filters
Just make sure "Exclude capitalized references" in "Tools->Preferences->Variable Explorer" is not marked. The reason you don't see your list in variable explorer is that your list name starts with capital letters and Spyder considers it a capitalized reference. If you define it as for example 'my_csv' or 'aCSV' instead of 'CSV', you don't need to change the setting and it will be fine.

Categories