Re: Pythonic style

2016-04-28 Thread Chris Angelico
On Fri, Apr 29, 2016 at 4:12 PM, Gregory Ewing wrote: > Chris Angelico wrote: >> >> I thought the twentieth zen would never be found? > > > Yes. This will have to be numbered the 21st zen > to maintain that invariant. > Python for the 21st Century. In a hundred years, another zen! ChrisA -- ht

Re: Pythonic style

2016-04-28 Thread Gregory Ewing
Chris Angelico wrote: I thought the twentieth zen would never be found? Yes. This will have to be numbered the 21st zen to maintain that invariant. -- Greg -- https://mail.python.org/mailman/listinfo/python-list

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Gregory Ewing
Irmen de Jong : if sys.stdout.isatty(): #use a pager to display help text else: #print all help text normally I think nowadays it's an anti-pattern for programs to do their own pagination. Very often the "terminal" is a GUI application with its own facilities for scrolling and se

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Jussi Piitulainen
Rustom Mody writes: > On Friday, April 29, 2016 at 7:45:35 AM UTC+5:30, Paul Rubin wrote: >> Steven D'Aprano writes: >> > (1) print the help text to stdout; >> > (2) run the help text through a pager; >> >> Stdout unless the PAGER env var is set. Otherwise, I'd say still stdout >> since the per

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Rustom Mody
On Friday, April 29, 2016 at 7:45:35 AM UTC+5:30, Paul Rubin wrote: > Steven D'Aprano writes: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > Stdout unless the PAGER env var is set. Otherwise, I'd say still stdout > since the person can pipe it through a pag

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Paul Rubin
Steven D'Aprano writes: > (1) print the help text to stdout; > (2) run the help text through a pager; Stdout unless the PAGER env var is set. Otherwise, I'd say still stdout since the person can pipe it through a pager if they want, but you could use the pager or be fancy and try to detect if st

Re: Pivot table of Pandas

2016-04-28 Thread Sayth Renshaw
On Friday, 29 April 2016 09:56:13 UTC+10, David Shi wrote: > Hello, Matt, > Please see the web link.Pandas Pivot Table Explained > > |   | > |   |   |   |   |   | > | Pandas Pivot Table ExplainedExplanation of pandas pivot_table function. | > | | > | View on pbpython.com | Preview by Yahoo | > |

Re: Controlling the passing of data

2016-04-28 Thread Sayth Renshaw
On Friday, 29 April 2016 01:19:28 UTC+10, Dan Strohl wrote: > If I am reading this correctly... you have something like (you will have to > excuse my lack of knowledge about what kinds of information these actually > are): > > > 1234 > first > > > 5678 > second > > > > And

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Steven D'Aprano
On Fri, 29 Apr 2016 07:08 am, Grant Edwards wrote: > On 2016-04-28, Random832 wrote: >> On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote: >>> That's fine. If you want two or three forms of documentation then you >>> prepare two or three forms of documentation. >>> >>> Adding an option to run

Re: Pythonic style

2016-04-28 Thread Chris Angelico
On Fri, Apr 29, 2016 at 10:48 AM, Gregory Ewing wrote: > MRAB wrote: > >> Is it worthy of being in the Zen of Python? > > > +1. Maybe something along the lines of: > >Dunder methods are for defining, not calling. >Unless you're a dunderhead[1]. > > [1] Meant in the sense of an enthusiast,

Re: Pythonic style

2016-04-28 Thread Gregory Ewing
MRAB wrote: Is it worthy of being in the Zen of Python? +1. Maybe something along the lines of: Dunder methods are for defining, not calling. Unless you're a dunderhead[1]. [1] Meant in the sense of an enthusiast, cf. gearhead. -- Greg -- https://mail.python.org/mailman/listinfo/pytho

Pivot table of Pandas

2016-04-28 Thread David Shi via Python-list
Hello, Matt, Please see the web link.Pandas Pivot Table Explained |   | |   |   |   |   |   | | Pandas Pivot Table ExplainedExplanation of pandas pivot_table function. | | | | View on pbpython.com | Preview by Yahoo | | | |   | Debra and Fred have their own groups. How to split the pivot

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Grant Edwards
On 2016-04-28, Random832 wrote: > On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote: >> That's fine. If you want two or three forms of documentation then you >> prepare two or three forms of documentation. >> >> Adding an option to run the default 'help' output through a pager or >> display it

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Cameron Simpson
On 29Apr2016 03:06, Chris Angelico wrote: On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano wrote: I have an application written in Python which accepts -h or --help to show help. I can: (1) print the help text to stdout; (2) run the help text through a pager; (3) do something else? Many c

Re: Have I ofended someone?

2016-04-28 Thread alister
On Thu, 28 Apr 2016 20:11:27 +, alister wrote: > I don't see my posts appearing, posting to news group using Pan on > Linux. > posts to other news groups are fine No just going blind Someone top-posted to my last reply & then everything got snipped to restore readability. -- Be careful

Have I ofended someone?

2016-04-28 Thread alister
I don't see my posts appearing, posting to news group using Pan on Linux. posts to other news groups are fine -- Just about every computer on the market today runs Unix, except the Mac (and nobody cares about it). -- Bill Joy 6/21/85 -- https://mail.python.org/mailman/listinfo/

Re: Have I ofended someone?

2016-04-28 Thread Marko Rauhamaa
alister : > I don't see my posts appearing, posting to news group using Pan on > Linux. posts to other news groups are fine Take yourself out of your killfile. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Random832
On Thu, Apr 28, 2016, at 15:39, Grant Edwards wrote: > That's fine. If you want two or three forms of documentation then you > prepare two or three forms of documentation. > > Adding an option to run the default 'help' output through a pager or > display it in a web browser doesn't somehow force

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Grant Edwards
On 2016-04-28, Marko Rauhamaa wrote: > Grant Edwards : > >> On 2016-04-28, Random832 wrote: >>> One disadvantage is that you have to compose two forms of >>> documentation. >> >> Only if you want two forms of documentation. >> >> If you add an option to run the help info through a pager, I don't

Re: Simplest way to locate a string in a column and get the value on the same row in another column

2016-04-28 Thread Tim Chase
On 2016-04-28 18:37, David Shi via Python-list wrote: > What is the simplest way to locate a string in a column and get > the value on the same row in another column ? 1  a2  b3  c > Locate b and obtain 2 in a table. > Looking forward to hearing from you. I've had success with using regexp matche

Re: Simplest way to locate a string in a column and get the value on the same row in another column

2016-04-28 Thread John Gordon
In David Shi writes: > What is the simplest way to locate a string in a column and get the value > on the same row in another column ? You haven't given enough context for us to be able to answer. Are you talking about a spreadsheet, a database table, an HTML table, or something else? -- Jo

Simplest way to locate a string in a column and get the value on the same row in another column

2016-04-28 Thread David Shi via Python-list
What is the simplest way to locate a string in a column and get the value on the same row in another column ? 1  a2  b3  c Locate b and obtain 2 in a table. Looking forward to hearing from you. Regards. David -- https://mail.python.org/mailman/listinfo/python-list

Best way to do subversion stuff

2016-04-28 Thread Grant Edwards
I'd like to write some small command-line utilities to do some tasks in subversion: * Do a commit that includes all modified externals. * Do a status that includes status of all externals. * Do a log that combines logs of . and all externals. There appear to be three options: 1) pysvn

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Marko Rauhamaa
Grant Edwards : > On 2016-04-28, Random832 wrote: >> One disadvantage is that you have to compose two forms of >> documentation. > > Only if you want two forms of documentation. > > If you add an option to run the help info through a pager, I don't see > how that requires you to compose two forms

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Grant Edwards
On 2016-04-28, Random832 wrote: > > > On Thu, Apr 28, 2016, at 13:33, Grant Edwards wrote: >> As long as -? -h --help just write stuff to stdout you can add >> whatever other options you like that run pagers, start up web >> browsers, or show mp4 movies on the wall without annoying grouchy old >>

RE: What should Python apps do when asked to show help?

2016-04-28 Thread Dan Strohl via Python-list
Yup.. another reason to use something like argparse... you define the argument descriptions, help, and when you raise an error, it automatically handles the output, sending it to the right place (stderr/stdout)... as well as allowing you to define different levels of verbosity easily... (or not

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Marko Rauhamaa
Irmen de Jong : > An idea: Use just one help option, then > > if sys.stdout.isatty(): > #use a pager to display help text > else: > #print all help text normally I've seen that used, but I find it annoying:

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Random832
On Thu, Apr 28, 2016, at 13:33, Grant Edwards wrote: > As long as -? -h --help just write stuff to stdout you can add > whatever other options you like that run pagers, start up web > browsers, or show mp4 movies on the wall without annoying grouchy old > Unix users like me. ;) One disadvantage

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Jussi Piitulainen
Steven D'Aprano writes: > I have an application written in Python which accepts -h or --help to > show help. I can: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > (3) do something else? > > > Many command line tools simply output help to stdout (or stderr, if

RE: What should Python apps do when asked to show help?

2016-04-28 Thread Dan Strohl via Python-list
I would hesitate to take this approach unless the tool was one that only I was going to be using, and I knew exactly what environments it was going to be in. I know that many of the system items in python work differently in different operating systems, and different os's report things different

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Grant Edwards
On 2016-04-28, Steven D'Aprano wrote: > I have an application written in Python which accepts -h or --help to show > help. I can: > > (1) print the help text to stdout; Yep: just write it to stdout. > (2) run the help text through a pager; If you do (1), and I can do that myself if that's what

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Random832
On Thu, Apr 28, 2016, at 13:06, Chris Angelico wrote: > On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano > wrote: > > Many command line tools simply output help to stdout (or stderr, if they're > > evil), > > I'm not sure stderr is particularly more evil than stdout, but whatever > :) When a too

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Ethan Furman
On 04/28/2016 10:02 AM, Dan Strohl via Python-list wrote: I would suggest using argparse https://docs.python.org/3/library/argparse.html as it handles all of that natively... On the other hand, if you feel that argparse is akin to using a canon to kill a mosquito, you can try scription*: -

RE: What should Python apps do when asked to show help?

2016-04-28 Thread Dan Strohl via Python-list
Yeah, if I am handling arguments from the command line, I use argparse, if I am doing a cli based app (so, going back and forth in interacting with the command line), I would look at clint (https://github.com/kennethreitz/clint) As many people have said here, don’t reinvent the wheel. Dan Fro

Re: What should Python apps do when asked to show help?

2016-04-28 Thread John Wong
On Thu, Apr 28, 2016 at 1:02 PM, Dan Strohl via Python-list < python-list@python.org> wrote: > I would suggest using argparse > https://docs.python.org/3/library/argparse.html as it handles all of that > natively... including validating arguments, showing errors, help, etc... > however, assuming y

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Chris Angelico
On Fri, Apr 29, 2016 at 2:33 AM, Steven D'Aprano wrote: > I have an application written in Python which accepts -h or --help to show > help. I can: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > (3) do something else? > > > Many command line tools simply outp

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Irmen de Jong
On 28-4-2016 18:33, Steven D'Aprano wrote: > but I was thinking of doing both: give my application a subcommand or an > option to display help directly in a pager, while -h and --help print to > stdout as normal. > > What do you think? Too clever? An idea: Use just one help option, then if sys

RE: What should Python apps do when asked to show help?

2016-04-28 Thread Dan Strohl via Python-list
I would suggest using argparse https://docs.python.org/3/library/argparse.html as it handles all of that natively... including validating arguments, showing errors, help, etc... however, assuming you don't want to; Send it to stdout, that allows the user to redirect it if they want to (and play

Re: How to get the closure environment in Python?

2016-04-28 Thread Rob Gaddi
Jin Li wrote: > Hi all, > > I want to get the closure environment in Python. As in the following example: > > def func1(): > x = 10 > def func2(): > return 0 > > return func2 > > f=func1() > print f() > > > How could I get the variable `x` in the environment

Re: How to get the closure environment in Python?

2016-04-28 Thread Steven D'Aprano
On Fri, 29 Apr 2016 02:23 am, Jin Li wrote: > I want to get the closure environment in Python. As in the following > example: > > def func1(): > x = 10 > def func2(): > return 0 > return func2 > > f=func1() > print f() > > > How could I get the variable

Re: What should Python apps do when asked to show help?

2016-04-28 Thread Ethan Furman
On 04/28/2016 09:33 AM, Steven D'Aprano wrote: I have an application written in Python which accepts -h or --help to show help. I can: (1) print the help text to stdout; (2) run the help text through a pager; (3) do something else? I think if the user is proficient enough to: a) run the pr

Re: What should Python apps do when asked to show help?

2016-04-28 Thread alister
On Fri, 29 Apr 2016 02:33:56 +1000, Steven D'Aprano wrote: > I have an application written in Python which accepts -h or --help to > show help. I can: > > (1) print the help text to stdout; > > (2) run the help text through a pager; > > (3) do something else? > > > Many command line tools sim

Re: How to get the closure environment in Python?

2016-04-28 Thread Yuan Cao
On Thu, Apr 28, 2016 at 12:23 PM, Jin Li wrote: > Hi all, > > I want to get the closure environment in Python. As in the following > example: > > def func1(): > x = 10 > def func2(): > return 0 > > return func2 > > f=func1() > print f() > > > How could I ge

What should Python apps do when asked to show help?

2016-04-28 Thread Steven D'Aprano
I have an application written in Python which accepts -h or --help to show help. I can: (1) print the help text to stdout; (2) run the help text through a pager; (3) do something else? Many command line tools simply output help to stdout (or stderr, if they're evil), which makes it easy to red

How to get the closure environment in Python?

2016-04-28 Thread Jin Li
Hi all, I want to get the closure environment in Python. As in the following example: def func1(): x = 10 def func2(): return 0 return func2 f=func1() print f() How could I get the variable `x` in the environment of `func2()`? i.e. `f()`. Best regards,

RE: Controlling the passing of data

2016-04-28 Thread Dan Strohl via Python-list
If I am reading this correctly... you have something like (you will have to excuse my lack of knowledge about what kinds of information these actually are): 1234 first 5678 second And you want something like: nominations = [(1,1234), (2,5678)] meetings = [(1,'first')

Re: online python courses

2016-04-28 Thread Rustom Mody
On Thursday, April 28, 2016 at 7:45:22 PM UTC+5:30, ldomp...@casema.nl wrote: > I am follows on this moment two online pythoncourses from code.tutsplus.com > But I am interested in following more online pythoncourses. > Maby someone have some links to websites for me what handles python online > c

Re: online python courses

2016-04-28 Thread justin walters
On Thu, Apr 28, 2016 at 7:57 AM, Joel Goldstick wrote: > On Thu, Apr 28, 2016 at 10:15 AM, wrote: > > I am follows on this moment two online pythoncourses from > code.tutsplus.com > > But I am interested in following more online pythoncourses. > > Maby someone have some links to websites for me

RE: online python courses

2016-04-28 Thread Dan Strohl via Python-list
I've heard good things about codeacademy.com and learnpython.org. Also, I've heard that pycharm educational edition is helpful. (https://www.jetbrains.com/pycharm-edu/ ) I haven't personally tried any of these though, so your mileage may vary. Good Luck! Dan Strohl > -Original Message

Re: online python courses

2016-04-28 Thread Joel Goldstick
On Thu, Apr 28, 2016 at 10:15 AM, wrote: > I am follows on this moment two online pythoncourses from code.tutsplus.com > But I am interested in following more online pythoncourses. > Maby someone have some links to websites for me what handles python online > courses. > > thanks > -- > https://m

Re: Controlling the passing of data

2016-04-28 Thread Rustom Mody
On Thursday, April 28, 2016 at 8:11:26 PM UTC+5:30, Dan Strohl wrote: > In addition to Peter's points, > - I would suggest breaking out the list comprehensions into standard for > loops and/or functions. That makes it easier to read and troubleshoot. (you > can always re-optimize It if needed.

RE: Controlling the passing of data

2016-04-28 Thread Dan Strohl via Python-list
In addition to Peter's points, - I would suggest breaking out the list comprehensions into standard for loops and/or functions. That makes it easier to read and troubleshoot. (you can always re-optimize It if needed.) - Peter's point about making things into functions will also help troublesh

online python courses

2016-04-28 Thread ldompeling
I am follows on this moment two online pythoncourses from code.tutsplus.com But I am interested in following more online pythoncourses. Maby someone have some links to websites for me what handles python online courses. thanks -- https://mail.python.org/mailman/listinfo/python-list

Re: Controlling the passing of data

2016-04-28 Thread Sayth Renshaw
> > Your actual problem is drowned in too much source code. Can you restate it > in English, optionally with a few small snippets of Python? > > It is not even clear what the code you provide should accomplish once it's > running as desired. > > To give at least one code-related advice: You

Re: Controlling the passing of data

2016-04-28 Thread Peter Otten
Sayth Renshaw wrote: > In my file here I needed to traverse and modify the XML file I don't want > to restore it or put it in a new variable or other format I just want to > alter it and let it flow onto the list comprehensions as they were. That looks like an arbitrary limitation to me. It's a b

Re: Why does pathlib not have is_readable() & things like that?

2016-04-28 Thread Grant Edwards
On 2016-04-28, Adam Funk wrote: > On 2016-04-26, Random832 wrote: > >> On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >>> I recently discovered pathlib in the Python 3 standard library, & find >>> it very useful, but I'm a bit surprised that it doesn't offer things >>> like is_readable() and is_

Re: Pythonic style

2016-04-28 Thread Random832
On Thu, Apr 28, 2016, at 01:16, Rustom Mody wrote: > On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: > > My rule of thumb is: Dunders are for defining, not for calling. It's > > not a hard-and-fast rule, but it'll get you through 99%+ of > > situations. > > Neat and cleve

Re: Why does pathlib not have is_readable() & things like that?

2016-04-28 Thread Jussi Piitulainen
Adam Funk writes: > On 2016-04-26, Random832 wrote: > >> On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >>> I recently discovered pathlib in the Python 3 standard library, & find >>> it very useful, but I'm a bit surprised that it doesn't offer things >>> like is_readable() and is_writable. Is

Re: Dunder docs again (was Pythonic style)

2016-04-28 Thread MRAB
On 2016-04-28 13:25, Marko Rauhamaa wrote: MRAB : 'pythonic-ness'? Surely it's 'pythonicity'! :-) Doubt it: Full Definition of generic [...] —generically \-i-k(ə-)lē\ adverb —genericness noun http://www.merriam-webster.com/dictionary/generic> I can point you to 3 alternatives,

Re: Why does pathlib not have is_readable() & things like that?

2016-04-28 Thread Adam Funk
On 2016-04-26, Random832 wrote: > On Tue, Apr 26, 2016, at 09:30, Adam Funk wrote: >> I recently discovered pathlib in the Python 3 standard library, & find >> it very useful, but I'm a bit surprised that it doesn't offer things >> like is_readable() and is_writable. Is there a good reason for th

Re: Why does pathlib not have is_readable() & things like that?

2016-04-28 Thread Adam Funk
On 2016-04-26, Steven D'Aprano wrote: > On Tue, 26 Apr 2016 11:30 pm, Adam Funk wrote: >> I've been improvising with things like this: >> >> import pathlib, os >> >> path = pathlib.Path('some/directory') >> writable = os.access(str(path), os.W_OK | os.X_OK) >> >> Is that the best way to do it?

Re: Dunder docs again (was Pythonic style)

2016-04-28 Thread Marko Rauhamaa
MRAB : > 'pythonic-ness'? Surely it's 'pythonicity'! :-) Doubt it: Full Definition of generic [...] —generically \-i-k(ə-)lē\ adverb —genericness noun http://www.merriam-webster.com/dictionary/generic> Marko -- https://mail.python.org/mailman/listinfo/python-list

Controlling the passing of data

2016-04-28 Thread Sayth Renshaw
Hi This file contains my biggest roadblock with programming and that's the abstract nature of needing to pass data from one thing to the next. In my file here I needed to traverse and modify the XML file I don't want to restore it or put it in a new variable or other format I just want to alter

Re: Dunder docs again (was Pythonic style)

2016-04-28 Thread MRAB
On 2016-04-28 12:45, Rustom Mody wrote: On Thursday, April 28, 2016 at 4:46:43 PM UTC+5:30, MRAB wrote: On 2016-04-28 06:16, Rustom Mody wrote: > On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: >> My rule of thumb is: Dunders are for defining, not for calling. It's >> n

Dunder docs again (was Pythonic style)

2016-04-28 Thread Rustom Mody
On Thursday, April 28, 2016 at 4:46:43 PM UTC+5:30, MRAB wrote: > On 2016-04-28 06:16, Rustom Mody wrote: > > On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: > >> My rule of thumb is: Dunders are for defining, not for calling. It's > >> not a hard-and-fast rule, but it'll

Re: Pythonic style

2016-04-28 Thread MRAB
On 2016-04-28 06:16, Rustom Mody wrote: On Thursday, April 28, 2016 at 9:26:21 AM UTC+5:30, Chris Angelico wrote: My rule of thumb is: Dunders are for defining, not for calling. It's not a hard-and-fast rule, but it'll get you through 99%+ of situations. Neat and clever. Should get in the docs

Re: Dictionary is really not easy to handle

2016-04-28 Thread jfong
I was overwhelmed that three gurus inspire me in three different ways in their own flavour:-) That's really appreciated! Now I understand why it's so, thanks to all of you. To Peter: > With that information, can you predict what > for k, v in {(1, 2): "three"}: print(k, v) > will print? It's

Re: for loop in python

2016-04-28 Thread BartC
On 28/04/2016 10:34, g.v.aar...@skct.edu.in wrote: start_list = [5, 3, 1, 2, 4] square_list = [] # Your code here! for square_list in start_list: x = pow(start_list, 2) square_list.append(x) square_list.sort() print square_list TypeError: unsupported operand type(s) for ** or pow(): 'l

Re: Dictionary is really not easy to handle

2016-04-28 Thread Steven D'Aprano
On Thu, 28 Apr 2016 06:27 pm, jf...@ms4.hinet.net wrote: > I have a dictionary like this: > dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} > > The following code works: > for k in dct: print(k, dct[k]) > ... > 1 D > 2 B > 3 B > 4 E > 5 A When you iterate over the dictionary, you get a

Re: for loop in python

2016-04-28 Thread Peter Otten
g.v.aar...@skct.edu.in wrote: > start_list = [5, 3, 1, 2, 4] > square_list = [] > > # Your code here! > for square_list in start_list: You are iterating over start_list, that's OK. But you are assigning the current value to square_list, a variable name that you already use for the list where y

Re: for loop in python

2016-04-28 Thread Steven D'Aprano
On Thu, 28 Apr 2016 07:34 pm, g.v.aar...@skct.edu.in wrote: > start_list = [5, 3, 1, 2, 4] > square_list = [] Here you set square_list to a list. > # Your code here! > for square_list in start_list: .^ Here you set square_list to each item of the start_list. So the first time ar

for loop in python

2016-04-28 Thread g . v . aarthi
start_list = [5, 3, 1, 2, 4] square_list = [] # Your code here! for square_list in start_list: x = pow(start_list, 2) square_list.append(x) square_list.sort() print square_list TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int' Please provide me the solution for the

Re: Dictionary is really not easy to handle

2016-04-28 Thread Peter Otten
jf...@ms4.hinet.net wrote: > I have a dictionary like this: > dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} > > The following code works: > But...this one? > for k,v in dct: print(k,v) > ... > Traceback (most recent call last): > File "", line 1, in > TypeError: 'int' object is no

Re: Dictionary is really not easy to handle

2016-04-28 Thread Rustom Mody
On Thursday, April 28, 2016 at 1:57:40 PM UTC+5:30, jf...@ms4.hinet.net wrote: > I have a dictionary like this: > > >>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} > > The following code works: > > >>> for k in dct: print(k, dct[k]) > ... > 1 D > 2 B > 3 B > 4 E > 5 A > > and this one too: >

