python-interactive

Where does Python's interactive prompt “>>>” output to?

天大地大妈咪最大 提交于 2019-12-05 00:40:45
I've run into a somewhat unusual situation. I'm trying to script the interactive console (for teaching/testing purposes), and I tried the following: $ python > /dev/null Python 2.7.3 (v2.7.3:70274d53c1dd, Apr 9 2012, 20:52:43) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> print 3 >>> 3 isn't printed, so clearly everything else was on stderr . So far so good. But then we redirect stderr : $ python 2> /dev/null >>> print 3 3 >>> How can the prompt be printed in both cases? EDIT: Redirecting both stdout and stderr

Interactive Slider Bar Chart Color Control

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 12:28:56
I have four sets of random normal distributed numbers. The means are used to plot bar chart with each set's 95% confidence intervals plotted with errorbar. Given a value y, four different colors will be set to the bars corresponding to the four ranges y is in: 1. lower bound to avg; 2. avg to upper bound; 3. below lower; 4. above upper. I want to use a slider to control the y value and update the bar color each time I slide, I tried to use the following code but the bar charts cannot be plotted every update. Could someone give me some ideas? import matplotlib.pyplot as plt import pandas as pd

Why use Python interactive mode?

笑着哭i 提交于 2019-11-30 07:57:42
问题 When I first started reading about Python, all of the tutorials have you use Python's Interactive Mode. It is difficult to save, write long programs, or edit your existing lines (for me at least). It seems like a far more difficult way of writing Python code than opening up a code.py file and running the interpreter on that file. python code.py I am coming from a Java background, so I have ingrained expectations of writing and compiling files for programs. I also know that a feature would not

Why does typing a variable (or expression) print the value to stdout?

跟風遠走 提交于 2019-11-29 13:25:54
Take this example: >>> 5+10 15 >>> a = 5 + 10 >>> a 15 How and why does Python do this without an explicit print statement? If I do the same thing in an IPython cell, only the last such value is actually printed on stdout in this way: In[1]: 5+10 1 Out[1]: 1 Why does this happen? When Python is in "interactive" mode, it enables certain behaviors it doesn't have in non-interactive mode. For example, sys.displayhook , originally specified in PEP 217 . If value is not None, this function prints it to sys.stdout, and saves it in __builtin__._ . sys.displayhook is called on the result of evaluating

Why use Python interactive mode?

巧了我就是萌 提交于 2019-11-28 10:44:50
When I first started reading about Python, all of the tutorials have you use Python's Interactive Mode. It is difficult to save, write long programs, or edit your existing lines (for me at least). It seems like a far more difficult way of writing Python code than opening up a code.py file and running the interpreter on that file. python code.py I am coming from a Java background, so I have ingrained expectations of writing and compiling files for programs. I also know that a feature would not be so prominent in Python documentation if it were not somehow useful. So what am I missing? Let's see

Why does typing a variable (or expression) print the value to stdout?

亡梦爱人 提交于 2019-11-28 07:01:24
问题 Take this example: >>> 5+10 15 >>> a = 5 + 10 >>> a 15 How and why does Python do this without an explicit print statement? If I do the same thing in an IPython cell, only the last such value is actually printed on stdout in this way: In[1]: 5+10 1 Out[1]: 1 Why does this happen? 回答1: When Python is in "interactive" mode, it enables certain behaviors it doesn't have in non-interactive mode. For example, sys.displayhook, originally specified in PEP 217. If value is not None, this function

What is the meaning of a forward slash “/” in a Python method signature, as shown by help(foo)? [duplicate]

两盒软妹~` 提交于 2019-11-26 09:45:50
问题 This question already has an answer here: Python: What does the slash mean in help() output? 2 answers In the signature returned interactively by help(foo) , what is the meaning of a / ? In [37]: help(object.__eq__) Help on wrapper_descriptor: __eq__(self, value, /) Return self==value. In [55]: help(object.__init__) Help on wrapper_descriptor: __init__(self, /, *args, **kwargs) Initialize self. See help(type(self)) for accurate signature. I thought it might be related to keyword-only