Re: Just starting to learn Python, and encounter a problem

2016-07-22 Thread Zagyen Leo
I got it! Thank you. Hope in one day I could help other newbies as you do. -- https://mail.python.org/mailman/listinfo/python-list

Re: Why not allow empty code blocks?

2016-07-22 Thread Kent Tong
On Saturday, July 23, 2016 at 9:49:51 AM UTC+8, Steven D'Aprano wrote: > Because it cannot tell the difference between an empty code block and > failing to indent the code block: > > for x in sequence: > print('loop') Thanks for the excellent answer! -- https://mail.python.org/mailman/listinfo/

Re: Why not allow empty code blocks?

2016-07-22 Thread Steven D'Aprano
On Sat, 23 Jul 2016 01:33 am, Kent Tong wrote: > Hi > > I'm aware that we can use 'pass' as an empty code block. But why doesn't > python allow a code block to be empty and thus eliminate the need for this > null statement? Because it cannot tell the difference between an empty code block and fa

Re: learning python. learning defining functions . need help

2016-07-22 Thread Steven D'Aprano
On Sat, 23 Jul 2016 01:21 am, justin walters wrote: > That should illustrate why. This is because simply typing '{}' could be > interpreted as > either a dict or a set. No. {} is always an empty dict. That is a language guarantee. Any programming language where {} is not an empty disk is not val

How asyncio works? and event loop vs exceptions

2016-07-22 Thread Marco S. via Python-list
I'm developing a web app based on aiohttp, and I find the event loop concept very interesting. I never programmed with it before, but I know that node.js and GUIs are based on it. What I can't understand is how asyncio make it possible to run multiple tasks concurrently, since it's single threaded

Re: Dynamically call methods where method is known by address vs name

2016-07-22 Thread Malcolm Greene
Hi Michael, > Out[3]: 'HELLO' > In [4]: g = str.upper > In [5]: g(s) > Out[5]: 'HELLO' That's perfect! My mistake was trying to use the method returned by ''.upper vs. str.upper. Thank you, Malcolm   -- https://mail.python.org/mailman/listinfo/python-list

Re: Dynamically call methods where method is known by address vs name

2016-07-22 Thread Michael Selik
On Fri, Jul 22, 2016 at 4:05 PM Malcolm Greene wrote: > I know I can do the following: > > >>> s = 'lower' > >>> getattr(s, 'upper')() > 'LOWER' > > But how could I do the same if I had the method 'address' (better > name???) vs. method name? > > >>> upper_method = s.upper > > How do I combine th

Dynamically call methods where method is known by address vs name

2016-07-22 Thread Malcolm Greene
I know I can do the following: >>> s = 'lower' >>> getattr(s, 'upper')() 'LOWER' But how could I do the same if I had the method 'address' (better name???) vs. method name? >>> upper_method = s.upper How do I combine this upper_method with string s to execute the method and return 'LOWER'?

Re: Stupid question, just need a quick and dirty fix

2016-07-22 Thread Michael Selik
On Fri, Jul 22, 2016 at 2:11 AM Steven D'Aprano wrote: > On Fri, 22 Jul 2016 03:18 pm, Michael Selik wrote: > >> On Jul 22, 2016, at 12:39 AM, Jordan Bayless > wrote: > >> > >> Posting the entire code snippet is tough because it's thousands of lines > >> of code. > > > > You could paste into a G

Re: learning python. learning defining functions . need help

2016-07-22 Thread MRAB
On 2016-07-22 16:41, D'Arcy J.M. Cain wrote: On Fri, 22 Jul 2016 08:21:17 -0700 justin walters wrote: You could also replace that line with: if stock is None or type(stock) != dict: Use isinstance(). That handles classes that subclass dict as well. If you're checking that it's a dict,

Re: learning python. learning defining functions . need help

2016-07-22 Thread D'Arcy J.M. Cain
On Fri, 22 Jul 2016 08:21:17 -0700 justin walters wrote: > You could also replace that line with: > > if stock is None or type(stock) != dict: Use isinstance(). That handles classes that subclass dict as well. -- D'Arcy J.M. Cain System Administrator, Vex.Net http://www.Vex.Net/ IM:da...@

Re: Algorithm for sequencing a collection of dependent equations

2016-07-22 Thread Malcolm Greene
Hi Tim, > I think that what you're looking for is a topological sort BINGO! That's *exactly* what I was searching for. Thank you very much, Malcolm -- https://mail.python.org/mailman/listinfo/python-list

Re: Why not allow empty code blocks?

2016-07-22 Thread Rob Gaddi
Kent Tong wrote: > Hi > > I'm aware that we can use 'pass' as an empty code block. But why doesn't > python allow a code block to be empty and thus eliminate the need for this > null statement? > > thanks in advance Because it's more likely that you have an indentation error than an intentional

Re: Algorithm for sequencing a collection of dependent equations

2016-07-22 Thread Tim Golden
On 22/07/2016 17:01, Malcolm Greene wrote: We're working on a DSL (domain specific language) that we translate into a list of tokenized expressions. My challenge is to figure out how to sequence evaluation of these expressions so that we evaluate these expressions in the proper order given that e

Re: Floating point equality [was Re: What exactly is "exact" (was Clean Singleton Docstrings)]

2016-07-22 Thread Ben Bacarisse
Chris Kaynor writes: > On Thu, Jul 21, 2016 at 4:54 PM, Ben Bacarisse wrote: > >> Steven D'Aprano writes: >> >> > Or you might be using a language like Javascript, which intentionally has >> > only floats for numbers. That's okay, you can still perform exact integer >> > arithmetic, so long as

Algorithm for sequencing a collection of dependent equations

2016-07-22 Thread Malcolm Greene
We're working on a DSL (domain specific language) that we translate into a list of tokenized expressions. My challenge is to figure out how to sequence evaluation of these expressions so that we evaluate these expressions in the proper order given that expressions have dependencies on other express

Re: Stupid question, just need a quick and dirty fix

2016-07-22 Thread Cousin Stanley
Jordan Bayless wrote: > > desired = Id < 10 or Id > 133 or Id in good_ids > > When I try to validate whether I passed that check, > I'm told there's a Name error and it's not defined > On the outside chance that failing to define Id produces the Name error, I defined Id in a fo

Re: learning python. learning defining functions . need help

2016-07-22 Thread Random832
On Fri, Jul 22, 2016, at 11:21, justin walters wrote: > Try opening the interactive terminal on your command line and type the > following: > > type({}) == dict() > > That should illustrate why. That doesn't illustrate anything relevant at all. The reason this is false is because dict() is

Re: learning python. learning defining functions . need help

2016-07-22 Thread Chris Angelico
On Sat, Jul 23, 2016 at 1:21 AM, justin walters wrote: > Hi Chris, > > Try opening the interactive terminal on your command line and type the > following: > > type({}) == dict() > > That should illustrate why. This is because simply typing '{}' could be > interpreted as > either a dict or a se

Why not allow empty code blocks?

2016-07-22 Thread Kent Tong
Hi I'm aware that we can use 'pass' as an empty code block. But why doesn't python allow a code block to be empty and thus eliminate the need for this null statement? thanks in advance -- https://mail.python.org/mailman/listinfo/python-list

Re: learning python. learning defining functions . need help

2016-07-22 Thread justin walters
On Fri, Jul 22, 2016 at 6:24 AM, Chris Angelico wrote: > On Fri, Jul 22, 2016 at 11:13 PM, Dennis Lee Bieber > wrote: > > Now... Going much beyond the assignment (if you were having > trouble > > with the assignment, this will seem like magic) [Python 2.7]: > > I'm not sure, but I think

Re: Just starting to learn Python, and encounter a problem

2016-07-22 Thread MRAB
On 2016-07-22 14:59, Zagyen Leo wrote: yeah, it may be quite simple to you experts, but hard to me. In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Michael Palin", t

Re: Just starting to learn Python, and encounter a problem

2016-07-22 Thread justin walters
: On Jul 22, 2016 7:46 AM, "Gordon Levi" wrote: > > Zagyen Leo wrote: > > >yeah, it may be quite simple to you experts, but hard to me. > > > >In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they

Re: Stupid question, just need a quick and dirty fix

