[pythonvis] Re: A Question About Import And Another About List Comprehensions

  • From: Dzhovani Chemishanov <dzhovani.chemishanov@xxxxxxxxx>
  • To: pythonvis@xxxxxxxxxxxxx
  • Date: Wed, 1 Jul 2020 20:47:39 +0300

Hi,
  Regarding the import statement, import to the level it is
recognizable. If the names are too long, use "as" in order to make the
code readable, but not too short aliases.
  Regarding comprehensions, again strive for readability. If you are
not interested at the exact transformation or it is trivial, then move
it to the end of line and use the variable name to convey meaning.
HTH,
Dzhovani

On 7/1/20, jhomme1028@xxxxxxxxx <jhomme1028@xxxxxxxxx> wrote:

Hi,
As I think about using import, I feel like even if it's overkill, you
should
very often import something and then write dot notation to explicitly tell
Python to use a module or variable to keep from accidentally using one from
your program. But I still want to ask which form of the import statement
you
should use and when. So, what is the best practice for this?

Now to list comprehensions. I am proud that I understood one and got it to
work, but I feel that sometimes I might want to favor using a for loop if
it
makes the code more readable. What is the best practice for this. Below is
my code for getting and rolling the initial six dice in Farkle.

And thanks for your answers in advance.

import random

min = 1
max = 6

table = [random.randint(min, max) for i in range(max)]
print (table)


Thanks.

Jim

==========
Jim Homme
Skype: jim.homme
FreeChess: jhomme
Twitter: jimhomme <https://twitter.com/jimhome>
Facebook: jimhomme
Website: jimhomme.com <https://www.jimhomme.com>



List web page is
//www.freelists.org/webpage/pythonvis

To unsubscribe, send email to
pythonvis-request@xxxxxxxxxxxxx with "unsubscribe" in the Subject field.

List web page is 
//www.freelists.org/webpage/pythonvis

To unsubscribe, send email to 
pythonvis-request@xxxxxxxxxxxxx with "unsubscribe" in the Subject field.

Other related posts: