I'm writing Python on Spyder. Please see my code below:
import pandas as pd
data = pd.io.excel.read_excel('Data.xls')
CMT_column = data['CMT']
"data" contains a column called "CMT." What I'm trying to do is create a variable called "CMT_column" that contains the values of the "CMT" column.
Here's the problem. After I run the code, only "data" appears in the variable explorer. "CMT_column" is not there. But if I call "CMT_column" in the IPython console, it shows the values of "CMT" as expected. So I guess the variable has been created after all, but why is it not visible in the variable explore?
Thanks in advance for any help.
Go to Variable explorer window.
Then you have options button right hand side.
Click on it,Untick the option Exclude all uppercase preferences as shown in image.
It seems that Spyder's variable explorer does not like variables with upper case: try rewriting CMT_ as cmt_.
I just added the below library then it works
from IPython.display import display
display()
Related
I am trying to recreate the notepad. I have added a lot of shortcut keys with a combination of two keys. I am trying to make a three combination shortcut, which will be Ctrl+Shift+s. But when I used <Control-Shift-Key-s> it's not working. I had even tried app.bind<Control-Shift-KeyPress-s> which I found at the Control+Shift+Tab key binding in stack overflow. When I used Tab instead of s that worked, when I use s nothing happens. I want to create a key binding of Control+Shift+s. How Can I Do That?This Is My Code:
from tkinter import *
app = Tk()
def SaveAs(event):
#Some code to save as new file.
print('Pressed Ctrl+Shift+s.')
app.bind_all('<Control-Shift-Key-s>', SaveAs)
Make sure that you are not mixing up uppercase and lowercase, because in Tkinter, "<Control-S>" means CTRL-SHIFT-S and "<Control-s>" means CTRL-S.
So, this line:
app.bind_all('<Control-Shift-Key-s>', SaveAs)
must be
app.bind_all('<Control-S>', SaveAs)
I would like to know if there is a way to update a panel pane content through a python callback.
If I define a Parameterized custom class the following way:
import panel as pn
pn.extension()
import param
class Myclass(param.Parameterized):
letter = param.ObjectSelector(
objects=['a', 'b', 'c', 'd'],
default='b',
)
#param.depends('letter')
def text(self):
return(pn.pane.Str(self.letter))
instance = Myclass()
If I output this instance in my notebook, I get the following:
pn.Row(instance.param.letter, instance.text)
yields:
However, when I select another entry in the dropdown list, the text on the right is not updated:
I know that the parameter has been updated, and that the text callback is fired (through debugging). Yet, no update is done in my notebook.
I feel that this example is very similar to the Sine wave example in the documentation (https://panel.holoviz.org/user_guide/Param.html), but I don't get what I am doing wrong...
Ideally, the answer should also work with a panel.pane.HTML as well as a panel.pane.Str.
I tried your code in jupyter notebook and it works: the text gets updated when the dropdown changes.
If I try it in my jupyter lab it doesn't work, but I have that more often. I think with me it's a jupyter version / installation thing.
So I think your code is correct. You could try updating your jupyter notebook or your panel or param packages.
I have a file named PushButtonType.py where I define two variables:
OK = 0 # acts like a OK button.
""" acts like a cancel button. """
CANCEL = 0
In another file, I import and use those variables:
from PushButtonType import CANCEL, OK
foo = CANCEL
bar = OK
I want the comments from the first file to be visible in the Quick Documentation (Ctrl+Q) functionality of PyCharm. Currently, when I put a cursor on one of the variables and press Ctrl+Q, I get a message saying "No documentation found" (see screenshot below).
I would like the comments be visible in the Quick documentation popup. How can I do this? Is there some special format of comments?
With 2018.2 EAP:
bar = 1
"""bar variable"""
I am attempting to complete a simple process of opening a web/browser based document, selecting a field within said document, and then copying it so that it goes into my operating system's clipboard. Here's the specs :
Windows 7
Google Chrome ( latest stable )
Python 3.5
pyautogui for keyboard/mouse control
Here is the field I am trying to work with ( http://screencast.com/t/jt0kTagb ). When that little arrow is clicked it pops open to reveal a calendar to pick a date. If you click directly in the field instead it highlights the field's contents. When I manually press CTRL+C in this situation the field's contents go right into the clipboard as expected.
I've tried two methods of getting the field to go into my clipboard. The first was leveraging pyautogui's keyDown/up and press functions which essentially looked like :
imageCoord = noClick("img/date.png")
x, y = pyautogui.center(imageCoord)
pyautogui.click(x, y + 20)
pyautogui.keyDown('ctrl')
pyautogui.press('c')
pyautogui.keyUp('ctrl')
I then attempted to just use the app menu that appears if you right click on something which looked like this:
imageCoord = noClick("img/date.png")
x, y = pyautogui.center(imageCoord)
pyautogui.click(x, y + 20, button='right')
pyautogui.press("down", presses=2)
time.sleep(1)
pyautogui.press('enter')
Lastly I tried the pyautogui.hotkey() function which looked like this :
imageCoord = noClick("img/date.png")
x, y = pyautogui.center(imageCoord)
pyautogui.click(x, y + 20, button='right')
pyautogui.hotKey('ctrl', 'c')
In all three events the field is indeed selected and as best as I can tell the keypresses are going through as all other presses/functions that happen prior go off without a hitch.
The problem that I am facing is that when I do this manually in the same fashion as both of those scripts above I am able to get the contents. When I use the scripts, the clipboard is never updated/populated with the field's contents. Is there something I am overlooking or not considering when working with Python and Window's clipboard?
In the end all I am trying to do is put that value into an excel sheet. Any advice would be appreciated!
I have also discovered this issue on a different automation script, and have been working on troubleshooting it for several days. I'm also on Python 3.5 and Windows 7. I can rule out that it has anything to do with Google Chrome, as my particular script is actually working with SAP.
The documentation for pyautogui on Read the Docs (https://pyautogui.readthedocs.io/en/latest/cheatsheet.html#keyboard-functions) gives a direct example of using Ctrl + C to copy text to the clipboard, so I can verify you're not actually doing something wrong. I believe you're just looking at a bug here.
I have opened an issue on the project's GitHub page:
https://github.com/asweigart/pyautogui/issues/102
Use the PyAutoGui module.
pip install PyAutoGUI
We can easily use HotKey combinations.
See docs: https://pyautogui.readthedocs.io/en/latest/keyboard.html#the-hotkey-function
Pressing Ctrl+C
>>> import pyautogui
>>> pyautogui.hotkey('ctrl', 'c')
I found the solution!
pyautogui.keyDown('ctrl')
pyautogui.keyDown('c')
pyautogui.keyUp('c')
pyautogui.keyUp('ctrl')
In my script I had to use root.update() after.
I am trying to create a program in tkinter that allows people to rename a log file to whatever is typed into a text entry box. However this is not going to plan.
EDITED Thanks to Bryan Oakley.
I have slaved the rename function to a button however my new issue is that the values for contents are a weird set of numbers. These appear to be randomly generated every time I run the rename function.
These numbers look like
44499952get
44452520get
46401376get
46400496get
44688048get
44697440get
Can anyone please help or explain what these numbers mean?
Look at this code:
newname_ent = Entry(self,width = 50,)
contents = newname_ent.get()
It seems highly unlikely that the user will be able to type in something in the millisecond or so between creating the widget and getting the value.
You need to create a button or set an event binding that will call a function after the user has the chance to enter some information. That function is where you will put the code to do the rename.