Re: what is payload

2017-09-07 Thread eth0
Era el Thu, 7 Sep 2017 00:48:34 -0700 (PDT) en comp.lang.python,
cuando de repente Andrej Viktorovich
dijo lo siguiente acerca de
what is payload:

>  Hello,
> 
>  Have working sample with strange property - payload:
> 
>  class ExampleClass(object):
>  def __init__(self,value):
>  print("Initialising instance...")
>  self.payload = value
> 
>  exampleInstance = ExampleClass(42)
>  print(exampleInstance.payload)
> 
> 
>  Is it some default field that all objects has? What it is used for?
> 
>   

No, it's just that Python lets you add members to your instance at
runtime. In this case, that code is adding an instance variable called
payload, but it's not some special property or anything.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Artificial creating of [Lists], is it possible? the best way...

2017-11-17 Thread eth0
On Fri, 17 Nov 2017 00:04:16 + in comp.lang.python, MRAB said:
>  On 2017-11-16 18:47, jakub.raj...@gmail.com wrote:
> > Hello, im working on school project, its deck game Sorry!
> > I need to create specific lists:
> > My idea is about to using for
> > For i in range (n):
> > i=[]
> > I know, that there is no possibility to make it from number, but
> > i havent idea, how to reach my wants Li/L"i"/L(i), how to make
> > possible for lists?
> > 
> > 
>  If you want multiple lists, make a list of lists:
> 
>  my_lists = []
> 
>  for i in range(n):
>   my_lists.append([])
> 
>  Then you can say my_lists[0], my_lists[1], etc.

It'd be even shorter using a list comprehension:

my_lists = [[] for i in range(n)]

And _even shorter still_ just using the multiply operator:

my_lists = [[]] * n
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: python logic

2017-09-01 Thread eth0
Era el Fri, 1 Sep 2017 06:30:43 -0700 (PDT) en comp.lang.python,
cuando de repente SS
dijo lo siguiente acerca de
python logic:

>  Check out the following simple code:
> 
>  #!/bin/python
> 
>  print "1 - echo 1"
>  print "2 - echo 2"
> 
>  answer = input("Enter your choice - ")
> 
>  if answer == 1:
>print "1"
>  elif answer == 2:
>print "2"
>  else:
>print "Invalid choice!"
> 
> 
>  The else statement noted above works fine for numeric values other
>  then 1 or 2.  But if a user types in alphanumeric data (letters) into
>  this, it blows up.  Check out the following:
> 
>  [root@ansi ~]$ ./trash
>  1 - echo 1
>  2 - echo 2
>  Enter your choice - 3
>  Invalid choice!
> 
>  [root@ansi ~]$ ./trash
>  1 - echo 1
>  2 - echo 2
>  Enter your choice - r
>  Traceback (most recent call last):
>File "./trash", line 6, in 
>  answer = input("Enter your choice - ")
>File "", line 1, in 
>  NameError: name 'r' is not defined
> 
>  I would expect the same behavior from both runs.  Why does Python
>  differ in the way it treats a character in that program?  Finally,
>  how to accomodate for such (how to fix)?
> 
>  TIA

In Python 2, the input() function evaluates whatever you enter in the
prompt. In your case, Python is trying to evaluate 'r' as if it was
a variable or something. Use the raw_input() function instead.

However, note that if you ever want to run your script with Python 3
you'll have to switch back to using input(), which does exactly the
same as Python 2's raw_input().
-- 
https://mail.python.org/mailman/listinfo/python-list