do_POST not working on http.server with python

2016-04-28 Thread Rahul Raghunath
0 down vote favorite I'm trying to create a simple http server with basic GET and POST functionality. The program is supposed to GET requests by printing out a simple webpage that greets a user and askes how he would rather be greeted. When the user enters a greeting of his choice, th

Dictionary is really not easy to handle

2016-04-28 Thread jfong
I have a dictionary like this: >>> dct ={1: 'D', 5: 'A', 2: 'B', 3: 'B', 4: 'E'} The following code works: >>> for k in dct: print(k, dct[k]) ... 1 D 2 B 3 B 4 E 5 A and this one too: >>> for k,v in dct.items(): print(k,v) ... 1 D 2 B 3 B 4 E 5 A But...this one? >>> for k,v in dct: print(k,v

Re: Python Madlibs.py code and error message

2016-04-28 Thread Steven D'Aprano
On Thursday 28 April 2016 17:08, Stephen Hansen wrote: > On Wed, Apr 27, 2016, at 11:55 PM, Ben Finney wrote: >> Stephen Hansen writes: >> >> > On Wed, Apr 27, 2016, at 10:32 PM, Ben Finney wrote: >> > > Better: when you have many semantically-different values, use named >> > > (not positional)

Re: Python Madlibs.py code and error message

2016-04-28 Thread Ben Finney
Stephen Hansen writes: > On Wed, Apr 27, 2016, at 11:55 PM, Ben Finney wrote: > > Everything I described above works fine in Python 2. > > This response is completely unhelpful. I'll let the OP be the judge of that. > The OP is using Python 2, and using %-formatting, and so you give a > series

Re: Python Madlibs.py code and error message

2016-04-28 Thread Stephen Hansen
On Wed, Apr 27, 2016, at 11:55 PM, Ben Finney wrote: > Stephen Hansen writes: > > > On Wed, Apr 27, 2016, at 10:32 PM, Ben Finney wrote: > > > Better: when you have many semantically-different values, use named > > > (not positional) parameters in the format string. […] > > > > > > https://d