python-interactive

Is it possible to make Python interpret a script line by line and generate output as if from an interactive shell? [duplicate]

拟墨画扇 提交于 2019-12-25 05:56:34
问题 This question already has an answer here : Simulate interactive python session (1 answer) Closed 5 years ago . Considering the following interactive shell session. Python 2.7.5+ (default, Feb 27 2014, 19:37:08) [GCC 4.8.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> 1+1 2 >>> 2+5 7 >>> "foo" 'foo' >>> Observe how, after every line, the interpreter will echo the result to the console. If I put those same three commands into a script Foo.py without print

Suppress warnings on import?

你离开我真会死。 提交于 2019-12-25 04:15:34
问题 Assuming I write a python package that has to use the imp module, and my package is "TestModule" which is the following: import imp import pip import sys def update_and_reload(module, *args, **kwargs): pip.main(['install', module, '--upgrade', '--user']) return imp.reload(module) When I do import TestModule in the terminal, I get a pending deprecation warning on imp . How would I make imp 's warning not occur / filter out? 回答1: Well you could use the warning module: import warnings with

os x 10.6.8 - Cannot input non-ASCII/UTF-8 chars (e.g: å, ä, ö) in Python Interactive Mode

回眸只為那壹抹淺笑 提交于 2019-12-25 03:39:20
问题 Running OS X 10.6.8 Snow Leopard I cannot input the scandinavian letters into the interpretive mode. The terminal bell sounds for every keystroke and nothing shows up. All letters show up as normal in the regular terminal environment. Inputting UTF8 characters works fine in the Terminal, when running a python script, in PyDev and in the REPL Is there a problem with the interactive mode settings and these special characters? I have installed and am running python 2.7.3 mainly, but the OS

Disable automatic printing in Python interactive session

筅森魡賤 提交于 2019-12-24 09:57:14
问题 I am going to be holding a Python workshop to teach some beginner level programmers at my college Python. I am looking for a way to modify the default behavior of Python interactive sessions so that expressions do not automatically print out results. For example, take this following interactive session: wil@calcifer:~$ python Python 2.7.3 (default, Aug 1 2012, 05:16:07) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> x = 5 >>> y = 7 >>> x + y

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

…衆ロ難τιáo~ 提交于 2019-12-22 03:54:09
问题 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 >

Interactive Slider Bar Chart Color Control

孤者浪人 提交于 2019-12-20 06:08:54
问题 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

Interactively Re-color Bars in Matplotlib Bar Chart using Confidence Intervals

萝らか妹 提交于 2019-12-14 03:29:06
问题 Trying to shade the bars in this chart based on the confidence that a selected y-value (represented by the red line) lies within a confidence interval. See recolorBars() method in the class example below. While I understand colormaps, Normalize() , and ScalarMappable() , I'm stumped on which values to pass to Normalize() to create a color and shade for each bar. Here's what my chart looks like when first generated. To generate the chart pictured above, call chart = interactiveChart() . The

How to run python interpreter in windows powershell ISE?

隐身守侯 提交于 2019-12-13 19:26:58
问题 According Microsoft, we can't run interactive console like python in it's own powershell ISE console. According to some sources it runs in the background. Can we run the same python interpreter in foreground ? 回答1: When people say it "runs in the background" they mean that when you try to run Python in ISE, it opens a legacy console app which ISE illogically hides (even though it can't bridge your actions to that app). If you run a script which runs and terminates , that's fine, you can do

Initialize interpreter with variables

房东的猫 提交于 2019-12-11 03:48:58
问题 How do I initialize the python interpreter such that it already has variables in its memory? For example, how could I initialize a[n i]Python interpreter, and type as my first input: In [1]: today Out[1]: '2015-05-05 17:49:32.726496' without first binding the name str(today = datetime.datetime.today()) ? 回答1: If you are using ipython, you can configure it to load scripts automatically for you. Run $ ipython profile create which will create default profile in your home directory. Create a file

Interactively add and remove scatter points in matplotlib

馋奶兔 提交于 2019-12-10 11:08:22
问题 Here is the problem I would like to solve: I would like to be able to interactively (i) remove scatter points (grey dots), (ii) add new scatter points, by clicking on the plot. import matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots(figsize=(16,4)) a = np.sin(range(100))*np.random.normal(20,10,100) b = [ 5, 15, 25, 30, 40, 50, 75, 85] aa = plt.plot(range(len(a)),a,color='red') bb = plt.scatter(b,a[b],color='grey',s=50) 回答1: This may not be elegant, but it works. Left-click