Re: What happens when you 'break' a generator?
On 29.07.2014 09:18, Frank Millman wrote: there's not print 'done' statement at the and. Here I break the loop - x = test() for j in x: print(j) if j == 2: break Now the output is - start 0 1 2 'done' does not appear, so the generator does not actually terminate. What happens to it? My guess is that normal scoping rules apply. Using my example, the generator is referenced by 'x', so when 'x' goes out of scope, the generator is garbage collected, even though it never completed. Is this correct? Frank Millman -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: The possibility integration in Python without an equation, just an array-like file
If you do not have a closed form for T(E) you cannot calculate the exact value of I(V). Anyway. Assuming T is integrable you can approximate I(V). 1. Way to do: interpolate T(E) by a polynomial P and integrate P. For this you need the equation (coefficients and exponents) of P. Integrating is easy after that. 2. other way: Use Stair-functions: you can approximate the Value of IV() by the sum over T(E_i) * (E_{i+1} - E_i) s.t. E_0 = E_F-\frac{eV}{2} and E_n = E_F+\frac{eV}{2}. 3 one more way: use a computer algebra system like sage. bg, Johannes On 16.05.2014 10:49, Enlong Liu wrote: Dear All, I have a question about the integration with Python. The equation is as below: and I want to get values of I with respect of V. E_F is known. But for T(E), I don't have explicit equation, but a .dat file containing two columns, the first is E, and the second is T(E). It is also in the attachment for reference. So is it possible to do integration in Python? Thanks a lot for your help! Best regards, -- Faculty of Engineering@K.U. Leuven BIOTECH@TU Dresden Email:liuenlon...@gmail.com mailto:liuenlon...@gmail.com; enlong@student.kuleuven.be mailto:enlong@student.kuleuven.be; enlong@biotech.tu-dresden.de mailto:enlong@biotech.tu-dresden.de Mobile Phone: +4917666191322 Mailing Address: Zi. 0108R, Budapester Straße 24, 01069, Dresden, Germany -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: The “does Python have variables?” debate
On 08.05.2014 02:35, Ben Finney wrote: Marko Rauhamaa ma...@pacujo.net writes: [..] Python, on the other hand, has this behaviour:: foo = [1, 2, 3] bar = foo # ‘bar’ binds to the value ‘[1, 2, 3]’ assert foo == bar # succeeds foo[1] = spam# ‘foo’ *and* ‘bar’ now == [1, spam, 3] [..] IMHO this is the behavior of having a variable pointing to it's value; foo to the list and bar to foo. consider the following: def f(l): ... l[1] = 'foo' ... l1 = [1,2,3] f(l1) l1 [1, 'foo', 3] this means, l1 consists of pointers to its values. Otherwise, it's not calling by reference, because g(l1) l1 [1, 'foo', 3] does not change l1. Once again, if I pass an object it behaves like calling by reference: class A: ... a = 0 ... a = A() a.a 0 def h(a1): ... a1.a = 1 ... h(a) a.a 1 bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: why i have the output of [None, None, None]
because thats the return value of [...] print retuns None. On 10.04.2014 15:54, length power wrote: x=['','x1','x2','x3',' '] x ['', 'x1', 'x2', 'x3', ' '] [print(ok) for it in x if it.strip() !=] ok ok ok [None, None, None] i understand there are three 'ok' in the output,but why i have the output of [None, None, None] -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: The sum of numbers in a line from a file
s = 4 e = 7 with f = file('path_to_file) as fp: for line in f: if line.startswith(name): avg = sum(map(int, filter(ambda x : len(x) 0, s.split(' '))[s : e])) / (e - s) On 20.02.2014 17:22, kxjakkk wrote: Let's say I have a sample file like this: Name1 2 34 5 6 78 name1099-66-7871 A-FY10067815998 name2999-88-7766 A-FN99 100969190 name3000-00-0110AUD5100281976 name4398-72-P/FY7684496978 name5909-37-3689A-FY97941006179 For name1, I want to add together columns 4, 5, 6, and get an average from that, then do the same for the last two columns. I want to do this for every name. All I've got is sum([int(s.strip()) for s in open('file').readlines()]) -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: SSH/Telnet program to Router/switch
On 19.02.2014 09:14, Sujith S wrote: Hi, I am new to programming and python. I am looking for a python script to do ssh/telnet to a network equipment ? I know tcl/perl does this using expect/send. Do we have expect available in python as well or need to use some other method ? Regards Sujith I'm using paramiko to access some routers and firewalls from python and it works very well. bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
thnx guys. On 24.01.2014 01:10, Terry Reedy wrote: Johannes Schneider johannes.schnei...@galileo-press.de Wrote in message: On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. I'm not sure, if this is the whole truth. think about this example: cat bla.py a = 10 cat foo.py from bla import a This makes a a global in foo, bound to 10 def stuff(): return a This a refers to the global a in foo. cat bar.py from foo import stuff print stuff() a = 5 This bar.a is irrelevant to the behavior of stuff. print stuff() from bla import * print a python bar.py 10 foo.a == 10 10 foo.a == 10 10 bla.a == 10 here the a is coming from bla Twice and is known in the global namespace. There is no global namespace outside of modules. the value differs in stuff() No it does not. and before/after the import statement. foo.a does not change. bar.a is never used. So the instance of the module differs Nope. Each of the three module instances is constant. The bindings within each could change, but there are no rebinding in the code above. -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: SIngleton from __defaults__
On 22.01.2014 20:18, Ned Batchelder wrote: On 1/22/14 11:37 AM, Asaf Las wrote: Chris is right here, too: modules are themselves singletons, no matter how many times you import them, they are only executed once, and the same module object is provided for each import. I'm not sure, if this is the whole truth. think about this example: cat bla.py a = 10 cat foo.py from bla import a def stuff(): return a cat bar.py from foo import stuff print stuff() a = 5 print stuff() from bla import * print a python bar.py 10 10 10 here the a is coming from bla and is known in the global namespace. But the value differs in stuff() and before/after the import statement. So the instance of the module differs - it cannot be a singelton. bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Imports in Python
Hi List, I remember some document explaining the python imports in detail somewhere, but I don't have any idea where it was. Even no idea if it was in the List or some blogbost. Does anybody of you have some suggestions where I can find those informations besides the official documentation? bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: matlabFunction Equivalent?
On 20.01.2014 23:09, rpi.bal...@gmail.com wrote: Hey all, I'm new at Python, so if you see any mistakes feel free to let me know. I'm trying to take a symbolic expression and turn it into a variable equation or function. I think that just an expression of variables would be preferable. I have a range equation which I form using symbols and then take various derivatives of it. I then want to have these derivatives on hand to use for various functions, but short of using sub every time or just copy pasting from the console output (I don't want to do that), I can't find an efficient way to do this. Matlab had matlabFunction which was really handy, but I don't think Python has an equivalent. import numpy as np import scipy as sp import sympy as sy import math as ma x, y, z, x_s, y_s, z_s, theta, theta_dot, x_dot, y_dot, z_dot = sy.symbols('x y z x_s y_s z_s theta theta_dot x_dot y_dot z_dot') rho = (x**2 + y**2 + z**2 + x_s**2 + y_s**2 + z_s**2 - 2*(x*x_s + y*y_s)*sy.cos(theta) + 2*(x*y_s - y*x_s)*sy.sin(theta) - 2*z*z_s)**(0.5) rho_dot = (x*x_dot + y*y_dot + z*z_dot - (x_dot*x_s + y_dot*y_s)*sy.cos(theta) + theta_dot*(x*x_s + y*y_s)*sy.sin(theta) + (x_dot*y_s - y_dot*x_s)*sy.sin(theta) + theta_dot*(x*y_s - y*x_s)*sy.cos(theta) - z_dot*z_s)/rho drho_dx = sy.diff(rho, x) drho_dy = sy.diff(rho, y) drho_dz = sy.diff(rho, z) #I then want drho_dx, etc to be variable expressions with x, y, z, etc as variables instead of symbols or numbers. I could do: x, y, z = 1200, 1300, 1400 #m drho_dx = subs([x, x], [y, y], [z, z]) #but this seems inefficient to do multiple times. Thoughts? If you don not mind installing other programs, maybe you can have a look at sage (www.sagemath.org). That's a ComputerAlgebraSystem using python as its base and supporting most (all?) of the python syntax and moduls bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: Brython (Python in the browser)
On 27.12.2013 07:14, Pierre Quentel wrote: Hi, Ever wanted to use Python instead of Javascript for web client programming ? Take a look at Brython, an implementation of Python 3 in the browser, with an interface with DOM elements and events Its use is very simple : - load the Javascript library brython.js : script src=/path/to/brython.js - embed Python code inside a tag script type=text/python - run the Python script on page load : body onload=brython() The Python code is translated into Javascript and executed on the fly Brython supports the DOM API, HTML5, SVG, with some syntaxic sugar to make the interface more concise (a la jQuery) ; interaction with Javascript libraries is very straightforward. The Brython site provides documentation and many examples After 1 year of intense development, Brython now covers most of the Python3 syntax and can run most of the modules of the Python3.3 standard distribution unmodified, including complex packages like unittest. The team aims at covering 100% of all of Python that makes sense in a browser environment Home page : http://www.brython.info Development site : https://bitbucket.org/olemis/brython/src Downloads : https://bitbucket.org/olemis/brython/downloads Community : https://groups.google.com/forum/?fromgroups=#!forum/brython that's amazing. is there any python construct which is not usable with brython? OR, the oder way around, anything possible in JS, which does not work in brython? bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Differences between obj.attribute and getattr(obj, attribute)
Hi list, can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? bg, Johannes -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list
Re: Differences between obj.attribute and getattr(obj, attribute)
thank you guys. On 11.12.2013 10:36, Chris Angelico wrote: 2013/12/11 Johannes Schneider johannes.schnei...@galileo-press.de: can somebody explain me the difference between accessing attributes via obj.attribute and getattr(obj, attribute)? Is there a special reason or advantage when using getattr? You use getattr when the attribute name comes from a string, rather than a literal. There's no advantage to it when you know ahead of time what attribute you're looking for. It's useful when you iterate over dir(), for instance: print(You can call...) n=0 for attr in dir(x): if callable(getattr(x,attr)): print(x.%s()%attr) n+=1 print(...,n, options.) ChrisA -- Johannes Schneider Webentwicklung johannes.schnei...@galileo-press.de Tel.: +49.228.42150.xxx Galileo Press GmbH Rheinwerkallee 4 - 53227 Bonn - Germany Tel.: +49.228.42.150.0 (Zentrale) .77 (Fax) http://www.galileo-press.de/ Geschäftsführer: Tomas Wehren, Ralf Kaulisch, Rainer Kaltenecker HRB 8363 Amtsgericht Bonn -- https://mail.python.org/mailman/listinfo/python-list