[Tutor] [Python 2.7] HELP: Serving HTTP on 0.0.0.0 port 80 not proceeding
Not completely sure why it doesn't open the chart on the web browser when i type this in the windows command prompt (cmd) python -m SimpleHTTPServer port 80.So first i type python ml.py data/sample.csv in cmd windows and then python -m SimpleHTTPServer port 80, but it's not proceeding to the graph in html?? See attached image for screenshoot and complete .py file ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] [Python 2.7] HELP: Serving HTTP on 0.0.0.0 port 80 not proceeding
Please don't repeat post. We saw it the first time. Please do post again with the extra information requested. On 18/02/17 04:46, Allan Tanaka via Tutor wrote: > Not completely sure why it doesn't open the chart on the web browser when i > type this in the windows command prompt (cmd) python -m SimpleHTTPServer port > 80.So first i type python ml.py data/sample.csv in cmd windows and then > python -m SimpleHTTPServer port 80, but it's not proceeding to the graph in > html?? > See attached image for screenshoot and complete .py file One extra piece of information is how do you try to access the chart? What url are you typing into ytour browser? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Select and deselect for multiple checkboxes in Tkinter
Hi Alan, Thank you for your input. That was an easy fix to it. Thanks a lot. Pooja On Fri, Feb 17, 2017 at 8:23 PM, Alan Gauld via Tutor wrote: > On 17/02/17 18:31, Pooja Bhalode wrote: > > > I am writing to create two buttons, for selecting and de-selecting > multiple > > checkboxes that I have created previously. These checkboxes have > different > > variables that they are associated with for their values and thus cannot > > create a loop for the same. > > You can still use a loop by putting the variables in > a list/tuple: > > checkboxVars = [keqparam,delHrxnparam,kfparam,Afparam,RCparam] > > for var in checkboxVars: > var = 0 #or whatever. > > You can even use different reset values if necessary > by putting them in tuples: > > checkboxVars = [(keqparam,0),(delHrxnparam,1), > (kfparam,2),(Afparam, > ...(RCparam,42)] > > for var,val in checkboxVars: > var = val #or whatever. > > HTH > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] SciPy Optimize-like calling function as string
I'm trying to use the scipy.optimize code as an example to be able to avoid using *eval* to call a function named by a string. The following appears to be the code used to do this: # from scipy optimize > def wrap_function(function, args): > ncalls = [0] > if function is None: > return ncalls, None > > def function_wrapper(*wrapper_args): > ncalls[0] += 1 > print(type(function)) > return function(*(wrapper_args + args)) > > return ncalls, function_wrapper where I should be able to use it to make the following work: > def sqr(x): > return x**2. > > > func = 'sqr' > > args=() > fcalls, func = wrap_function(func, args) > > x=3 > func(x) where I get: > > > --- > TypeError > Traceback (most recent call last) > > in () > 7 > 8 x=3 > > 9 func(x) > > > > in function_wrapper(*wrapper_args) > 8 ncalls[0] += 1 > 9 print(type(function)) > ---> 10 return function(*(wrapper_args + args)) > 11 > 12 return ncalls, function_wrapper > > > > TypeError: 'str' object is not callable This works in *optimize* but not for me. What am I missing? I've seen this done with dictionaries on some pages, but it seems that this is intended to be faster (which will become necessary for me in the future). Thanks, Joe ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Using numpy stack functions
Hi, I'm new to python programming so this question will probably be a no brainer for the experienced programmer. I'm trying to create a 10x10 array of zeros and then framing it with a border of ones. Output should look like this: [[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] [ 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. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]? As you can see I have too many zeros once I stack them and don't have the ones framing the sides vertically. Any guidance on where I'm going astray? Much appreciated, A.B. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Problems with matplotlib
Hi, I am trying to create a simple normal plot. But I am getting some errors which I am not able to understand. Would be a great help if someone can guide me to what I am doing wrong. Thankyou so much. Here is the code: # import matplotlib.pyplot as plt from matplotlib import pyplot as plt (Here, I have tried both these import statements, but both give me the same error.) x = [1,2,4,5,6,8,9,10] y = [6,7,8,9,10,11,12,14] plt.figure() plt.plot(x,y) plt.show() Error: /Users/poojabhalode/.bash_profile: line 1: .bashrc: No such file or directory Traceback (most recent call last): File "/Users/poojabhalode/Google Drive/GUI Python/matplot.py", line 3, in from matplotlib import pyplot as plt File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py", line 123, in import pyparsing File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pyparsing.py", line 3260, in _reBracketExpr = Literal("[") + Optional("^").setResultsName("negate") + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + "]" File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pyparsing.py", line 775, in setResultsName newself = self.copy() File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pyparsing.py", line 749, in copy cpy = copy.copy( self ) AttributeError: 'module' object has no attribute 'copy' [Finished in 2.4s with exit code 1] [shell_cmd: python -u "/Users/poojabhalode/Google Drive/GUI Python/matplot.py"] [dir: /Users/poojabhalode/Google Drive/GUI Python] [path: /usr/bin:/bin:/usr/sbin:/sbin] I am running this on the inbuilt python in Mac10.12 When I try running the same in terminal it works, but here it is not able to compile. Please let me know. Thankyou. Pooja ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SciPy Optimize-like calling function as string
On 18/02/17 21:52, Joseph Slater wrote: > I'm trying to use the scipy.optimize code ... > I've seen this done with dictionaries on some pages, > but it seems that this is intended to be faster There is a saying in programming that premature optimization is the root of all evil. If you don't know that you need to optimize then your time is usually better spent elsewhere. Dictionaries are pretty fast in Python and I'd suggest you try that first before shaving milliseconds in places that may not be where you need to make savings. Identify an actual problem, then identify the cause and optimise that. Don't try to second guess the future. Most performance problems are down to bad algorithms or bad data structures not bad dispatch techniques. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Using numpy stack functions
Bruhnke, Angelica wrote: > I'm new to python programming so this question will probably be a no > brainer for the experienced programmer. I'm trying to create a 10x10 array > of zeros and then framing it with a border of ones. So the final array is 12x12. > > Output should look like this: > > [[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 1.] > > [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]] > > > > This is the code I've written: > > a = np.ones ((1,10)) > > print a > > b = np.zeros ((10,10)) > > print b > > c = np.vstack ((b,a)) > > print c > > > This is my output: > > [[ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]] > [[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]] > [[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] > [ 1. 1. 1. 1. 1. 1. 1. 1. 1. 1.]]? > > As you can see I have too many zeros once I stack them and don't have the > ones framing the sides vertically. > > Any guidance on where I'm going astray? Below I'm using the dimensions 4x4. To get 1 1 1 1 1 0 0 1 1 0 0 1 1 1 1 1 you can vstack() >>> np.vstack(([1,1], [[0,0],[0,0]], [1,1])) array([[1, 1], [0, 0], [0, 0], [1, 1]]) and use hstack() to add ones to the sides: >>> side = [[1]]*4 >>> np.hstack((side, mid, side)) array([[1, 1, 1, 1], [1, 0, 0, 1], [1, 0, 0, 1], [1, 1, 1, 1]]) The same with ones() and zeros(), put into a function: >>> def frame(N): ... horz = np.ones((1, N)) ... inner = np.zeros((N, N)) ... vert = np.ones((N+2, 1)) ... mid = np.vstack((horz, inner, horz)) ... return np.hstack((vert, mid, vert)) ... >>> frame(3) array([[ 1., 1., 1., 1., 1.], [ 1., 0., 0., 0., 1.], [ 1., 0., 0., 0., 1.], [ 1., 0., 0., 0., 1.], [ 1., 1., 1., 1., 1.]]) >>> frame(1) array([[ 1., 1., 1.], [ 1., 0., 1.], [ 1., 1., 1.]]) Personally I'd probably use a simpler approach. Start with all ones and then set the inner values to 0: >>> def frame2(N): ... a = np.ones((N+2, N+2)) ... a[1: -1, 1: -1] = 0 ... return a ... >>> frame2(2) array([[ 1., 1., 1., 1.], [ 1., 0., 0., 1.], [ 1., 0., 0., 1.], [ 1., 1., 1., 1.]]) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problems with matplotlib
Pooja Bhalode wrote: > Hi, > > I am trying to create a simple normal plot. But I am getting some > errors which I am not able to understand. Would be a great help if someone > can guide me to what I am doing wrong. > > Thankyou so much. > Here is the code: > > # import matplotlib.pyplot as plt > from matplotlib import pyplot as plt > (Here, I have tried both these import statements, but both give me the > same error.) > > x = [1,2,4,5,6,8,9,10] > y = [6,7,8,9,10,11,12,14] > plt.figure() > plt.plot(x,y) > plt.show() > > Error: > > /Users/poojabhalode/.bash_profile: line 1: .bashrc: No such file or > directory > Traceback (most recent call last): > File "/Users/poojabhalode/Google Drive/GUI Python/matplot.py", line 3, > in > > from matplotlib import pyplot as plt > File > "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/__init__.py", > line 123, in > import pyparsing > File > "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pyparsing.py", > line 3260, in > _reBracketExpr = Literal("[") + Optional("^").setResultsName("negate") > + Group( OneOrMore( _charRange | _singleChar ) ).setResultsName("body") + > "]" > File > "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pyparsing.py", > line 775, in setResultsName > newself = self.copy() > File > "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pyparsing.py", > line 749, in copy > cpy = copy.copy( self ) > AttributeError: 'module' object has no attribute 'copy' > [Finished in 2.4s with exit code 1] > [shell_cmd: python -u "/Users/poojabhalode/Google Drive/GUI > Python/matplot.py"] > [dir: /Users/poojabhalode/Google Drive/GUI Python] > [path: /usr/bin:/bin:/usr/sbin:/sbin] > > I am running this on the inbuilt python in Mac10.12 > When I try running the same in terminal it works, but here it is not able > to compile. > Please let me know. You have a file copy.py, probably written by yourself, that shades the copy module in Python's standard library. To locate this module (if it is not in the current working directory) add the lines import copy print copy.__file__ If I'm guessing right everything should work after you have removed the pyc- file and renamed the corresponding copy.py. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] SciPy Optimize-like calling function as string
Joseph Slater wrote: > I'm trying to use the scipy.optimize code as an example to be able to > avoid using *eval* to call a function named by a string. > > The following appears to be the code used to do this: No, wrap_function wraps an existing function, adds some extra args, and provides a way to keep track of the number of invocations. For example: >>> def wrap_function(function, args): ... ncalls = [0] ... if function is None: ... return ncalls, None ... def function_wrapper(*wrapper_args): ... ncalls[0] += 1 ... print(type(function)) ... return function(*(wrapper_args + args)) ... return ncalls, function_wrapper ... >>> def demo(*args): ... print("demo() called with", args) ... >>> f = wrap_function(demo, ("one", "two")) >>> calls, func = wrap_function(demo, ("one", "two")) >>> calls [0] >>> func("x", "y") demo() called with ('x', 'y', 'one', 'two') >>> calls [1] >>> func() demo() called with ('one', 'two') >>> calls [2] To get a function in the current module from its name use globals(): >>> def square(x): ... return x*x ... >>> def twice(x): ... return 2*x ... >>> f = globals()["square"] >>> f(3) 9 >>> f = globals()["twice"] >>> f(3) 6 For a function in an external module try getattr(): >>> import os.path >>> f = getattr(os.path, "join") >>> f("foo", "bar") 'foo/bar' ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor