Re: Could you explain this rebinding (or some other action) on "nums = nums"?

2015-11-30 Thread fl
On Wednesday, June 24, 2015 at 8:17:08 PM UTC-4, Chris Angelico wrote: > On Thu, Jun 25, 2015 at 9:52 AM, fl wrote: > > The reason is that list implements __iadd__ like this (except in C, not > > Python): > > > > class List: > > def __iadd__(self, othe

Re: Question about code writing '% i, callback'

2015-11-30 Thread fl
On Monday, November 30, 2015 at 12:02:57 PM UTC-5, Ian wrote: > On Mon, Nov 30, 2015 at 10:44 AM, fl wrote: > > I come across the following code snippet. > > > > for i in range(10): > > def callback(): > > print "clicked button", i

Re: Question about code writing '% i, callback'

2015-11-30 Thread fl
On Monday, November 30, 2015 at 12:37:52 PM UTC-5, Terry Reedy wrote: > On 11/30/2015 11:44 AM, fl wrote: > > > I come across the following code snippet. > > > for i in range(10): > > def callback(): > > print "clicked button", i &

Re: Question about code writing '% i, callback'

2015-11-30 Thread fl
On Monday, November 30, 2015 at 11:44:44 AM UTC-5, fl wrote: > Hi, > > I come across the following code snippet. > > > > > > for i in range(10): > def callback(): > print "clicked button", i > UI.Button("button %s" % i

Question about code writing '% i, callback'

2015-11-30 Thread fl
Hi, I come across the following code snippet. for i in range(10): def callback(): print "clicked button", i UI.Button("button %s" % i, callback) The content inside parenthesis in last line is strange to me. "button %s" % i, callback That is, the writing looks like reco

variable vs. object

2015-11-29 Thread fl
Hi, I read several parts on line about Python that everything in Python is an object. Yes, it is a key difference with other languages. Then, I read a page it says variables: global and local variable at: http://www.tutorialspoint.com/python/python_functions.htm I have a question that whether

What use is this class?

2015-11-29 Thread fl
Hi, When I search around tutorial about None, I came across this link: http://jaredgrubb.blogspot.ca/2009/04/python-is-none-vs-none.html I don't understand what use of this class example: >>> class Zero(): # a class that is zero ...def __nonzero__(self): ... return False I can onl

Question about output different with command dis.dis(code)

2015-11-26 Thread fl
Hi, I see the following from a previous post: Python 1.5.2 (#1, Aug 27 2012, 09:09:18) [GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import dis >>> code = compile("(1, 2, 3)", "", "eval") >>> dis.dis(code) 0 S

Is there an meaning of '[[]]' in a list?

2015-11-19 Thread fl
Hi, In the previous exercises, I see list: cc=[[],[],[]] Then, I can have this: ccc=[[[]],[[]],[[]]] I can also have ccc[0] Out[158]: [[]] ccc[0]='o' ccc Out[163]: ['o', [[]], [[]]] I have question: Is there any difference between [[]] and []? [[]] can have deeper assignment and use than

Re: Question about 'print' in a loop

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 10:11:24 PM UTC-5, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 1:55 PM, fl wrote: > > There are only one time 5 'here' printed out, but there is no 'here' print > > out in thereafter call sq[2]() etc. How to understand t

Question about 'print' in a loop

2015-11-18 Thread fl
Hi, >From previous post, I get many helpful replies. Now I have a new question when I run this example code: - sq=[] for xx in range(5): print 'here' sq.append(lambda:xx**2) here here here here here xx Out[150]: 4 sq[2]() Out[151]: 16 sq[3]() Out[152]: 16 / There are

Re: What is a function parameter =[] for?

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 7:15:05 PM UTC-5, Chris Angelico wrote: > On Thu, Nov 19, 2015 at 11:02 AM, Ian Kelly wrote: > > On Wed, Nov 18, 2015 at 4:22 PM, Chris Angelico wrote: > >> On Thu, Nov 19, 2015 at 10:14 AM, BartC wrote: > >>> So, looking at some source code, a default value fo

Could you explain why the following generates 4 same elements list?

2015-11-18 Thread fl
Hi, I cannot reason out why the code: def mpl(): return [lambda x : i * x for i in range(4)] print [m(2) for m in mpl()] / has result: [6, 6, 6, 6] I have tried to simplify the above code to an easy understanding form, but fails. Either the modified code does not work

Re: What is a function parameter =[] for?

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 5:38:45 PM UTC-5, fl wrote: > On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote: > > On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: > > > Hi, > > > > > > I have tried the below function and find that it can remember

Re: What is a function parameter =[] for?

2015-11-18 Thread fl
On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote: > On Wed, Nov 18, 2015 at 2:08 PM, fl wrote: > > Hi, > > > > I have tried the below function and find that it can remember the previous > > setting value to 'val'. I think the second parameter ha

What is a function parameter =[] for?

2015-11-18 Thread fl
Hi, I have tried the below function and find that it can remember the previous setting value to 'val'. I think the second parameter has something on this effect, but I don't know the name and function of '=[]' in this application. Could you explain a little to me? Thanks, def eList(val, list0=

Re: Is there any reason to introduce this intermediate variable (sz)?

2015-11-17 Thread fl
On Tuesday, November 17, 2015 at 4:03:05 PM UTC-5, John Gordon wrote: > In fl <@gmail.com> > writes: > > > correctly. Could you see something useful with variable 'sz'? > > 'sz' is fewer characters than '(n_iter,)', which may make

Is there any reason to introduce this intermediate variable (sz)?

2015-11-17 Thread fl
Hi, I find the following code snippet, which is useful in my project: n_iter = 50 sz = (n_iter,) # size of array x = -0.37727 z = np.random.normal(x,0.1,size=sz) Q = 1e-5 # process variance # allocate space for arrays xhat=np.zeros(sz) P=np.zeros(sz) I learn Python now and t

Help on savefig parameters

2015-11-17 Thread fl
Hi, I find the parameters of savefig function has the similar format of that of main(*argc, **argv) in C. I have tried with savefig("temp.pdf", format='pdf'), and it works. I get the help content of savefig() as below. But I cannot understand why they also give: savefig(fname, dpi=None, facecolor

What meaning is 'a[0:10:2]'?

2015-11-15 Thread fl
hi, When I learn slice, I have a new question on the help file. If I set: pp=a[0:10:2] pp is array([1, 3]) I don't know how a[0:10:2] gives array([1, 3]). I know matlab a lot, but here it seems quite different. Could you tell me what meaning a[0:10:2] is? Thanks, class slice(object) | s

Question about yield

2015-11-14 Thread fl
Hi, I have read a couple of tutorial on yield. The following code snippet still gives me a shock. I am told yield is a little like return. I only see one yield in the tutorial examples. Here it has two yields. And there are three variables following keyword yield. I have not tried debug function t

What function is 'u0, j = random(), 0'?

2015-11-14 Thread fl
Hi, When I read the below code, I cannot make the last line (with ##) out. def res(weights): n = len(weights) indices = [] C = [0.] + [sum(weights[:i+1]) for i in range(n)] u0, j = random(), 0 ## If I run below code on console, it will say an error. uu, 0.1, 0 What differe

Re: What meaning is of '#!python'?

2015-11-14 Thread fl
On Saturday, November 14, 2015 at 8:58:57 PM UTC-5, Chris Angelico wrote: > On Sun, Nov 15, 2015 at 12:54 PM, fl wrote: > > I see an example Python code has such a line at the file beginning: > > > > #!python > > > > > > Is there some meaning about it? &g

What meaning is of '#!python'?

2015-11-14 Thread fl
Hi, I see an example Python code has such a line at the file beginning: #!python Is there some meaning about it? Thanks, -- https://mail.python.org/mailman/listinfo/python-list

What is the right way to import a package?

2015-11-14 Thread fl
Hi, I want to use a code snippet found on-line. It has such content: from numpy import * dt = 0.1 # Initialization of state matrices X = array([[0.0], [0.0], [0.1], [0.1]]) # Measurement matrices Y = array([[X[0,0] + abs(randn(1)[0])], [X[1,0] + abs(randn(1)[0])]]) When the above content is i

Re: What is wrong this wrapper (decorator)?

2015-11-14 Thread fl
On Saturday, November 14, 2015 at 12:23:50 PM UTC-5, fl wrote: > Hi, > > I follow a tutorial to learn decorator: > > http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ > > I use Enthought Canopy to run the following code. > It is really strange t

What is wrong this wrapper (decorator)?

2015-11-14 Thread fl
Hi, I follow a tutorial to learn decorator: http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/ I use Enthought Canopy to run the following code. It is really strange that the wrapper does not take effect. In fact, I go back to the basic way (not with @): wrapper(sub(two,

Re: Where is decorator in this example code?

2015-11-14 Thread fl
On Saturday, November 14, 2015 at 7:38:09 AM UTC-5, Chris Warrick wrote: > On 14 November 2015 at 13:13, fl wrote: > > On Saturday, November 14, 2015 at 7:11:11 AM UTC-5, fl wrote: > >> Hi, > >> > >> I am learning decorator following this link: > >>

Re: Where is decorator in this example code?

2015-11-14 Thread fl
On Saturday, November 14, 2015 at 7:11:11 AM UTC-5, fl wrote: > Hi, > > I am learning decorator following this link: > > http://thecodeship.com/patterns/guide-to-python-function-decorators/ > > When I read decorator on class, I don't see decorator taking in effec

Where is decorator in this example code?

2015-11-14 Thread fl
Hi, I am learning decorator following this link: http://thecodeship.com/patterns/guide-to-python-function-decorators/ When I read decorator on class, I don't see decorator taking in effect. In the following code snippet, there is the same print out if I comment out two lines 'def p_decorate(func

What is '@' for

2015-11-13 Thread fl
Hi, I read the following code snippet. A question is here about '@'. I don't find the answer online yet. What function is it here? BTW, below is for printing out? """theta = logit^{-1}(a+b)""" but I don't see it is printed when the following could have been called. Are you sure it would be

Can Canopy Express (Free) allow install a new package (PyBayes) to it?

2015-11-13 Thread fl
I am using Canopy Express (Free) version. I want to install PyBayes package, but I don't see it in Package Manager of Canopy. Can I install PyBayes to Canopy? Now, Canopy is the default Python on my Windows 7 PC. If Canopy does not allow to install PyBayes into it, can I install PyBayes to the

Is it useful for re.M in this example?

2015-11-12 Thread fl
Hi, I follow a web site on learning Python re. I have read the function description of re.m, as below. re.MMakes $ match the end of a line (not just the end of the string) and makes ^ match the start of any line (not just the start of the string). But I don't see the reason to put re.M in

Why does 'as' not recognized?

2015-11-12 Thread fl
Hi, When I try the following, python does not know 'as'. Why doesn't it? Thanks, >>> cats = ['Tom', 'Snappy', 'Kitty', 'Jessie', 'Chester'] >>> >>> type(cats) >>> cats[2] 'Kitty' >>> as=cats[2] SyntaxError: invalid syntax >>> as=cats SyntaxError: invalid syntax >>> as SyntaxError: invalid syn

Re: What is wrong in this example code?

2015-11-12 Thread fl
On Thursday, November 12, 2015 at 8:58:33 AM UTC-5, fl wrote: > Hi, > > I run a code snippet from link: > http://www.python-course.eu/inheritance_example.php > > It is found that there is an error in this loop: > > for i in xrange(1): > x.tick() > print(x)

What is wrong in this example code?

2015-11-12 Thread fl
Hi, I run a code snippet from link: http://www.python-course.eu/inheritance_example.php It is found that there is an error in this loop: for i in xrange(1): x.tick() print(x) SyntaxError: invalid syntax I have modified it to: for i in x range(1): x.tick() print(x) SyntaxError:

How to get 'od' run?

2015-11-11 Thread fl
Hi, I am learning python. I see a previous post has such code: >>> data = '"binääridataa"\n'.encode('utf-8') >>> f = open('roska.txt', 'wb') >>> f.write(data) 17 >>> f.close() The .encode methods produced a bytestring, which Python likes to display as ASCII characters wh

Re: Can anybody explain the '-' in a 2-D creation code?

2015-06-25 Thread fl
On Thursday, June 25, 2015 at 6:24:07 PM UTC-7, Mark Lawrence wrote: > On 26/06/2015 02:07, fl wrote: > > Hi, > > > > I read Ned's tutorial on Python. It is very interesting. On its last > > example, I cannot understand the '_' in: > > > > >

Can anybody explain the '-' in a 2-D creation code?

2015-06-25 Thread fl
Hi, I read Ned's tutorial on Python. It is very interesting. On its last example, I cannot understand the '_' in: board=[[0]*8 for _ in range(8)] I know '_' is the precious answer, but it is still unclear what it is in the above line. Can you explain it to me? Thanks, -- https://mail.pyth

Could you give me the detail process of 'make_incrementor(22)(33)'?

2015-06-25 Thread fl
Hi, I read a tutorial on lambda on line. I don't think that I am clear about the last line in its example code. It gives two parameters (22, 23). Is 22 for n, and 23 for x? Or, it creates two functions first. Then, each function gets 22 while the other function gets 23? Please help me on this i

Could you explain "[1, 2, 3].remove(2)" to me?

2015-06-25 Thread fl
Hi, I see a code snippet online: [1, 2, 3].remove(42) after I modify it to: [1, 2, 3].remove(2) and aa=[1, 2, 3].remove(2) I don't know where the result goes. Could you help me on the question? Thanks, -- https://mail.python.org/mailman/listinfo/python-list

Re: Could you explain why this program runs?

2015-06-25 Thread fl
On Thursday, June 25, 2015 at 8:20:52 AM UTC-7, fl wrote: > Hi, > > I download and install pyPDF2 library online. It says the test can run by: > > > python -m unittest Tests.tests > > > tests.py is under folder PyPDF2-master\Tests\ > > > The above c

Could you explain why this program runs?

2015-06-25 Thread fl
Hi, I download and install pyPDF2 library online. It says the test can run by: python -m unittest Tests.tests tests.py is under folder PyPDF2-master\Tests\ The above command line does run and give output message, but I don't understand why it run after I read tests.py: ///

Could you explain this rebinding (or some other action) on "nums = nums"?

2015-06-24 Thread fl
Hi, I read a blog written by Ned and find it is very interesting, but I am still unclear it in some parts. In the following example, I am almost lost at the last line: nums = num Could anyone explain it in a more detail to me? Thanks, ... The reason is that list imple

Re: Why does the unit test fail of the pyPDF2 package?

2015-06-24 Thread fl
On Wednesday, June 24, 2015 at 9:54:12 AM UTC-7, fl wrote: > Hi, > I want to learn some coding on PDF. After I download and install pyPDF2, > it cannot pass unit test, which is coming from the package. > > I put a screen shot link here to show the console message: > > http:/

Re: Why does the unit test fail of the pyPDF2 package?

2015-06-24 Thread fl
On Wednesday, June 24, 2015 at 9:54:12 AM UTC-7, fl wrote: > Hi, > I want to learn some coding on PDF. After I download and install pyPDF2, > it cannot pass unit test, which is coming from the package. > > I put a screen shot link here to show the console message: > > http:/

Re: Why does the unit test fail of the pyPDF2 package?

2015-06-24 Thread fl
On Wednesday, June 24, 2015 at 9:54:12 AM UTC-7, fl wrote: > Hi, > I want to learn some coding on PDF. After I download and install pyPDF2, > it cannot pass unit test, which is coming from the package. > > I put a screen shot link here to show the console message: > > http:/

Why does the unit test fail of the pyPDF2 package?

2015-06-24 Thread fl
Hi, I want to learn some coding on PDF. After I download and install pyPDF2, it cannot pass unit test, which is coming from the package. I put a screen shot link here to show the console message: http://tinypic.com/view.php?pic=fbdpg0&s=8#.VYre8_lVhBc [IMG]http://i57.tinypic.com/fbdpg0.png[/IMG]

Re: Can Python function return multiple data?

2015-06-06 Thread fl
ta = func(5) --> data = (10,15,... ) > > > On Wed, Jun 3, 2015 at 1:57 AM, fl wrote: > Hi, > > > > I just see the tutorial says Python can return value in function, it does > > not say multiple data results return situation. In C, it is possi

What is the difference between list() and list?

2015-06-02 Thread fl
Hi, I find the following results are interesting, but I don't know the difference between list() and list. >>> nums=list() >>> nums [] >>> xx=list >>> xx >>> nums [] >>> print(xx) >>> print(nums) [] >>> Could you tell me that? Thanks, -- https://mail.python.org/mailman/listinfo/pytho

Can Python function return multiple data?

2015-06-02 Thread fl
Hi, I just see the tutorial says Python can return value in function, it does not say multiple data results return situation. In C, it is possible. How about Python on a multiple data return requirement? Thanks, -- https://mail.python.org/mailman/listinfo/python-list

Re: Please help on this sorted function

2015-06-02 Thread fl
On Tuesday, June 2, 2015 at 1:20:40 PM UTC-7, fl wrote: > Hi, > > I try to learn sorted(). With the tutorial example: > > > > > >>> ff=sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) > >>> ff >

Please help on this sorted function

2015-06-02 Thread fl
Hi, I try to learn sorted(). With the tutorial example: >>> ff=sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) >>> ff [1, 2, 3, 4, 5] I don't see what sorted does in this dictionary, i.e. the sequence of 1..5 is unchanged. Could you explain it to me? Thanks, -- https://mail.python.org/

Could you explain lambda function to me?

2015-06-02 Thread fl
Hi, I see the description of lambda at the online tutorial, but I cannot understand it. '42' is transferred to the function. What 'x' value should be? I do not see it says that it is '0'. And, what is 'x'? >>> def make_incrementor(n): ... return lambda x: x + n ... >>> f = make_increm

How to access the low digits of a list

2015-06-02 Thread fl
Hi, I have a list: >>> lines ['12', '42', '49', '156', '225', '36', '49', '164', '11181', '3100'] I want to access the last two digits. That is: ['12', '42', '49', '56', '25', '36', '49', '64', '81', '00'] When I try to use lines[3][0] is '1' lines[3][1] is '5' lines[3][2] is '6' I d

How to understand '_' in these tests?

2015-06-01 Thread fl
Hi, I just know that '_' is the last result in the Python interpreter. I feel that it is like 'ans' in Matlab. When I run the following commands. The result of '_' are always '4'. Because I have tried several commands, such as reversed('fred'), xx and rx, '4' are always there. What is your exp

What use of string module?

2015-06-01 Thread fl
Hi, I read the online help about string. It lists string constants, string formatting, template strings and string functions. After reading these, I am still puzzled about how to use the string module. Could you show me a few example about this module? Thanks -- https://mail.python.org/mailma

How to use an iterator?

2015-06-01 Thread fl
Hi, I read the online tutorial on iterator: https://docs.python.org/2/library/itertools.html I have no idea on how to use this one: itertools.count(start=0, step=1) BTW, I am using Python 2.7.9 on Windows 7. I even input the following: def count(start=0, step=1): # count(10) --> 10 11

Re: Where is 'palindrome' defined?

2015-06-01 Thread fl
On Sunday, May 31, 2015 at 9:46:56 PM UTC-7, fl wrote: > Hi, > > When I search solution of reverse a string/number, I came across a short > function online: > > >>> def palindrome(num): > return str(num) == str(num)[::-1] > > I thought that it is a gene

A simple print cannot run in Python Shell

2015-06-01 Thread fl
Hi, When I try the following (They are saved in a main.py file) #!/usr/bin/python print r'C:\\nowhere' It works as the tutorial, i.e. it echoes in a Windows 7 command console: C:\\nowhere When I run the following command in a Python 2.7.9 Shell on Windows 7, print r'C:\\nowhere'

Re: What use for reversed()?

2015-05-31 Thread fl
On Sunday, May 31, 2015 at 12:59:47 PM UTC-7, Denis McMahon wrote: > On Sun, 31 May 2015 12:40:19 -0700, fl wrote: > reversed returns an iterator, not a list, so it returns the reversed list > of elements one at a time. You can use list() or create a list from > reversed and then joi

Where is 'palindrome' defined?

2015-05-31 Thread fl
Hi, When I search solution of reverse a string/number, I came across a short function online: >>> def palindrome(num): return str(num) == str(num)[::-1] I thought that it is a general function. And with the following variable: >>> a '1234_' >>> parlindrome(a) Traceback (most recen

Re: What use for reversed()?

2015-05-31 Thread fl
On Sunday, May 31, 2015 at 4:23:19 PM UTC-7, Tim Delaney wrote: > On 1 June 2015 at 05:40, fl wrote: > Hi, > > The for statement must have a colon at the end of line e.g. a complete for > statement and block is: > > for br in b: >     print br > > This will outp

Re: Are there any other better ways to access a single bit of string of digits?

2015-05-31 Thread fl
On Sunday, May 31, 2015 at 12:53:19 PM UTC-7, Denis McMahon wrote: > On Sun, 31 May 2015 11:36:35 -0700, fl wrote: > > I am new to Python. I would manipulate a string of hex numbers. If the > > first digit is bigger than 7, the first two digits are required to add > > 4.

Are there any other better ways to access a single bit of string of digits?

2015-05-31 Thread fl
Hi, I am new to Python. I would manipulate a string of hex numbers. If the first digit is bigger than 7, the first two digits are required to add 4. For example, '8022_3345' will be changed to '8422_3345'. The underscore between two 4-digit's was generated previously (i.e. it is already in the .

What use for reversed()?

2015-05-31 Thread fl
Hi, I have a string b='1234'. I run: br=reversed(b) I hope that I can print out '4321' by: for br in b but it complains: SyntaxError: invalid syntax My questions: 1. What use for reversed(). I do not find an example on web. 2. If reversed() is wrong the my purpose, what method can do it? i.e

Question about 'x' in pymc.invlogit(a+b*x)

2015-03-07 Thread fl
Hi, I once learnt Python for a few weeks. Now, I try to using a Python package pymc. It has the following example code: import pymc import numpy as np n = 5*np.ones(4,dtype=int) x = np.array([-.86,-.3,-.05,.73]) alpha = pymc.Normal('alpha',mu=0,tau=.01) beta = pymc.Normal('beta',mu=0,tau=.01)

Re: Question about python package numpy

2015-03-01 Thread fl
On Sunday, March 1, 2015 at 1:25:59 PM UTC-8, Andrea D'Amore wrote: > On 2015-03-01 20:32:34 +, fl said: > > > import numpy > > it succeeds. On http://wiki.scipy.org/Cookbook, it shows some interesting > > code example snippet, such as Cookbook / ParticleFilte

Question about python package numpy

2015-03-01 Thread fl
Hi, It is difficult to install numpy package for my PC Windows 7, 64-bit OS. In the end, I install Enthought Canopy, which is recommended on line because it does install numpy automatically. Now, I can test it with import numpy it succeeds. On http://wiki.scipy.org/Cookbook, it shows some inter

What meaning of this ""hello %s you are %s years old" % x"

2014-07-27 Thread fl
Hi, I get a post on tuple, see below please, on line. It seems that something is missing. I want to learn tuple from this example as well. Could you explain it to me (a tuple % another tuple)? Thanks, http://stackoverflow.com/questions/1708510/python-list-vs-tuple-when-to-use-each In Py

Re: What is the simplest method to get a vector result?

2014-07-25 Thread fl
On Friday, July 25, 2014 8:37:14 PM UTC-4, Ian wrote: > On Fri, Jul 25, 2014 at 5:08 PM, fl wrote: > > Do you have other ways to import? (I find the above import a little more > > letters) > > What's wrong with: > > import numpy I was wrong, maybe some ca

Re: What is the simplest method to get a vector result?

2014-07-25 Thread fl
On Thursday, July 24, 2014 9:49:14 AM UTC-4, Vlastimil Brom wrote: > 2014-07-24 14:53 GMT+02:00 fl : > internally): > http://mpmath.org/ > Using the sensible defaults, the plotting of a function can be as simple as: > > mpmath.plot(mpmath.sin) > > As for your original

Re: How to index an array with even steps?

2014-07-25 Thread fl
On Friday, July 25, 2014 7:45:31 AM UTC-4, fl wrote: > to 999 of the target array. Then, I want to use interpolate it from 200 to > 1000 > > with interpolate method. > > In Python, ':' is used to indicate range (while in Matlab I know it can be > used > to con

How to index an array with even steps?

2014-07-25 Thread fl
Hi, I have an array arr which is indexed from 0 to 999. I would like to construct a column in two steps. The first step is input from 200 data, evenly spread from 0 to 999 of the target array. Then, I want to use interpolate it from 200 to 1000 with interpolate method. In Python, ':' is used to

Re: What is the simplest method to get a vector result?

2014-07-24 Thread fl
On Thursday, July 24, 2014 10:25:52 AM UTC-4, Marko Rauhamaa wrote: > #!/usr/bin/env python3 > > import math > > for x in range(0, 361, 15): > > print(int((math.sin(x / 180 * math.pi) + 1) * 30 + 0.5) * " " + "*") > >

How to place several "import ...." lines in one .py file?

2014-07-24 Thread fl
Hi, I have seen several kinds of module import examples, but most of the programs are small and less content. They only have one or two module import. I'll use the following modules in a small project. I would like to know whether it is appropriate to put all of them at the file header, like thi

Re: How can I import unnecessary_math?

2014-07-24 Thread fl
On Thursday, July 24, 2014 1:58:45 PM UTC-4, Chris Angelico wrote: > On Fri, Jul 25, 2014 at 3:54 AM, fl wrote: > > @with_setup(my_setup_function, my_teardown_function) > > def test_numbers_3_4(): > > print 'test_numbers_3_4 < act

Re: How can I import unnecessary_math?

2014-07-24 Thread fl
On Thursday, July 24, 2014 1:48:02 PM UTC-4, fl wrote: > On Thursday, July 24, 2014 1:37:49 PM UTC-4, Chris Angelico wrote: > > > On Fri, Jul 25, 2014 at 3:33 AM, fl wrote: > > Thanks. The source of that snippet is from this link: > > > http://pythontest

Re: How can I import unnecessary_math?

2014-07-24 Thread fl
On Thursday, July 24, 2014 1:37:49 PM UTC-4, Chris Angelico wrote: > On Fri, Jul 25, 2014 at 3:33 AM, fl wrote: > > Hi, > > I want to write some test code. Some on-line tutorials have such codes: > > > > > > from unnecessary_math import multiply > Which tut

How can I import unnecessary_math?

2014-07-24 Thread fl
Hi, I want to write some test code. Some on-line tutorials have such codes: from unnecessary_math import multiply When it runs, it has errors: >>> from unnecessary_math import multiply Traceback (most recent call last): File "", line 1, in ImportError: No module named unnecessary_math I hav

What is the simplest method to get a vector result?

2014-07-24 Thread fl
Hi, I have read a lot about Python, but it still has a problem now on a simple exercise. For example, I want to generate a sine curve. First, I get a time sequence: index=range(100) I import math module, try to calculate sine with math.sin(index*math.pi/2) but it fails. It is possible to use

Re: How to install data analysis pandas toolkit?

2014-07-23 Thread fl
On Wednesday, July 23, 2014 8:30:00 PM UTC-4, fl wrote: I have figured it out. It is installed under Cygwin. Although there are some errors in the process, it works now. Thanks, -- https://mail.python.org/mailman/listinfo/python-list

How to install data analysis pandas toolkit?

2014-07-23 Thread fl
Hi, I download data analysis pandas toolkit (Windows 32 version) to my PC: pandas-0.14.0.win32-py2.7.exe After I run it, I still cannot import the module: >>> import pandas as pd No module named numpy Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-pack

Where is the function of Repr.repr1() in this example?

2014-07-23 Thread fl
Hi, I run the example code below from website: https://docs.python.org/2/library/repr.html#repr.Repr.repr1 If I run these lines from an editor, it echoes: >>> >>> dsfdsf # entered letters If I only run the last line (hoping the same effect with running from the editor) it simply ech

Re: Question about Pass-by-object-reference?

2014-07-22 Thread fl
On Tuesday, July 22, 2014 8:27:15 PM UTC-4, Terry Reedy wrote: > When you call a function, Python binds function parameter names to > argument objects in the function's local namespace, the same as in name > assignments. Given > def f(a, b): pass > a call f(1, 'x') starts by executing > a, b = 1,

Re: Question about Pass-by-object-reference?

2014-07-22 Thread fl
On Tuesday, July 22, 2014 4:35:33 PM UTC-4, Peter Pearson wrote: > On Tue, 22 Jul 2014 12:34:51 -0700 (PDT), fl wrote: > When you say "def reassign(list)", that means "I'm defining a function > to which the caller will pass one object, and within this function I'

Re: Question about Pass-by-object-reference?

2014-07-22 Thread fl
On Tuesday, July 22, 2014 4:46:25 PM UTC-4, emile wrote: > On 07/22/2014 01:35 PM, Peter Pearson wrote: > def reassign(mylist): # no reason to shadow the list builtin > mylist[:] = [0,1] > > mylist = [1] > reassign(mylist) > mylist > > Emile I have a new question on the code. When I run it

Re: Question about Pass-by-object-reference?

2014-07-22 Thread fl
On Tuesday, July 22, 2014 4:46:25 PM UTC-4, emile wrote: > On 07/22/2014 01:35 PM, Peter Pearson wrote: > def reassign(mylist): # no reason to shadow the list builtin > mylist[:] = [0,1] > mylist = [1] > reassign(mylist) > mylist > Emile Thanks for your example. I do not find the explanation

Re: Why does not pprint work?

2014-07-22 Thread fl
On Tuesday, July 22, 2014 5:51:07 PM UTC-4, emile wrote: > On 07/22/2014 02:42 PM, fl wrote: > pprint is a module name -- you need to invoke the pprint function from > within the pprint module: > pprint.pprint(board) Thanks. I am curious about the two pprint. Is it the first pprint

Why does not pprint work?

2014-07-22 Thread fl
Hi, I read web tutorial at: http://nedbatchelder.com/blog/201308/names_and_values_making_a_game_board.html I enter the example lines of that website: import pprint board = [ [0]*8 ] * 8 pprint(board) It echos error with Python 2.7: Traceback (most recent call last): File "C:\Python27\Lib

Re: Question about Pass-by-object-reference?

2014-07-22 Thread fl
On Tuesday, July 22, 2014 3:32:19 PM UTC-4, Ned Batchelder wrote: > On 7/22/14 3:04 PM, fl wrote: > it is here: http://nedbatchelder.com/text/names.html > > When I enter the command lines on my computer: > I recommend putting the code into a .py file, and > running it all at

Re: Question about Pass-by-object-reference?

2014-07-22 Thread fl
On Tuesday, July 22, 2014 3:04:09 PM UTC-4, fl wrote: Hi, Excuse me. I find that the OP misses some info. I rewrite it again: I learn Python function call on tutorial. There is a link on this subject. http://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k

Question about Pass-by-object-reference?

2014-07-22 Thread fl
Hi, I learn Python function call on tutorial. There is a link on this subject. http://robertheaton.com/2014/02/09/pythons-pass-by-object-reference-as-explained-by-philip-k-dick/ Although it explains clearly, the figure makes me puzzled. ""Python is different. As we know, in Python, "Object refere

How to use string constant?

2014-07-21 Thread fl
Hi, I learn string constant on Python tutorial at: https://docs.python.org/2/library/string.html Although it gives explanation, it does not show me any example usage. Could you give me an example on using these options? string.digits string.ascii_letters Thanks, -- https://mail.python.or

Re: How to extract digit from a number?

2014-07-21 Thread fl
On Monday, July 21, 2014 4:26:25 PM UTC-4, Tim Chase wrote: > On 2014-07-21 13:14, fl wrote: > You don't specify *what* is wrong or what constitutes "does not > work". If you provide an example of what you *do* want, folks here > can help you get closer to the code you

How to extract digit from a number?

2014-07-21 Thread fl
Hi, I see the following example on line, but it does not work. I do not know what is wrong. Could you correct it for me? Thanks, I'm not sure what [1, 1, 0, 0, 0, 0, ...] has to do with 128, but if you want the base 10 digits: >>> a = 1234 >>> [int(d) for d in str(

I am confused about ' and "

2014-07-10 Thread fl
Hi, It is still in the Regular expression operations concept, this link: has example using single quote mark: ' https://docs.python.org/2/library/re.html#re.split While in this link: https://docs.python.org/3/howto/regex.html It gives table with quote: " Regular String Raw string "ab*"

How to decipher :re.split(r"(\(\([^)]+\)\))" in the example

2014-07-10 Thread fl
Hi, This example is from the link: https://wiki.python.org/moin/RegularExpression I have thought about it quite a while without a clue yet. I notice that it uses double quote ", in contrast to ' which I see more often until now. It looks very complicated to me. Could you simplified it to a simp

Re: What does (A ``quote'' is the character used to open the string, i.e. either ' or ".) mean?

2014-07-10 Thread fl
On Thursday, July 10, 2014 10:14:14 AM UTC-4, Chris "Kwpolska" Warrick wrote: > > > > > Please don't learn from this link. It's from 2001. You should learn > > from modern documentation: https://docs.python.org/ (if not running > > 3.4.x, change the version in the top) > > > > You also sho

What does (A ``quote'' is the character used to open the string, i.e. either ' or ".) mean?

2014-07-10 Thread fl
Hi, For me, it is difficult to understand the last line of the paragraph below in parenthesis (A ``quote'' is the character used to open the string, i.e. either ' or ".) It talks about triple-quoted strings. Where is ``quote'' from? It has two ` and '. What this different ` and ' do for here?

  1   2   >