2016-07-22 Thread MRAB
On 2016-07-22 05:19, Jordan Bayless wrote: I'm trying to modify some code to suit my purposes and I'm just trying to filter results as necessary. Basically, the code is returning one of a number from a subset of 150 numbers. I want to only do anything with it if the number is a 'good' one. I'm

Re: Convert from unsigned long long to PyLong

2016-07-22 Thread MRAB
On 2016-07-22 07:01, Tian JiaLin wrote: HI There, I'm using MySQLdb as the MySQL client. Recently I got a weird problem of this library. After looking into it, I suspect the problem may related to the conversion from unsigned long to PyLongObject. Here is the detail, If you are familiar with

Re: Just starting to learn Python, and encounter a problem

2016-07-22 Thread Gordon Levi
Zagyen Leo wrote: >yeah, it may be quite simple to you experts, but hard to me. > >In one of exercises from the Tutorial it said: "Write a program that asks the >user their name, if they enter your name say "That is a nice name", if they >enter "John Cleese" or "Michael Palin", tell them how yo

Re: Just starting to learn Python, and encounter a problem

2016-07-22 Thread Bob Gailer
On Jul 22, 2016 10:00 AM, "Zagyen Leo" wrote: > > yeah, it may be quite simple to you experts, but hard to me. > > In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Micha

Re: Just starting to learn Python, and encounter a problem

2016-07-22 Thread Random832
On Fri, Jul 22, 2016, at 09:59, Zagyen Leo wrote: > yeah, it may be quite simple to you experts, but hard to me. > > In one of exercises from the Tutorial it said: "Write a program that asks > the user their name, if they enter your name say "That is a nice name", > if they enter "John Cleese" o

Just starting to learn Python, and encounter a problem

2016-07-22 Thread Zagyen Leo
yeah, it may be quite simple to you experts, but hard to me. In one of exercises from the Tutorial it said: "Write a program that asks the user their name, if they enter your name say "That is a nice name", if they enter "John Cleese" or "Michael Palin", tell them how you feel about them ;), ot

Re: learning python. learning defining functions . need help

2016-07-22 Thread Chris Angelico
On Fri, Jul 22, 2016 at 11:13 PM, Dennis Lee Bieber wrote: > Now... Going much beyond the assignment (if you were having trouble > with the assignment, this will seem like magic) [Python 2.7]: I'm not sure, but I think your code would become Py3 compatible if you just change your prints.

Re: Stupid question, just need a quick and dirty fix

2016-07-22 Thread thilfigr16
I'm certainly not going to sugar-coat it and act like I know anything about this language, or wax about how I think it's "inferior" for any reason (because doing so would be pretty foolish). I just figured I'd be able to muddle through and find *something* that would easily filter out results I

Re: python3: why writing to socket require bytes type while writing to a file require str ?

2016-07-22 Thread Steven D'Aprano
On Fri, 22 Jul 2016 06:52 pm, Yubin Ruan wrote: > Hi, > I'm migrating my code to python3 now and find it hard to deal with > python's 'str' and 'bytes' type. It's kind of painful. One thing I > find really confusing is that, writing to a socket requires argument > to be of type 'by

Re: python3: why writing to socket require bytes type while writing to a file require str ?

2016-07-22 Thread Frank Millman
"Yubin Ruan" wrote in message news:47f3acf9-8da2-4aad-a6f0-7a9efbdfe...@googlegroups.com... In my understanding, writing to a file would requires that everything be written byte by byte. So writing objects of type 'bytes' to socket makes sense. But, how could python write to file using unic

Re: python3: why writing to socket require bytes type while writing to a file require str ?

2016-07-22 Thread Chris Angelico
On Fri, Jul 22, 2016 at 6:52 PM, Yubin Ruan wrote: > In my understanding, writing to a file would requires that everything be > written byte by byte. So writing objects of type 'bytes' to socket makes > sense. But, how could python write to file using unicode(type 'str')? Does > python enco

python3: why writing to socket require bytes type while writing to a file require str ?

2016-07-22 Thread Yubin Ruan
Hi, I'm migrating my code to python3 now and find it hard to deal with python's 'str' and 'bytes' type. It's kind of painful. One thing I find really confusing is that, writing to a socket requires argument to be of type 'bytes'(otherwise python throw 'str does not support buffer interfa