Correct Way to Write in Python

2013-08-03 Thread punk . sagar
Hi All,

Im new to Python. Im coming from C# background and want to learn Python.
I was used to do following thing in C# in my previous experiences. I want to 
know how do I implement below example in Python. How these things are done in 
Python.
[code]
public class Bank 
{

public ListCustomer lstCustomers = new ListCustomer();
private string micrcode;

public void Bank()
{
customer
}

}

public class Customer
{
private srting customername;

public string CustomerName

{
get { return customername; }
set { customername = value; }
}
}

main()
{
Customer objCustomer = new Customer;
objCustomer.CustomerName = XYZ

Bank objBank = new Bank();
objBank.lstCustomer.Add(objCustomer);

}
[/code]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct Way to Write in Python

2013-08-03 Thread Peter Otten
punk.sa...@gmail.com wrote:

 Hi All,
 
 Im new to Python. Im coming from C# background and want to learn Python.
 I was used to do following thing in C# in my previous experiences. I want
 to know how do I implement below example in Python. How these things are
 done in Python.
 [code]
 public class Bank
 {
 
 public ListCustomer lstCustomers = new ListCustomer();
 private string micrcode;
 
 public void Bank()
 {
 customer
 }
 
 }
 
 public class Customer
 {
 private srting customername;
 
 public string CustomerName
 
 {
 get { return customername; }
 set { customername = value; }
 }
 }
 
 main()
 {
 Customer objCustomer = new Customer;
 objCustomer.CustomerName = XYZ
 
 Bank objBank = new Bank();
 objBank.lstCustomer.Add(objCustomer);
 
 }
 [/code]

While I don't know C# I doubt that this is good C# code ;)
Here's a moderately cleaned-up Python version:

class DuplicateCustomerError(Exception):
pass

class Customer:
def __init__(self, name):
self.name = name

class Bank:
def __init__(self):
self.customers = {}
def add_customer(self, name):
if name in self.customers:
raise DuplicateCustomerError
customer = Customer(name)
self.customers[name] = customer
return customer

if __name__ == __main__:
bank = Bank()
bank.add_customer(XYZ)

I'm assuming a tiny bank where every customer has a unique name and only one 
program is running so that you can ignore concurrency issues.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct Way to Write in Python

2013-08-03 Thread Sagar Varule
On Saturday, August 3, 2013 12:17:49 PM UTC+5:30, Peter Otten wrote:
 punk.sa...@gmail.com wrote:
 
 
 
  Hi All,
 
  
 
  Im new to Python. Im coming from C# background and want to learn Python.
 
  I was used to do following thing in C# in my previous experiences. I want
 
  to know how do I implement below example in Python. How these things are
 
  done in Python.
 
  [code]
 
  public class Bank
 
  {
 
  
 
  public ListCustomer lstCustomers = new ListCustomer();
 
  private string micrcode;
 
  
 
  public void Bank()
 
  {
 
  customer
 
  }
 
  
 
  }
 
  
 
  public class Customer
 
  {
 
  private srting customername;
 
  
 
  public string CustomerName
 
  
 
  {
 
  get { return customername; }
 
  set { customername = value; }
 
  }
 
  }
 
  
 
  main()
 
  {
 
  Customer objCustomer = new Customer;
 
  objCustomer.CustomerName = XYZ
 
  
 
  Bank objBank = new Bank();
 
  objBank.lstCustomer.Add(objCustomer);
 
  
 
  }
 
  [/code]
 
 
 
 While I don't know C# I doubt that this is good C# code ;)
 
 Here's a moderately cleaned-up Python version:
 
 
 
 class DuplicateCustomerError(Exception):
 
 pass
 
 
 
 class Customer:
 
 def __init__(self, name):
 
 self.name = name
 
 
 
 class Bank:
 
 def __init__(self):
 
 self.customers = {}
 
 def add_customer(self, name):
 
 if name in self.customers:
 
 raise DuplicateCustomerError
 
 customer = Customer(name)
 
 self.customers[name] = customer
 
 return customer
 
 
 
 if __name__ == __main__:
 
 bank = Bank()
 
 bank.add_customer(XYZ)
 
 
 
 I'm assuming a tiny bank where every customer has a unique name and only one 
 
 program is running so that you can ignore concurrency issues.

Thanks a lot Peter. I appreciate your Help. You mentioned that C# code above is 
not good. If you can point me why it is not good, would help me learn new 
approaches as this type of Code I use to see long back(when i was fresher). 
There may be better approaches or concepts i am not aware of. If you can point 
me in that direction it would be gr8.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct Way to Write in Python

2013-08-03 Thread Steven D'Aprano
On Fri, 02 Aug 2013 23:18:47 -0700, punk.sagar wrote:

 Hi All,
 
 Im new to Python. Im coming from C# background and want to learn Python.
 I was used to do following thing in C# in my previous experiences. I
 want to know how do I implement below example in Python. How these
 things are done in Python. 

I am not an expert on C#, but I'll try to translate the following code to 
Python.


 [code]
 public class Bank
 {
   
   public ListCustomer lstCustomers = new ListCustomer();
   private string micrcode;
   
   public void Bank()
   {
   customer
   }
 
 }
 
 public class Customer
 {
   private srting customername;
   public string CustomerName

Do you mean private string rather than private srting?


   {
   get { return customername; }
   set { customername = value; }
   }
 }
 
 main()
 {
   Customer objCustomer = new Customer;
   objCustomer.CustomerName = XYZ
   
   Bank objBank = new Bank();
   objBank.lstCustomer.Add(objCustomer);
   
 }
 [/code]


Here is a literally translation, as best as I can understand the C# code. 
(But note that this is not the best Python code.)


class Bank:
def __init__(self):
self.lstCustomers = []  # Empty list of customers.
self._micrcode = ''  # Does this actually get used?

class Customer:
def __init__(self):
self._customername = ''

@property
def CustomerName(self):
return self._customername

@CustomerName.setter
def CustomerName(self, value):
if not instance(value, str):
raise TypeError('names must be strings')
self._customername = value


if __name__ == '__main__':
# Running as a script, call the main function.
objCustomer = Customer()
objCustomer.CustomerName = XYZ

objBank = Bank()
objBank.lstCustomers.append(objCustomer)



But this isn't how I would write it in Python. For starters, our naming 
conventions are different. Everything in Python is an object, even simple 
types like ints and strings, and even classes, so it isn't meaningful to 
prefix instances with obj.

We tend to avoid anything which even vaguely looks like Hungarian 
Notation, so lstCustomer is right out. Instead, we use plural for 
collections (lists, sets, dicts, whatever) of things, and singular for 
individual instances.

Also, while we can use the property decorator to make computed 
attributes, we very rarely do just to enforce private/public variables. 
Our philosophy is, if you want to shoot yourself in the foot, we're not 
going to stop you. (People spend far too much time trying to work around 
private names in other languages for Python to spend too much effort in 
this area.) Instead, we have private by convention: names starting with 
a single underscore are private, so don't touch them, and if you do, 
you have nobody but yourself to blame when you shoot yourself in the foot.

Similarly, the language doesn't spend much time enforcing type 
restrictions. Python is a dynamic language, and type restrictions go 
against that philosophy. If you have a good reason to put a non-string as 
the customer name, you can do so, but don't come crying to me if you 
break your code. So here is how I would write the above:



class Bank:
def __init__(self):
self.customers = []
self._micrcode = ''  # Does this actually get used?

class Customer:
def __init__(self, name):
# This type-check is optional.
if not instance(name, str):
raise TypeError('names must be strings')
self.name = name


if __name__ == '__main__':
# Running as a script, call the main function.
customer = Customer(XYX)

bank = Bank()
bank.customers.append(customer)


The above is still not what I call professional quality -- no doc strings 
(documentation), and the bank doesn't actually do anything, but it's a 
start.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct Way to Write in Python

2013-08-03 Thread Peter Otten
Sagar Varule wrote:

 On Saturday, August 3, 2013 12:17:49 PM UTC+5:30, Peter Otten wrote:
 punk.sa...@gmail.com wrote:

 Thanks a lot Peter. I appreciate your Help. You mentioned that C# code
 above is not good. If you can point me why it is not good, would help me
 learn new approaches as this type of Code I use to see long back(when i
 was fresher). There may be better approaches or concepts i am not aware
 of. If you can point me in that direction it would be gr8.

As I said, I don't know C#  -- but I already tried to fix some of the 
potential issues in my code snippet.

- A list is not the best choice to store the customers -- there should be a 
lookup by some kind of ID (I picked the name to keep it simple)
- Is it really necessary to expose that container in a language that 
provides privacy?
- Is there ever a customer without name/ID? I'd say no, so these should be 
passed as constructor arguments.
- Renaming a customer is a delicate process, you may need to keep track of 
the old name, the reason for the name, update your database etc., so I 
wouldn't allow setting the attribute and instead add a method

Bank.rename_customer(...)

or

Bank.customers.rename_customer(...)

Asking to translate code might make sense if you are a wizzard in the 
other language and want to see how a particular construct is written 
idomatically in Python, but to rewrite very basic C# code in Python is a bit 
like trying to learn a natural language by replacing one word after another 
in a text with the word in the new language that you looked up in a dict. 
The result tends to be underwhelming.

I recommend that you read the tutorial and then try to solve a simple task 
in Python. Whenever you run into a problem you can come here for help. 
Because there's a real problem behind your code there will be different ways 
to solve it in Python, and you'll learn much more about the possibilites 
Python has to offer while your code gradually becomes more idiomatic.

-- 
http://mail.python.org/mailman/listinfo/python-list


Minions are Python Powered!

2013-08-03 Thread Borja Morales
Everytime I watched the minions from Despicable Me something was hitting my 
unconscious mind. Finally I figured it out... Minions are Python Powered!

I couldn't resist to make an image :)

https://www.dropbox.com/s/t8kaba619vi6q82/minion_powered_by_python_reality3d.jpg
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 79 char max

2013-08-03 Thread Wayne Werner

On Wed, 31 Jul 2013, Joshua Landau wrote:


To explain, I tend to take the HTML form of alignment by wrapping:

open stuff stuff stuff close

to

open
    stuff
    stuff
    stuff
close


Depending on how much 'stuff' I have, I, for one, prefer a third:

open stuff
 stuff
 stuff
close


Which then makes it 1) fairly easy to read, 2) fairly easy to extend.

Of course it could just be that I'm used to that style - our brains are 
wired weird.



-W-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-08-03 Thread Wayne Werner

On Thu, 1 Aug 2013, Gilles wrote:


On Wed, 24 Jul 2013 10:38:52 -0400, Kevin Walzer k...@codebykevin.com
wrote:

Thanks. hMailServer was one of the apps I checked, and I was just
making sure there weren't something simpler, considering my needs,
ideally something like Mongoose MTA.


Have you checked Kenneth Rietz's inbox.py[1]? It's fairly simple to 
use/extend and might fit your modest needs.



-W

[1]:https://crate.io/packages/inbox/


--
http://mail.python.org/mailman/listinfo/python-list


Re: Minions are Python Powered!

2013-08-03 Thread Steven D'Aprano
On Sat, 03 Aug 2013 03:16:09 -0700, Borja Morales wrote:

 Everytime I watched the minions from Despicable Me something was hitting
 my unconscious mind. Finally I figured it out... Minions are Python
 Powered!
 
 I couldn't resist to make an image :)
 
 https://www.dropbox.com/s/t8kaba619vi6q82/
minion_powered_by_python_reality3d.jpg


The Dropbox website requires JavaScript.

Why the hell does some site need to run code in my browser just to 
display a JPEG? That's rubbish.

What's even more rubbish is that Dropbox's 404 Page Not Found tries to 
set a cookie that doesn't expire for FIVE YEARS.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python 'enable' poke and hope programming?

2013-08-03 Thread Wayne Werner

On Thu, 1 Aug 2013, CM wrote:


(My subject line is meant to be tongue and cheek inflammatory)

I've been thinking about why programming for me often feels like ice skating uphill.  I 
think part of the problem, maybe the biggest part, is what now strikes me as a Very Bad 
Habit, which is poke and hope (trial and error) programming (of several names 
this page provided, I kind of like that one):

http://en.wikipedia.org/wiki/Programming_by_permutation

It seems that if I can make a change to the code and then immediately test it by running 
the Python interpreter and finding out, in a few seconds, if it worked, I am going to be 
*much* more likely to use this trial-and-error approach than if I had to use a compiled 
language, since compiling takes so long.  E.g. Oh, that doesn't work?  Maybe if I 
add this...no.  OK, what about if I increment that?  No...OK, wait, maybe this...AH!  
That worked.  (obviously it is not quite that uninformed all the time).

Instead, with a compiled language, because of the pain of having to wait for 
the newest version to compile, one would be encouraged to get the mechanism of 
how something works *clear* and robustly represented in one's mind (or on scrap 
paper/notes document) prior to testing through compiling and running.

Basically this amounts to:  with an interpreted language (so of course this is 
not really just about Python--I just think in terms of Python), it's easier to 
be mentally lazy.  But, ironically, being lazy winds up creating *way* more 
work ultimately, since one winds up programming in this terribly inefficient 
way, and progress proceeds at an, at times, evolutionary (slow!) pace.

And of course I am not really blaming it on Python or any interpreted language; 
I am blaming it fully on my own lame habits and attitude.

I'm sick of this in my own work, and want to avoid this trap as much as I can 
from now on.

Thoughts?



I see that many others have had thoughts already - but rather than take the
time to read their responses and either find out that they said the same thing
(oops, sorry!) or become influenced by their arguments, I feel like I should
respond to this with a clean slate.


I don't think that Python enables the poke and hope style programming (I like
the name!) any more than a compiled language does - if you're doing it right.

Example: My brother had a kid in his C++ class that would go about randomly
flipping , , =, = signs until he got the behavior that he wanted. There was
no mental effort of thinking about the problem or applying the scientific
method - i.e. form a hypothesis, test the hypothesis, check results. My
experience is that people who go throughout their programming careers without
this attitude will do it whether it requires several seconds (or minutes) of
compile time or not. Whether or not it's a conscious choice I don't know - at
least in your case you seem to desire to make a conscious choice in the
direction of wait a minute, this is a stupid way to program.

Though poke and hope is headed in the right direction, I think it's a bit
naive and misses the very essential nature of the better (best?) method -
formulation of a /real/ hypothesis. For instance I think my program will work
is a hypothesis of exactly the same quality of, When I turn on my water
faucet, it will rain. Of course the smaller the application, the more valid
the original hypothesis. For instance, the poke and hope programmer might
write this program:

 x = 3
 if x  3:
 print x is less than 3
 else:
 print x is greater than 3

And then of course make the weak hypothesis if I change my  to  then maybe
my program will work - or if I change my x to 5 then maybe my program will
work.


The problem is that these are really just random guesses - flips of the coin
that eventually might produce a correct result - but only because of the
monkeys[1].

What you really want is to actually understand cause and effect at a more
fundamental level (in programming) than what you may currently enjoy. And this
is in fact something that, while makes it easier for the poke and hope, also
provides a much more enjoyable laboratory experience for the initiated. And
when you combine that with the REPL (interactive interpreter) you get an
embarassingly powerful laboratory in which to experiment to your heart's
delight.

For instance, say you want to really understand the previous example. You could
do something like so:

 x = 3
 x  3
False
 x  3
False
 x = 3
True
 x = 3
True
 x == 3
True


And *this* type of poke and hope *is* actually valuable. This is where
understanding is formed, and high-quality developers are forged. At your
fingertips you begin to see A hah! so *that's what this does! You are free to
explore and play and understand the rules of the system. And you can build on
the previous experiments:


 if x  3:
...  print(Hello?)   #single space indentation for the interpeter
...
 

Re: Logging help

2013-08-03 Thread Wayne Werner

On Thu, 1 Aug 2013, Joseph L. Casale wrote:


I have a couple handlers applied to a logger for a file and console destination.
Default levels have been set for each, INFO+ to console and anything to file.

How does one prevent logging.exception from going to a specific handler when
it falls within the desired levels?



There is probably a better way, I'm not too familiar with the more 
advanced logging, but off the top of my head I'd suggest subclassing the 
Handler classes that you're interested in and overriding the Handle method 
(I think - you can check the source to be sure) and if the type of message 
is exception then just skip handling it.


Alternatively, you could simply create a different logger, e.g.

exc_logger = logging.getLogger('mything.exceptions')


And use that to log exceptions.

Oh hai - as I was reading the documentation, look what I found:

http://docs.python.org/2/library/logging.html#filter

Methinks that should do exactly what you want.

HTH,
W
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python performance

2013-08-03 Thread Wayne Werner

On Fri, 2 Aug 2013, Schneider wrote:


Hi list,

I have to write a small SMTP-Relay script (+ some statistic infos) and 
I'm wondering, if this
can be done in python (in terms of performance, of course not in terms 
of possibility ;) ).


It has to handle around 2000 mails per hour for at least 8hours a day 
(which does not mean, that it is allowed not to respond the rest of 

the day.


Can this be done? or should I better use some other programming language?
My second choice would be erlang.


Check out Kenneth Rietz's inbox.py[1]

It's quite quick. One instance should handle over one thousand emails per 
second.


So it should be able to handle your hour's load in oh, say 2 seconds? ;)

HTH,
W

[1]: https://crate.io/packages/inbox/
--
http://mail.python.org/mailman/listinfo/python-list


Re: Minions are Python Powered!

2013-08-03 Thread mm0fmf

Steven D'Aprano wrote:

On Sat, 03 Aug 2013 03:16:09 -0700, Borja Morales wrote:


Everytime I watched the minions from Despicable Me something was hitting
my unconscious mind. Finally I figured it out... Minions are Python
Powered!

I couldn't resist to make an image :)

https://www.dropbox.com/s/t8kaba619vi6q82/

minion_powered_by_python_reality3d.jpg


The Dropbox website requires JavaScript.

Why the hell does some site need to run code in my browser just to 
display a JPEG? That's rubbish.




Works for me with javascript disabled.
--
http://mail.python.org/mailman/listinfo/python-list


Re: PyArg_ParseTuple() when the type could be anything?

2013-08-03 Thread Stefan Behnel
David M. Cotter, 03.08.2013 02:55:
 I'd like to be able to use PyArg_ParseTuple() in a generic way.
 
 for example, i'd like to have all commands start with 1 integer parameter, 
 and this commandID will inform me of what parameters come next (via LUT).
 
 knowing that i can then call ParseTuple again with the proper parameters.
 
 like this:
 
 if (PyArg_ParseTuple(args, i|, commandID)) {
 
   switch (commandID) {
   
   case cmd_with_str: {
   const char *strZ = NULL;
   
   if (PyArg_ParseTuple(args, is, commandID, strZ)) {
   //  do something with string
   }
   break;
   }
   
   case cmd_with_float: {
   float   valF = -1;
   
   if (PyArg_ParseTuple(args, if, commandID, valF)) {
   //  do something with float
   }
   break;
   }
   }
 }
 
 is there a way to achieve this?  the i| at the start is not working

If you're willing to switch to Cython, here's an (untested) example:

cdef enum:
cmd_with_str = 1
cmd_with_float = 2

cdef int command_id = args[0]
if command_id == cmd_with_str:
str_z = args[1]  # it's an object, so use it as such
print(str_z)
elif command_id == cmd_with_float:
val_f = floatargs[1]   # converting to C float here
...
else:
raise ValueError(unknown command)

Two comments:

1) you can obviously do the same in C, by writing a bit more code. It would
likely be a lot slower, though, and you'd have to take care of error
handling etc.

2) you might want to rethink your design as this is a rather unpythonic
API. Although it depends on who (or what) you are expecting to use it.

Stefan


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 revised: max line lengths

2013-08-03 Thread Chris Angelico
On Sat, Aug 3, 2013 at 3:21 AM, Joshua Landau jos...@landau.ws wrote:
 On 2 August 2013 22:34, Chris Angelico ros...@gmail.com wrote:

 On Fri, Aug 2, 2013 at 10:15 PM,  wxjmfa...@gmail.com wrote:

  Problem #3
  cm or inch? The only serious unit is an SI unit.
  (In scientific publications, only SI units are accepted)

 The cm is not a primary SI unit either.


 But it is an SI unit.

Sorry. Term I should have used is base SI unit. Instead of using the
cm, use the m. Or go three orders of magnitude at a time to the km or
the mm.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re:web development in python without using any webframework

2013-08-03 Thread jj
you could check the codes of flask ,bottle ,web.py to read codes ,the learn 
what you want to know .
 
 




-- Original --
From:  Alok Singh Mahoralokma...@gmail.com;
Date:  Sat, Aug 3, 2013 12:52 PM
To:  python-listpython-list@python.org; 

Subject:  web development in python without using any webframework



Hello everyone,

few months back I started learning python and now I got nice familiarity. now i 
want to use python for creating dynamic database driven websites. and I dont 
want to use existing web frameworks for my work. I am learning things so I wont 
feel lazy to  write all the code myself because I want to learn. 
 

could anyone suggest me any books/site from where I can start. I want to follow 
MVC architecture. so please suggest me some links/book or anything 


thank you in advance-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 revised: max line lengths

2013-08-03 Thread Nicholas Cole
On Friday, 2 August 2013, Chris “Kwpolska” Warrick wrote:

[snip]


 So, what are you feasting for?  Nothing?


I have long since ceased to be amazed at the number of people who would
like their personal and arbitrary preferences, and the rationalisations
that go with them, to be validated and endorsed by others, in law if
possible and in policy documents if not!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PEP8 revised: max line lengths

2013-08-03 Thread Roy Smith
In article mailman.158.1375541014.1251.python-l...@python.org,
 Chris Angelico ros...@gmail.com wrote:

 Sorry. Term I should have used is base SI unit. Instead of using the
 cm, use the m. Or go three orders of magnitude at a time to the km or
 the mm.

Or, go digital, and use Kim (kibimeters).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: LibreOffice

2013-08-03 Thread David Robinow
On Fri, Aug 2, 2013 at 9:26 PM, Terry Reedy tjre...@udel.edu wrote:
 ...
 Of relevance to this list, Libre Office upgraded the included Python
 interpreter to 3.3. I have no idea whether OO is still using 2.3 or also
 updated.
 They're up to 2.7 now.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct Way to Write in Python

2013-08-03 Thread Sagar Varule
On Saturday, August 3, 2013 1:50:41 PM UTC+5:30, Steven D'Aprano wrote:
 On Fri, 02 Aug 2013 23:18:47 -0700, punk.sagar wrote:
 
 
 
  Hi All,
 
  
 
  Im new to Python. Im coming from C# background and want to learn Python.
 
  I was used to do following thing in C# in my previous experiences. I
 
  want to know how do I implement below example in Python. How these
 
  things are done in Python. 
 
 
 
 I am not an expert on C#, but I'll try to translate the following code to 
 
 Python.
 
 
 
 
 
  [code]
 
  public class Bank
 
  {
 
  
 
  public ListCustomer lstCustomers = new ListCustomer();
 
  private string micrcode;
 
  
 
  public void Bank()
 
  {
 
  customer
 
  }
 
  
 
  }
 
  
 
  public class Customer
 
  {
 
  private srting customername;
 
  public string CustomerName
 
 
 
 Do you mean private string rather than private srting?
 
 
 
 
 
  {
 
  get { return customername; }
 
  set { customername = value; }
 
  }
 
  }
 
  
 
  main()
 
  {
 
  Customer objCustomer = new Customer;
 
  objCustomer.CustomerName = XYZ
 
  
 
  Bank objBank = new Bank();
 
  objBank.lstCustomer.Add(objCustomer);
 
  
 
  }
 
  [/code]
 
 
 
 
 
 Here is a literally translation, as best as I can understand the C# code. 
 
 (But note that this is not the best Python code.)
 
 
 
 
 
 class Bank:
 
 def __init__(self):
 
 self.lstCustomers = []  # Empty list of customers.
 
 self._micrcode = ''  # Does this actually get used?
 
 
 
 class Customer:
 
 def __init__(self):
 
 self._customername = ''
 
 
 
 @property
 
 def CustomerName(self):
 
 return self._customername
 
 
 
 @CustomerName.setter
 
 def CustomerName(self, value):
 
 if not instance(value, str):
 
 raise TypeError('names must be strings')
 
 self._customername = value
 
 
 
 
 
 if __name__ == '__main__':
 
 # Running as a script, call the main function.
 
 objCustomer = Customer()
 
 objCustomer.CustomerName = XYZ
 
 
 
 objBank = Bank()
 
 objBank.lstCustomers.append(objCustomer)
 
 
 
 
 
 
 
 But this isn't how I would write it in Python. For starters, our naming 
 
 conventions are different. Everything in Python is an object, even simple 
 
 types like ints and strings, and even classes, so it isn't meaningful to 
 
 prefix instances with obj.
 
 
 
 We tend to avoid anything which even vaguely looks like Hungarian 
 
 Notation, so lstCustomer is right out. Instead, we use plural for 
 
 collections (lists, sets, dicts, whatever) of things, and singular for 
 
 individual instances.
 
 
 
 Also, while we can use the property decorator to make computed 
 
 attributes, we very rarely do just to enforce private/public variables. 
 
 Our philosophy is, if you want to shoot yourself in the foot, we're not 
 
 going to stop you. (People spend far too much time trying to work around 
 
 private names in other languages for Python to spend too much effort in 
 
 this area.) Instead, we have private by convention: names starting with 
 
 a single underscore are private, so don't touch them, and if you do, 
 
 you have nobody but yourself to blame when you shoot yourself in the foot.
 
 
 
 Similarly, the language doesn't spend much time enforcing type 
 
 restrictions. Python is a dynamic language, and type restrictions go 
 
 against that philosophy. If you have a good reason to put a non-string as 
 
 the customer name, you can do so, but don't come crying to me if you 
 
 break your code. So here is how I would write the above:
 
 
 
 
 
 
 
 class Bank:
 
 def __init__(self):
 
 self.customers = []
 
 self._micrcode = ''  # Does this actually get used?
 
 
 
 class Customer:
 
 def __init__(self, name):
 
 # This type-check is optional.
 
 if not instance(name, str):
 
 raise TypeError('names must be strings')
 
 self.name = name
 
 
 
 
 
 if __name__ == '__main__':
 
 # Running as a script, call the main function.
 
 customer = Customer(XYX)
 
 
 
 bank = Bank()
 
 bank.customers.append(customer)
 
 
 
 
 
 The above is still not what I call professional quality -- no doc strings 
 
 (documentation), and the bank doesn't actually do anything, but it's a 
 
 start.
 
 
 
 
 
 -- 
 
 Steven

Thanks Steven for your Time and Effort. You have cleared many doubts and 
concepts for that I was struggling, since I started learning python. But I am 
falling in love for Python. Your explanation for private and public access 
modifier was awesome as I was having harding time finding why we dont have 
access modifier for pythonThanks a lot
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct Way to Write in Python

2013-08-03 Thread Sagar Varule
On Saturday, August 3, 2013 2:34:10 PM UTC+5:30, Peter Otten wrote:
 Sagar Varule wrote:
 
 
 
  On Saturday, August 3, 2013 12:17:49 PM UTC+5:30, Peter Otten wrote:
 
  punk.sa...@gmail.com wrote:
 
 
 
  Thanks a lot Peter. I appreciate your Help. You mentioned that C# code
 
  above is not good. If you can point me why it is not good, would help me
 
  learn new approaches as this type of Code I use to see long back(when i
 
  was fresher). There may be better approaches or concepts i am not aware
 
  of. If you can point me in that direction it would be gr8.
 
 
 
 As I said, I don't know C#  -- but I already tried to fix some of the 
 
 potential issues in my code snippet.
 
 
 
 - A list is not the best choice to store the customers -- there should be a 
 
 lookup by some kind of ID (I picked the name to keep it simple)
 
 - Is it really necessary to expose that container in a language that 
 
 provides privacy?
 
 - Is there ever a customer without name/ID? I'd say no, so these should be 
 
 passed as constructor arguments.
 
 - Renaming a customer is a delicate process, you may need to keep track of 
 
 the old name, the reason for the name, update your database etc., so I 
 
 wouldn't allow setting the attribute and instead add a method
 
 
 
 Bank.rename_customer(...)
 
 
 
 or
 
 
 
 Bank.customers.rename_customer(...)
 
 
 
 Asking to translate code might make sense if you are a wizzard in the 
 
 other language and want to see how a particular construct is written 
 
 idomatically in Python, but to rewrite very basic C# code in Python is a bit 
 
 like trying to learn a natural language by replacing one word after another 
 
 in a text with the word in the new language that you looked up in a dict. 
 
 The result tends to be underwhelming.
 
 
 
 I recommend that you read the tutorial and then try to solve a simple task 
 
 in Python. Whenever you run into a problem you can come here for help. 
 
 Because there's a real problem behind your code there will be different ways 
 
 to solve it in Python, and you'll learn much more about the possibilites 
 
 Python has to offer while your code gradually becomes more idiomatic.

Thanks Peter for helping me out,
Your Questions and suggestions are thoughts provoking and will help me every 
time I write a new Class. I will keep your suggestions. I am happy and amazed 
that Im getting help from strangers, But I got none when I approached 
programmers in my officeThanks a Lot...!

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct Way to Write in Python

2013-08-03 Thread Chris Angelico
On Sat, Aug 3, 2013 at 4:59 PM, Sagar Varule punk.sa...@gmail.com wrote:
 Your explanation for private and public access modifier was awesome as I was 
 having harding time finding why we dont have access modifier for 
 pythonThanks a lot

It's a huge saving in time and effort. The C++ convention is: Make
everything private, then hand-write getters and setters for them all,
just in case you want to put extra code onto them. (I don't know C#
but it seems to be pretty much the same.) The Python convention is:
We're all consenting adults. Make stuff public, then if you need to
add code to something, make a @property that simulates the old
behaviour.

Personally, I've started to adopt the Python style in my C++ code as
well. I use struct instead of class, avoid making anything private,
and document the things that must not be done - for instance, I
created a class that had one particular pointer that must never be
advanced other than by the provided member function, but may be
retarded. No reason to fiddle with member privacy even there.

(The same technique has benefit in a quite different area, too:
separation of code and data. Not in C++, but I have systems that let
me load new code into a running process, and there it's extremely
helpful to just do everything as a simple structure, and then the new
code can slide in and work with the old data structure, happily
extending it with whatever it now needs. Again, everything's public.)

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python performance

2013-08-03 Thread Stefan Behnel
Wayne Werner, 03.08.2013 15:09:
 On Fri, 2 Aug 2013, Schneider wrote:
 I have to write a small SMTP-Relay script (+ some statistic infos) and
 I'm wondering, if this
 can be done in python (in terms of performance, of course not in terms of
 possibility ;) ).

 It has to handle around 2000 mails per hour for at least 8hours a day
 (which does not mean, that it is allowed not to respond the rest of 
 the day.

 Can this be done? or should I better use some other programming language?
 My second choice would be erlang.
 
 Check out Kenneth Rietz's inbox.py[1]
 
 It's quite quick. One instance should handle over one thousand emails per
 second.

Well, this has little to do with Kenneth Reitz. The smtpd implementation is
part of the stdlib in Python. It uses asyncore and asynchat to scale, so
you can generally expect it to be fast enough for the load in question.
Working with asyncore and asynchat isn't the most pleasant that Python can
offer, but given that it's there and has been for years, it should be
pretty ok.

Alternatively, Twisted also has a server+client implementation of SMTP:

https://twistedmatrix.com/trac/wiki/TwistedMail

Haven't used either of the two yet, though, so I can't say which is a
better start for the problem at hand.

Stefan


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Minions are Python Powered!

2013-08-03 Thread CM
On Saturday, August 3, 2013 6:16:09 AM UTC-4, Borja Morales wrote:
 Everytime I watched the minions from Despicable Me something was hitting my 
 unconscious mind. Finally I figured it out... Minions are Python Powered!
 
 
 
 I couldn't resist to make an image :)

I haven't even seen either of those movies (though have seen those characters 
in their advertising) and despite that, upon seeing your image, was unable to 
do anything but smile really hard.  Killer job!  Brightened my day.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python 'enable' poke and hope programming?

2013-08-03 Thread CM
Wayne, thanks for your thoughts.  

I am all for the scientific method--in understanding the natural world, which 
doesn't come with a manual.  But Python is an artificial system designed by 
mere people (as well as Guido), and, as such, does have a manual.  Ideally, 
there should be very little need for experimentation and hypotheses.  That 
said, yes, when learning the language a little experimentation along the way is 
fine, and error messages Python throws back to you or unexpected results can 
and should be a form of real time instruction.

But what I meant is that if one is writing a program, there is a way to 
**know**--without experimentation--what a particular set of code is going to 
do.  This is often cognitively demanding work, but it is possible.  And my 
point is that it is, in the end, far more efficient to be disciplined and do 
that work rather than try to take shortcuts by simply trying a few things until 
one of them works.  

In sum:  experimentation is for when you don't know what you're doing and there 
is no manual; but, after the initial learning time, you *should* know what 
you're doing and you should have the manual handy, and therefore the time for 
experimentation is largely over.



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python 'enable' poke and hope programming?

2013-08-03 Thread Chris Angelico
On Sat, Aug 3, 2013 at 6:30 PM, CM cmpyt...@gmail.com wrote:
 In sum:  experimentation is for when you don't know what you're doing and 
 there is no manual; but, after the initial learning time, you *should* know 
 what you're doing and you should have the manual handy, and therefore the 
 time for experimentation is largely over.


Yet with fast turnaround interactive languages, the interpreter IS
part of the manual. Keeping IDLE (I prefer it to command-line Python
on Windows, as the latter lacks GNU readline ergo no tab completion
etc) handy is at least as useful as keeping the manual up.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Where to suggest improvements in the official Python documentation?

2013-08-03 Thread Aseem Bansal
I have a suggestion about the Python tutorial for improvement. Specifically 
about in Python tutorial 4.7.5 lambda forms.
http://docs.python.org/3/tutorial/controlflow.html#lambda-forms

It is not very clear from the tutorial what lambda forms are for someone who 
doesn't know functional programming. I think placing a link of functional 
Programming HOWTO of Python documentation can take out much confusion for 
Python newbies.

I would like to suggest this because as I newbiw I had much confusion 2 months 
back before I could figure out its proper use. Where do I suggest this 
improvement?
-- 
http://mail.python.org/mailman/listinfo/python-list


Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-03 Thread Aseem Bansal
I was writing a Python script for getting the user stats of a 
website(Specifically codereview.stackexchange). I wanted to store the stats in 
a database. I found Python3's sqlite3 library. I found that I needed sql 
commands for using it.

I have tried sql.learncodethehardway but it isn't complete yet. I tired looking 
on stackoverflow's  sql tag also but nothing much there. Can someone suggest me 
better resources for learning sql/sqlite3? 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where to suggest improvements in the official Python documentation?

2013-08-03 Thread Joel Goldstick
On Sat, Aug 3, 2013 at 1:53 PM, Aseem Bansal asmbans...@gmail.com wrote:
 I have a suggestion about the Python tutorial for improvement. Specifically 
 about in Python tutorial 4.7.5 lambda forms.
 http://docs.python.org/3/tutorial/controlflow.html#lambda-forms

 It is not very clear from the tutorial what lambda forms are for someone who 
 doesn't know functional programming. I think placing a link of functional 
 Programming HOWTO of Python documentation can take out much confusion for 
 Python newbies.

 I would like to suggest this because as I newbiw I had much confusion 2 
 months back before I could figure out its proper use. Where do I suggest this 
 improvement?
 --
 http://mail.python.org/mailman/listinfo/python-list

http://docs.python.org/2/bugs.html

-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-03 Thread Vito De Tullio
Aseem Bansal wrote:

 I have tried sql.learncodethehardway but it isn't complete yet. I tired
 looking on stackoverflow's  sql tag also but nothing much there. Can
 someone suggest me better resources for learning sql/sqlite3?

a start is the sqlite homepage: http://www.sqlite.org/docs.html

-- 
By ZeD

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-03 Thread Joel Goldstick
On Sat, Aug 3, 2013 at 1:57 PM, Aseem Bansal asmbans...@gmail.com wrote:
 I was writing a Python script for getting the user stats of a 
 website(Specifically codereview.stackexchange). I wanted to store the stats 
 in a database. I found Python3's sqlite3 library. I found that I needed sql 
 commands for using it.

 I have tried sql.learncodethehardway but it isn't complete yet. I tired 
 looking on stackoverflow's  sql tag also but nothing much there. Can someone 
 suggest me better resources for learning sql/sqlite3?

Have you tried the sqlite home page at http://www.sqlite.org/


 --
 http://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does Python 'enable' poke and hope programming?

2013-08-03 Thread Ethan Furman

On 08/03/2013 10:30 AM, CM wrote:


But what I meant is that if one is writing a program, there is a way
 to **know**--without experimentation--what a particular set of code
 is going to do.


Even when you /know/, experimenting is still good for two other purposes:

  - check that what you know is so

  - check that the interpreter behaves consistently with the docs

But yes, I otherwise agree with you.

--
~Ethan~
--
http://mail.python.org/mailman/listinfo/python-list


Crawl Quora

2013-08-03 Thread Umesh Sharma
Hello,

I am writing a crawler in python, which crawl quora. I can't read the content 
of quora without login. But google/bing crawls quora. One thing i can do is use 
browser automation and login in my account and the go links by link and crawl 
content, but this method is slow. So can any one tell me how should i start in 
writing this crawler.


Thanks,
Umesh Kumar Sharma
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-03 Thread Cousin Stanley
Aseem Bansal wrote:

 
 Can someone suggest me better resources 
 for learning sql/sqlite3 ?

  http://docs.python.org/3/library/sqlite3.html

  http://wiki.python.org/moin/DbApiCheatSheet

  http://www.w3schools.com/sql/default.asp

  http://www.sqlcourse.com/index.html

  http://sqlite.org/docs.html

  http://zetcode.com/db/sqlite/  
 


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python: Code is ignoring the if and else

2013-08-03 Thread kevin4fong
On Friday, August 2, 2013 10:04:56 PM UTC-7, Terry Reedy wrote:
 On 8/2/2013 10:24 PM, kevin4f...@gmail.com wrote:
 
 
 
 Looking at this again, I believe you actually had the structure almost 
 
 right before. You want to look through *all* of the target players cards 
 
 and if *none* of them match, (ie the search fails), you want to draw 1 
 
 card. What you were missing before is break or return
 
 
 
 def player_0_hitman(hit):
 
   for card in pHands[target_player]:
 
   if target_card[0] == card[0]:
 
   count = pHands[target_player].count(card)
 
   pHands[0].append(card)
 
   pHands[target_player].remove(card)
 
   ShowMessage(HIT:  + str(count) +  card(s) transferred)
 
   return True
 
 
 
# else: needed if just break above, but not with return
 
   
 
top_card = GetTopCard(sDeck)
 
pHands[0].append(top_card)
 
if top_card[0] == target_card[0]:
 
ShowMessage(HIT: LUCKILY Player 0 has fished up a rank  + 
 
 str(top_card[0]) + !!!)
 
return True
 
 else:
 
 ShowMessage(MISS: You fished up the rank  + 
 
 str(top_card[0]) + )
 
 hit = hit - 1
 
 return False
 
 
 
 The returns are based on what I remember of the rules from decades ago, 
 
 that a hit either in the hand or the draw allowed another turn by the 
 
 player.
 
 
 
 -- 
 
 Terry Jan Reedy

Thank you, that information worked quite well and is much appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Removing matching items from a list?

2013-08-03 Thread kevin4fong


Basically, I'm trying to find out how to remove matching items from a list. But 
there doesn't seem to be any information on how to go about doing this specific 
function.

For example, what I want is:

let's say there is a list:

pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']

So up there, my list, which is named pHands[0] has ten items in it.

I'm trying to make a function where a search is initiated into the list and any 
matching items with a first matching number/letter reaching four are removed

So in the end, ad, ac, as, ah (the four a's) will all be deleted/removed from 
the list. I need the list to automatically detect if there are four matching 
first letter/numbers in the items in the list.

The remaining list will be: pHands[0] = ['7d', '8s', '9d', 'td', 'js', 'jd']
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
On Saturday, August 3, 2013 1:12:55 PM UTC-7, kevin...@gmail.com wrote:
 Basically, I'm trying to find out how to remove matching items from a list. 
 But there doesn't seem to be any information on how to go about doing this 
 specific function.
 
 
 
 For example, what I want is:
 
 
 
 let's say there is a list:
 
 
 
 pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
 
 
 
 So up there, my list, which is named pHands[0] has ten items in it.
 
 
 
 I'm trying to make a function where a search is initiated into the list and 
 any matching items with a first matching number/letter reaching four are 
 removed
 
 
 
 So in the end, ad, ac, as, ah (the four a's) will all be deleted/removed from 
 the list. I need the list to automatically detect if there are four matching 
 first letter/numbers in the items in the list.
 
 
 
 The remaining list will be: pHands[0] = ['7d', '8s', '9d', 'td', 'js', 'jd']

Ah, I forgot to mention. This function will be used for other lists to so it 
can't specifically target a and needs to auto search for four matching first 
letters.

If it helps, the two letters/numbers in each item are strung together by the 
following function:

for suite in range(4):
for rank in range(13):
deck.append(rankList[rank]+suitList[suite])

So they can be directly accessed using:
card[0] for the first letter/number
card[1] for the second  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread woooee
Use a dictionary to count the number of times each first letter appears, then 
place any first letters==4 in a list or set and remove any items that have a 
first letter in the list/set (or keep items that are not in the set which is 
probably faster if using list comprehension).


-- 
http://mail.python.org/mailman/listinfo/python-list


Python 2.7.5 incompatible

2013-08-03 Thread sofia prata
I use the Windows 7 and i'm trying to install the Python 2.7.5, even though 
it's working, it says it not compatible. So then, i can't use other programs 
that depend upon the Python like the Google App Engine. What do i do?   
 -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Where to suggest improvements in the official Python documentation?

2013-08-03 Thread Terry Reedy

On 8/3/2013 2:23 PM, Joel Goldstick wrote:

On Sat, Aug 3, 2013 at 1:53 PM, Aseem Bansal asmbans...@gmail.com
wrote:

I have a suggestion about the Python tutorial for improvement.
Specifically about in Python tutorial 4.7.5 lambda forms.
http://docs.python.org/3/tutorial/controlflow.html#lambda-forms

It is not very clear from the tutorial what lambda forms are for


They are mostly for passing a one-use function as an argument to another 
function. The tutorial should say that and give an example.


http://bugs.python.org/issue18646


someone who doesn't know functional programming. I think placing a
link of functional Programming HOWTO of Python documentation can
take out much confusion for Python newbies.


That document is not about lambda. The word 'lambda' does not appear 
until near the end, and some of the current examples violate PEP 8.



I would like to suggest this because as I newbiw I had much
confusion 2 months back before I could figure out its proper use.
Where do I suggest this improvement? --



http://docs.python.org/2/bugs.html


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread Roy Smith
In article 6c0bdea5-23bd-4854-8016-4bf0af3b7...@googlegroups.com,
 kevin4f...@gmail.com wrote:

 let's say there is a list:
 
 pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']

I assume this is a card game, and these are cards (ad = Ace of Diamonds, 
etc).

 I'm trying to make a function where a search is initiated into the list and 
 any matching items with a first matching number/letter reaching four are 
 removed

I'm not quite sure how to parse that, but I think what you're saying 
(using the deck of cards model) is you want to find all the sets of 4 
cards of the same rank.  In the example above, you've got all four aces 
(which, in the wrong saloon, can get you shot).

I think I would do something like:

-
import collections

def remove_four_of_a_kind(hand):
ranks = [card[0] for card in hand]
counts = collections.Counter(ranks)
fours = [rank for rank, count in counts.items() if count == 4]
new_hand = [card for card in hand if card[0] not in fours]
return new_hand

hand = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
print remove_four_of_a_kind(hand)
-

$ python cards.py
['7d', '8s', '9d', 'td', 'js', 'jd']

I just gave a class yesterday where we covered list comprehensions and 
Counters, so maybe I just have comprehensions on the brain today :-)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread MRAB

On 03/08/2013 21:12, kevin4f...@gmail.com wrote:



Basically, I'm trying to find out how to remove matching items from a list. But 
there doesn't seem to be any information on how to go about doing this specific 
function.

For example, what I want is:

let's say there is a list:

pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']

So up there, my list, which is named pHands[0] has ten items in it.

I'm trying to make a function where a search is initiated into the list and any 
matching items with a first matching number/letter reaching four are removed

So in the end, ad, ac, as, ah (the four a's) will all be deleted/removed from 
the list. I need the list to automatically detect if there are four matching 
first letter/numbers in the items in the list.

The remaining list will be: pHands[0] = ['7d', '8s', '9d', 'td', 'js', 'jd']


 hands = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
 from collections import Counter
 counts = Counter(hand[0] for hand in hands)
 counts
Counter({'a': 4, 'j': 2, 't': 1, '7': 1, '9': 1, '8': 1})
 counts.most_common()
[('a', 4), ('j', 2), ('t', 1), ('7', 1), ('9', 1), ('8', 1)]

So there are 4 aces.

 hands = [hand for hand in hands if hand[0] != 'a']
 hands
['7d', '8s', '9d', 'td', 'js', 'jd']

--
http://mail.python.org/mailman/listinfo/python-list


Re: Crawl Quora

2013-08-03 Thread Dave Angel
Umesh Sharma wrote:

 Hello,

 I am writing a crawler in python, which crawl quora. I can't read the content 
 of quora without login. But google/bing crawls quora. One thing i can do is 
 use browser automation and login in my account and the go links by link and 
 crawl content, but this method is slow. So can any one tell me how should i 
 start in writing this crawler.


I had never heard of quora.  And I had to hunt a bit to find a link to
this website.  When you post a question here which refers to a
non-Python site, you really should include a link to it.

You start with reading the page:  http://www.quora.com/about/tos

which you agreed to when you created your account with them.  At one
place it seems pretty clear that unless you make specific arrangements
with Quora, you're limited to using their API.

I suspect that they bend over backwards to get Google and the other big
names to index their stuff.  But that doesn't make it legal for you to
do the same.

In particular, the section labeled Rules makes constraints on
automated crawling.  And so do other parts of the TOS.  Crawling is
permissible, but not scraping.  What's that mean?  I dunno.  Perhaps
scraping is what you're describing above as method is slow.

I'm going to be looking to see what API's they offer, if any.  I'm
creating an account now.

-- 
DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Print word from list

2013-08-03 Thread eschneider92
pie='apple keylime pecan meat pot cherry'
pie.split()

How can I print a word from the list other than this way:  print(pie[0:5])  ?

Thanks in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Print word from list

2013-08-03 Thread Chris Angelico
On Sat, Aug 3, 2013 at 11:17 PM,  eschneide...@comcast.net wrote:
 pie='apple keylime pecan meat pot cherry'
 pie.split()

 How can I print a word from the list other than this way:  print(pie[0:5])  ?

The split() method returns a list, it doesn't change the original string. Try:

pies = pie.split()
print(pie[2])

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Print word from list

2013-08-03 Thread eschneider92
Thanks!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7.5 incompatible

2013-08-03 Thread Steven D'Aprano
Hi Sofia, and welcome!


On Sat, 03 Aug 2013 17:31:03 -0300, sofia prata wrote:

 I use the Windows 7 and i'm trying to install the Python 2.7.5, even
 though it's working, it says it not compatible. So then, i can't use
 other programs that depend upon the Python like the Google App Engine.
 What do i do?

Start by explaining the problem in more detail. We cannot see your 
computer or see what you are doing.

How do you know Python is working? How are you running Python? Explain 
the steps that you use, e.g.:

I go to the Start Menu, choose Python 2.7IDLE, then the IDLE window 
opens. If I type code in IDLE, the code runs correctly.

Or: 

I double-click my program 'test.py', and it runs the way I expect.


Then explain what says Python is not compatible. What did you do to get 
that message?  Where is the error message? Is it in IDLE? In a Windows 
dialog box? Somewhere else?

If this is a Python error, it will almost certainly start with a line 
like:

Traceback (most recent call last)

and continue until an error like 

ImportError
ValueError
TypeError

etc. followed by a message. Please COPY AND PASTE the entire traceback, 
starting from the first line, not just the last. Don't retype from memory 
or summarize it.

If the error is somewhere else, and you cannot copy and paste it, then 
retype it *exactly* unless it is unreasonably long.

If necessary, but only if absolutely necessary, try taking a screenshot 
and posting that here. But 99 times out of 100, you should be able to 
copy and paste the text, or at least re-type it if it is short.

That will do for a start. If any of my instructions are unclear, feel 
free to ask for more help, but remember, more detail is usually better 
than vague comments.


Good luck!


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Print word from list

2013-08-03 Thread Steven D'Aprano
On Sat, 03 Aug 2013 15:17:42 -0700, eschneider92 wrote:

 pie='apple keylime pecan meat pot cherry'

That sets pie to a string containing multiple words.

 pie.split()

This splits pie into individual words, then immediately throws the result 
away, leaving pie still set to a string. Instead, you want to do this:

pie = pie.split()

Now pie will be a list of individual words. You can print the entire list:

print(pie)


or print each word separately:


for filling in pie:
print(filling)


Or pick out one specific filling:


print(pie[2])  # should print 'pecan'


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread Steven D'Aprano
On Sat, 03 Aug 2013 13:12:55 -0700, kevin4fong wrote:

 Basically, I'm trying to find out how to remove matching items from a
 list. But there doesn't seem to be any information on how to go about
 doing this specific function.

The documentation cannot possibly cover every single one of the infinite 
number of things somebody might want to do with Python. Programming is 
about figuring out how to do the things you want from the tools provided 
by the language.


 For example, what I want is:
 
 let's say there is a list:
 
 pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
 
 So up there, my list, which is named pHands[0] has ten items in it.

Ten items? I wouldn't have known that if you didn't say so! *wink*

But seriously... you don't need to repeat obvious things like that. We 
can count as well as you can.

But more importantly, it is irrelevant. Is ten items important to this 
problem? No. What if there were nine, or thirty five, or seven? Would the 
problem of removing matching items change? No, the problem remains the 
same regardless of how many items there are.


 I'm trying to make a function where a search is initiated into the list
 and any matching items with a first matching number/letter reaching four
 are removed

In general, rather than removing items from a list, it is faster and 
safer (less error-prone) to create a new list with the items not removed. 
But either way, when trying to program, start by thinking about how *you* 
would do this task by hand:

1) I would start by counting how many items start with each initial 
letter: in your example I would count those starting with 'a' (4), 
'7' (1), and so on.

2) Then go through those initial letters, and pick out the ones equal to 
4 (or should that be four or more?). In this case, only 'a' is 4 or 
more, but there could be multiple examples, say, 4 'a's and 6 'b's.

3) Then, either delete those items from the original list, *or* make a 
new list with the remaining items. Making a new list is usually better.

Now start turning each step into Python code.

Step 1:

Iterate over each item, grab the first character of that item, and add 
one to a counter.

counts = {}  # Start with an empty dict.
for item in pHands[0]:
c = item[0]  # Grab the first character.
if c in counts:
counts[c] += 1
else:
counts[c] = 1


This sets the counter to 1 the first time each character is seen, 
otherwise increments the counter by 1. There's a ready-made tool for 
doing that:

from collections import Counter
counts = Counter(item[0] for item in pHands[0])

but under the hood, it's essentially doing the same thing as I wrote 
above.


Steps 2 and 3 can be done together:

new_list = []
for item in pHand[0]:
c = item[0]
# Look up the character in the counter.
if counts[c]  4:
new_list.append(item)

pHand[0] = new_list



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread Roy Smith
In article 51fd8635$0$3$c3e8da3$54964...@news.astraweb.com,
 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 2) Then go through those initial letters, and pick out the ones equal to 
 4 (or should that be four or more?).

Assuming my earlier hunch is correct about these being cards in a deck, 
and the a's being aces, I would hope it's not four or more.  See my 
earlier comment about saloons and gunshot wounds.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread Chris Angelico
On Sun, Aug 4, 2013 at 12:06 AM, Roy Smith r...@panix.com wrote:
 In article 51fd8635$0$3$c3e8da3$54964...@news.astraweb.com,
  Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:

 2) Then go through those initial letters, and pick out the ones equal to
 4 (or should that be four or more?).

 Assuming my earlier hunch is correct about these being cards in a deck,
 and the a's being aces, I would hope it's not four or more.  See my
 earlier comment about saloons and gunshot wounds.

Unless he's working with multiple decks. There are plenty of games
played with a double deck. But we did get a peek at his creation code,
which appears to make but a single deck's worth of cards.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.7.5 incompatible

2013-08-03 Thread Terry Reedy

On 8/3/2013 6:32 PM, Steven D'Aprano wrote:

Hi Sofia, and welcome!


On Sat, 03 Aug 2013 17:31:03 -0300, sofia prata wrote:


I use the Windows 7 and i'm trying to install the Python 2.7.5, even
though it's working, it says it not compatible. So then, i can't use
other programs that depend upon the Python like the Google App Engine.
What do i do?


Start by explaining the problem in more detail. We cannot see your
computer or see what you are doing.

How do you know Python is working? How are you running Python? Explain
the steps that you use, e.g.:

I go to the Start Menu, choose Python 2.7IDLE, then the IDLE window
opens. If I type code in IDLE, the code runs correctly.

Or:

I double-click my program 'test.py', and it runs the way I expect.


Then explain what says Python is not compatible. What did you do to get
that message?  Where is the error message? Is it in IDLE? In a Windows
dialog box? Somewhere else?

If this is a Python error, it will almost certainly start with a line
like:

Traceback (most recent call last)

and continue until an error like

ImportError
ValueError
TypeError

etc. followed by a message. Please COPY AND PASTE the entire traceback,
starting from the first line, not just the last. Don't retype from memory
or summarize it.

If the error is somewhere else, and you cannot copy and paste it, then
retype it *exactly* unless it is unreasonably long.

If necessary, but only if absolutely necessary, try taking a screenshot
and posting that here. But 99 times out of 100, you should be able to
copy and paste the text, or at least re-type it if it is short.

That will do for a start. If any of my instructions are unclear, feel
free to ask for more help, but remember, more detail is usually better
than vague comments.


In addition to what Steven said, what did you already have installed 
before you installed 2.7.5.


Here is a guess. You had and still have 2.5 or 2.6 installed as the 
default python. You installed 2.7.5 and left the [x] make this the 
default python box checked. ???


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
On Saturday, August 3, 2013 3:37:41 PM UTC-7, Steven D'Aprano wrote:
 On Sat, 03 Aug 2013 13:12:55 -0700, kevin4fong wrote:
 
 
 
  Basically, I'm trying to find out how to remove matching items from a
 
  list. But there doesn't seem to be any information on how to go about
 
  doing this specific function.
 
 
 
 The documentation cannot possibly cover every single one of the infinite 
 
 number of things somebody might want to do with Python. Programming is 
 
 about figuring out how to do the things you want from the tools provided 
 
 by the language.
 
 
 
 
 
  For example, what I want is:
 
  
 
  let's say there is a list:
 
  
 
  pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
 
  
 
  So up there, my list, which is named pHands[0] has ten items in it.
 
 
 
 Ten items? I wouldn't have known that if you didn't say so! *wink*
 
 
 
 But seriously... you don't need to repeat obvious things like that. We 
 
 can count as well as you can.
 
 
 
 But more importantly, it is irrelevant. Is ten items important to this 
 
 problem? No. What if there were nine, or thirty five, or seven? Would the 
 
 problem of removing matching items change? No, the problem remains the 
 
 same regardless of how many items there are.
 
 
 
 
 
  I'm trying to make a function where a search is initiated into the list
 
  and any matching items with a first matching number/letter reaching four
 
  are removed
 
 
 
 In general, rather than removing items from a list, it is faster and 
 
 safer (less error-prone) to create a new list with the items not removed. 
 
 But either way, when trying to program, start by thinking about how *you* 
 
 would do this task by hand:
 
 
 
 1) I would start by counting how many items start with each initial 
 
 letter: in your example I would count those starting with 'a' (4), 
 
 '7' (1), and so on.
 
 
 
 2) Then go through those initial letters, and pick out the ones equal to 
 
 4 (or should that be four or more?). In this case, only 'a' is 4 or 
 
 more, but there could be multiple examples, say, 4 'a's and 6 'b's.
 
 
 
 3) Then, either delete those items from the original list, *or* make a 
 
 new list with the remaining items. Making a new list is usually better.
 
 
 
 Now start turning each step into Python code.
 
 
 
 Step 1:
 
 
 
 Iterate over each item, grab the first character of that item, and add 
 
 one to a counter.
 
 
 
 counts = {}  # Start with an empty dict.
 
 for item in pHands[0]:
 
 c = item[0]  # Grab the first character.
 
 if c in counts:
 
 counts[c] += 1
 
 else:
 
 counts[c] = 1
 
 
 
 
 
 This sets the counter to 1 the first time each character is seen, 
 
 otherwise increments the counter by 1. There's a ready-made tool for 
 
 doing that:
 
 
 
 from collections import Counter
 
 counts = Counter(item[0] for item in pHands[0])
 
 
 
 but under the hood, it's essentially doing the same thing as I wrote 
 
 above.
 
 
 
 
 
 Steps 2 and 3 can be done together:
 
 
 
 new_list = []
 
 for item in pHand[0]:
 
 c = item[0]
 
 # Look up the character in the counter.
 
 if counts[c]  4:
 
 new_list.append(item)
 
 
 
 pHand[0] = new_list
 
 
 
 
 
 
 
 -- 
 
 Steven

Ah, all of the replies were useful but I found yours the most useful because of 
all the descriptions and in depth steps so I could actually understand what the 
code did. Thank you.

Would you also happen to know how to fit in a simple count for each set of 
cards that is removed?

For example, 4a's gone would set the count to 1 but if there was also 4j's, the 
count would be at 2.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread Steven D'Aprano
On Sat, 03 Aug 2013 19:06:05 -0400, Roy Smith wrote:

 In article 51fd8635$0$3$c3e8da3$54964...@news.astraweb.com,
  Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 
 2) Then go through those initial letters, and pick out the ones equal
 to 4 (or should that be four or more?).
 
 Assuming my earlier hunch is correct about these being cards in a deck,
 and the a's being aces, I would hope it's not four or more.  See my
 earlier comment about saloons and gunshot wounds.

There are card games that involve more than four suits, or more than one 
pack. In principle, if you draw ten cards from an unknown number of 
packs, you could draw ten Aces, or even ten Aces of the same suit. Think 
of playing blackjack with ten packs shuffled together.

Cripple Mr Onion, for example, uses hands of ten cards drawn from eight 
suits:

http://discworld.wikia.com/wiki/Cripple_Mr_Onion

(yes, it's a real game, based on a fictional game)


The Indian Ganjifa deck uses ten houses (decks) of 12 cards each.

Pinochle uses the standard four Western suits, but uses two copies of 
each card 9, 10, J, Q, K, A, for 48 cards in total. Sometimes people 
combine two pinochle decks for larger games, so with a double deck all 
ten cards could be Aces.

In the 1930s, there was a fad for playing Bridge with a fifth suit, 
coloured green, called Royals, Leaves, Eagles or Rooks depending on the 
manufacturer.

There are five- and six-suit versions of poker, with at least two still 
commercially available: the five-suit Stardeck pack (which adds Stars), 
and the six-suit Empire deck (which adds red Crowns and black Anchors).

There is an eight-suit Euchre pack that adds red Moons, black Stars, red 
four-leaf Clovers and black Tears to the standard deck.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
On Saturday, August 3, 2013 3:37:41 PM UTC-7, Steven D'Aprano wrote:
 On Sat, 03 Aug 2013 13:12:55 -0700, kevin4fong wrote:
 
 
 
  Basically, I'm trying to find out how to remove matching items from a
 
  list. But there doesn't seem to be any information on how to go about
 
  doing this specific function.
 
 
 
 The documentation cannot possibly cover every single one of the infinite 
 
 number of things somebody might want to do with Python. Programming is 
 
 about figuring out how to do the things you want from the tools provided 
 
 by the language.
 
 
 
 
 
  For example, what I want is:
 
  
 
  let's say there is a list:
 
  
 
  pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
 
  
 
  So up there, my list, which is named pHands[0] has ten items in it.
 
 
 
 Ten items? I wouldn't have known that if you didn't say so! *wink*
 
 
 
 But seriously... you don't need to repeat obvious things like that. We 
 
 can count as well as you can.
 
 
 
 But more importantly, it is irrelevant. Is ten items important to this 
 
 problem? No. What if there were nine, or thirty five, or seven? Would the 
 
 problem of removing matching items change? No, the problem remains the 
 
 same regardless of how many items there are.
 
 
 
 
 
  I'm trying to make a function where a search is initiated into the list
 
  and any matching items with a first matching number/letter reaching four
 
  are removed
 
 
 
 In general, rather than removing items from a list, it is faster and 
 
 safer (less error-prone) to create a new list with the items not removed. 
 
 But either way, when trying to program, start by thinking about how *you* 
 
 would do this task by hand:
 
 
 
 1) I would start by counting how many items start with each initial 
 
 letter: in your example I would count those starting with 'a' (4), 
 
 '7' (1), and so on.
 
 
 
 2) Then go through those initial letters, and pick out the ones equal to 
 
 4 (or should that be four or more?). In this case, only 'a' is 4 or 
 
 more, but there could be multiple examples, say, 4 'a's and 6 'b's.
 
 
 
 3) Then, either delete those items from the original list, *or* make a 
 
 new list with the remaining items. Making a new list is usually better.
 
 
 
 Now start turning each step into Python code.
 
 
 
 Step 1:
 
 
 
 Iterate over each item, grab the first character of that item, and add 
 
 one to a counter.
 
 
 
 counts = {}  # Start with an empty dict.
 
 for item in pHands[0]:
 
 c = item[0]  # Grab the first character.
 
 if c in counts:
 
 counts[c] += 1
 
 else:
 
 counts[c] = 1
 
 
 
 
 
 This sets the counter to 1 the first time each character is seen, 
 
 otherwise increments the counter by 1. There's a ready-made tool for 
 
 doing that:
 
 
 
 from collections import Counter
 
 counts = Counter(item[0] for item in pHands[0])
 
 
 
 but under the hood, it's essentially doing the same thing as I wrote 
 
 above.
 
 
 
 
 
 Steps 2 and 3 can be done together:
 
 
 
 new_list = []
 
 for item in pHand[0]:
 
 c = item[0]
 
 # Look up the character in the counter.
 
 if counts[c]  4:
 
 new_list.append(item)
 
 
 
 pHand[0] = new_list
 
 
 
 
 
 
 
 -- 
 
 Steven

Thank you. I found all the replies useful but yours the most useful because of 
the descriptions and indepth steps so I could understand what the code did.

Would you also happen to know how I could go about setting up a list that keeps 
track of the removed sets?

For example, if there were 4 a's removed, that would be one set. And the list 
would be:

['a']

but if there was also 4j's in addition to the a's. It would be:

['a', 'j']

And so forth
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
On Saturday, August 3, 2013 3:37:41 PM UTC-7, Steven D'Aprano wrote:
 On Sat, 03 Aug 2013 13:12:55 -0700, kevin4fong wrote:
 
 
 
  Basically, I'm trying to find out how to remove matching items from a
 
  list. But there doesn't seem to be any information on how to go about
 
  doing this specific function.
 
 
 
 The documentation cannot possibly cover every single one of the infinite 
 
 number of things somebody might want to do with Python. Programming is 
 
 about figuring out how to do the things you want from the tools provided 
 
 by the language.
 
 
 
 
 
  For example, what I want is:
 
  
 
  let's say there is a list:
 
  
 
  pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
 
  
 
  So up there, my list, which is named pHands[0] has ten items in it.
 
 
 
 Ten items? I wouldn't have known that if you didn't say so! *wink*
 
 
 
 But seriously... you don't need to repeat obvious things like that. We 
 
 can count as well as you can.
 
 
 
 But more importantly, it is irrelevant. Is ten items important to this 
 
 problem? No. What if there were nine, or thirty five, or seven? Would the 
 
 problem of removing matching items change? No, the problem remains the 
 
 same regardless of how many items there are.
 
 
 
 
 
  I'm trying to make a function where a search is initiated into the list
 
  and any matching items with a first matching number/letter reaching four
 
  are removed
 
 
 
 In general, rather than removing items from a list, it is faster and 
 
 safer (less error-prone) to create a new list with the items not removed. 
 
 But either way, when trying to program, start by thinking about how *you* 
 
 would do this task by hand:
 
 
 
 1) I would start by counting how many items start with each initial 
 
 letter: in your example I would count those starting with 'a' (4), 
 
 '7' (1), and so on.
 
 
 
 2) Then go through those initial letters, and pick out the ones equal to 
 
 4 (or should that be four or more?). In this case, only 'a' is 4 or 
 
 more, but there could be multiple examples, say, 4 'a's and 6 'b's.
 
 
 
 3) Then, either delete those items from the original list, *or* make a 
 
 new list with the remaining items. Making a new list is usually better.
 
 
 
 Now start turning each step into Python code.
 
 
 
 Step 1:
 
 
 
 Iterate over each item, grab the first character of that item, and add 
 
 one to a counter.
 
 
 
 counts = {}  # Start with an empty dict.
 
 for item in pHands[0]:
 
 c = item[0]  # Grab the first character.
 
 if c in counts:
 
 counts[c] += 1
 
 else:
 
 counts[c] = 1
 
 
 
 
 
 This sets the counter to 1 the first time each character is seen, 
 
 otherwise increments the counter by 1. There's a ready-made tool for 
 
 doing that:
 
 
 
 from collections import Counter
 
 counts = Counter(item[0] for item in pHands[0])
 
 
 
 but under the hood, it's essentially doing the same thing as I wrote 
 
 above.
 
 
 
 
 
 Steps 2 and 3 can be done together:
 
 
 
 new_list = []
 
 for item in pHand[0]:
 
 c = item[0]
 
 # Look up the character in the counter.
 
 if counts[c]  4:
 
 new_list.append(item)
 
 
 
 pHand[0] = new_list
 
 
 
 
 
 
 
 -- 
 
 Steven

Thank you for the advice. It was really helpful with the descriptions and steps.

Would you also happen to know how I could set up a list that keeps track of the 
removed sets?

Let's say there's 4 a's taken out. The list would show:

['a']

But if there was also 4 j's in addition to the 4 a's, it would go:

['a', 'j']

and so forth. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
On Saturday, August 3, 2013 1:12:55 PM UTC-7, kevin...@gmail.com wrote:
 Basically, I'm trying to find out how to remove matching items from a list. 
 But there doesn't seem to be any information on how to go about doing this 
 specific function.
 
 
 
 For example, what I want is:
 
 
 
 let's say there is a list:
 
 
 
 pHands[0] = ['ad', 'ac', 'as', 'ah', '7d', '8s', '9d', 'td', 'js', 'jd']
 
 
 
 So up there, my list, which is named pHands[0] has ten items in it.
 
 
 
 I'm trying to make a function where a search is initiated into the list and 
 any matching items with a first matching number/letter reaching four are 
 removed
 
 
 
 So in the end, ad, ac, as, ah (the four a's) will all be deleted/removed from 
 the list. I need the list to automatically detect if there are four matching 
 first letter/numbers in the items in the list.
 
 
 
 The remaining list will be: pHands[0] = ['7d', '8s', '9d', 'td', 'js', 'jd']


Thank you for the advice. It was really helpful with the descriptions and steps.

Would you also happen to know how I could set up a list that keeps track of the 
removed sets?

Let's say there's 4 a's taken out. The list would show:

['a']

But if there was also 4 j's in addition to the 4 a's, it would go:

['a', 'j']

and so forth. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
On Saturday, August 3, 2013 5:25:16 PM UTC-7, Steven D'Aprano wrote:
 On Sat, 03 Aug 2013 19:06:05 -0400, Roy Smith wrote:
 
 
 
  In article 51fd8635$0$3$c3e8da3$54964...@news.astraweb.com,
 
   Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote:
 
  
 
  2) Then go through those initial letters, and pick out the ones equal
 
  to 4 (or should that be four or more?).
 
  
 
  Assuming my earlier hunch is correct about these being cards in a deck,
 
  and the a's being aces, I would hope it's not four or more.  See my
 
  earlier comment about saloons and gunshot wounds.
 
 
 
 There are card games that involve more than four suits, or more than one 
 
 pack. In principle, if you draw ten cards from an unknown number of 
 
 packs, you could draw ten Aces, or even ten Aces of the same suit. Think 
 
 of playing blackjack with ten packs shuffled together.
 
 
 
 Cripple Mr Onion, for example, uses hands of ten cards drawn from eight 
 
 suits:
 
 
 
 http://discworld.wikia.com/wiki/Cripple_Mr_Onion
 
 
 
 (yes, it's a real game, based on a fictional game)
 
 
 
 
 
 The Indian Ganjifa deck uses ten houses (decks) of 12 cards each.
 
 
 
 Pinochle uses the standard four Western suits, but uses two copies of 
 
 each card 9, 10, J, Q, K, A, for 48 cards in total. Sometimes people 
 
 combine two pinochle decks for larger games, so with a double deck all 
 
 ten cards could be Aces.
 
 
 
 In the 1930s, there was a fad for playing Bridge with a fifth suit, 
 
 coloured green, called Royals, Leaves, Eagles or Rooks depending on the 
 
 manufacturer.
 
 
 
 There are five- and six-suit versions of poker, with at least two still 
 
 commercially available: the five-suit Stardeck pack (which adds Stars), 
 
 and the six-suit Empire deck (which adds red Crowns and black Anchors).
 
 
 
 There is an eight-suit Euchre pack that adds red Moons, black Stars, red 
 
 four-leaf Clovers and black Tears to the standard deck.
 
 
 
 
 
 
 
 -- 
 
 Steven


Thank you for the advice. It was really helpful with the descriptions and steps.

Would you also happen to know how I could set up a list that keeps track of the 
removed sets?

Let's say there's 4 a's taken out. The list would show:

['a']

But if there was also 4 j's in addition to the 4 a's, it would go:

['a', 'j']

and so forth. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
Thank you, Steven, for the advice. It was really helpful with the descriptions 
and steps.

Would you also happen to know how I could set up a list that keeps track of the 
removed sets?

Let's say there's 4 a's taken out. The list would show:

['a']

But if there was also 4 j's in addition to the 4 a's, it would go:

['a', 'j']

and so forth. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread Steven D'Aprano
On Sat, 03 Aug 2013 17:29:28 -0700, kevin4fong wrote:

 Would you also happen to know how I could go about setting up a list
 that keeps track of the removed sets?
 
 For example, if there were 4 a's removed, that would be one set. And the
 list would be:
 
 ['a']
 
 but if there was also 4j's in addition to the a's. It would be:
 
 ['a', 'j']
 
 And so forth


How would *you* do it in person? Start with that, then turn it into 
Python code.

For example, you might count the cards first, as in my previous post, 
then look at each counter. If the counter is four (or greater), add it to 
a list of cards to be removed.

# counter is a dict like {'a': 4, '7': 1} as per previous post
cards_to_remove = []
for card in counter:
if counter[card] = 4:
cards_to_remove.append(card)


Or you could do this at the same time as you build the counter. I leave 
it to you to work out how to do that.

The important thing is, you have to start by asking the question, How 
would I do this task? before you can write Python code for it. 



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
I have no idea why but I'm unable to post in my original thread so I made a new 
one here.


Thank you for the advice, everyone, especially Steven. It was really helpful 
with the descriptions and steps.

Would you also happen to know how I could set up a list that keeps track of the 
removed sets?

Let's say there's 4 a's taken out. The list would show:

['a']

But if there was also 4 j's in addition to the 4 a's, it would go:

['a', 'j']

and so forth. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread kevin4fong
On Saturday, August 3, 2013 5:36:42 PM UTC-7, kevin...@gmail.com wrote:
 I have no idea why but I'm unable to post in my original thread so I made a 
 new one here.
 
 
 
 
 
 Thank you for the advice, everyone, especially Steven. It was really helpful 
 with the descriptions and steps.
 
 
 
 Would you also happen to know how I could set up a list that keeps track of 
 the removed sets?
 
 
 
 Let's say there's 4 a's taken out. The list would show:
 
 
 
 ['a']
 
 
 
 But if there was also 4 j's in addition to the 4 a's, it would go:
 
 
 
 ['a', 'j']
 
 
 
 and so forth.

Sorry for the repeated messages. I have no idea why I have such a long time 
delay. My messages didn't appear until just now after a few minutes (thought I 
was having some issues).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-03 Thread CM
ave tried sql.learncodethehardway but it isn't complete yet. I tired looking on 
stackoverflow's  sql tag also but nothing much there. Can someone suggest me 
better resources for learning sql/sqlite3?

There are a lot of nice small tutorials out there found by Googling.  One 
resource that you might not find easily, though, and that helped me a while 
back and I liked is:

http://sqlzoo.net/howto/source/u.cgi/tip241028/sqlite

The thing about that page is, if you go to the main site, sqlzoo.net, it seems 
that SQLite is no longer one of the options.  But if you go through the link I 
gave above, you can find the older site that does treat SQLite.  To find the 
other command examples, I guess use Google like so:

sqlite zoo INSERT
sqlite zoo UPDATE

and others.  I don't know why SQLite was dropped from the Zoo's roster; I 
really liked that format.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-08-03 Thread Kevin Walzer

On 8/1/13 10:15 AM, Gilles wrote:

I already have a static IP, so the issue is more that remote MTAs
might not accept connections from MTAs running on users' PC instead of
ISP's.


For what it's worth, that hasn't been my experience.

--
Kevin Walzer
Code by Kevin/Mobile Code by Kevin
http://www.codebykevin.com
http://www.wtmobilesoftware.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: Removing matching items from a list?

2013-08-03 Thread Dave Angel
kevin4f...@gmail.com wrote:
 snip

 Would you also happen to know how I could set up a list that keeps track of 
 the removed sets?


Let's see, i think that makes 5 times you've asked the same question,
counting the dups you apparently sent to the same person.

Instead of writing all these messages, could you perhaps actually write
some code?  Show us that you've learned something, and that you actually
tried to get the next answer?

Frame your question around one of the following scenarios:

Here's some code I wrote, and it doesn't work because:

  1) it gets an exception (show full traceback)
  2) it hangs
  3) it gets this answer:  show actual answer
  instead of what I expected:  show what you expected to get

And when you post the code, paste it into your message, don't point to
some temporary website.

And if you must use googlegroups, please edit your messages to hide the
bugs in googlegarbage.  Go into the message and tediously delete all the
stupid extra blank lines, because one person doing it is better than
1000 people seeing double-spaced nonsense.  Many people just won't see a
message sent from googlegroups because they filter them out.


-- 
DaveA


-- 
http://mail.python.org/mailman/listinfo/python-list


[argparse] mutually exclusive group with 2 sets of options

2013-08-03 Thread Francois Lafont
Hi,

Is it possible with argparse to have this syntax for a script?

my-script (-a -b VALUE-B | -c -d VALUE-D)

I would like to do this with the argparse module.

Thanks in advance.


-- 
François Lafont
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue18521] [cppcheck] Full report

2013-08-03 Thread Julien Nabet

Julien Nabet added the comment:

Thank you for your feedback, you can close this tracker.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18521
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18606] Add statistics module to standard library

2013-08-03 Thread Steven D'Aprano

Steven D'Aprano added the comment:

On 03/08/13 13:02, Alexander Belopolsky wrote:

 Alexander Belopolsky added the comment:

 Is there a reason why there is no review link?  Could it be because the 
 file is uploaded as is rather than as a patch?

I cannot answer that question, sorry.

 In any case, I have a question about this code in sum:

  # Convert running total to a float. See comment below for
  # why we do it this way.
  total = type(total).__float__(total)

 The comment below says:

  # Don't call float() directly, as that converts strings and we
  # don't want that. Also, like all dunder methods, we should call
  # __float__ on the class, not the instance.
  x = type(x).__float__(x)

 but this reason does not apply to total that cannot be a string unless you 
 add instances of a really weird class in which case all bets are off and the 
 dunder method won't help much.

My reasoning was that total may be a string if the start parameter is a string, 
but of course I explicitly check the type of start. So I think you are right.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18606
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18595] zipfile: symlinks etc.

2013-08-03 Thread Ronald Oussoren

Ronald Oussoren added the comment:

My initial plan was to add the patch soon after filing the issue, but that's 
before I noticed that this needs some API design to integrate nicely :-)

My current idea for the api:

* add symlink(path, target) to write a symlink

* add readlink(path) to read a symlink

* read will raise an exception when trying to read a symlink
  (alternative: do symlink resolving, but that's too magical to my taste)
 
* extract and extractall extract the symlink as a symlink
  (but I'm not sure yet what to do on systems that don't support symlinks)

* with the various file types it might be better to also provide
  islink(name), isdir(name) and isfile(name) methods (simular to
  their os.path equivalents)

This will also require some changes to the ZipInfo class.

I'm not sure yet if adding support for device files and other unix attributes 
(UID/GID).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18595
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18606] Add statistics module to standard library

2013-08-03 Thread Vajrasky Kok

Vajrasky Kok added the comment:

Is there a reason why there is no 'review' link?  Could it be because the file 
is uploaded as is rather than as a patch?

I think I can answer this question. The answer is yes. You can have review 
only if you use diff not raw file.

The original poster, Steven D'Aprano, uploaded the raw file instead of diff. To 
upload the new file as a diff, (assuming he is using mercurial) he can do 
something like this:

hg add Lib/statistics.py
hg diff Lib/statistics.py  /tmp/statistics_diff.patch

Then he can upload the statistics_diff.patch.

Of course, this is just my hypothetical guess.

--
nosy: +vajrasky

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18606
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16463] testConnectTimeout of test_timeout TCPTimeoutTestCasefailures fails intermittently

2013-08-03 Thread koobs

Changes by koobs koobs.free...@gmail.com:


--
nosy: +koobs

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16463
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18566] In unittest.TestCase docs for setUp() and tearDown() don't mention AssertionError

2013-08-03 Thread Phil Connell

Changes by Phil Connell pconn...@gmail.com:


--
nosy: +pconnell

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18566
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18594] C accelerator for collections.Counter is slow

2013-08-03 Thread Phil Connell

Changes by Phil Connell pconn...@gmail.com:


--
nosy: +pconnell

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18594
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue11798] Test cases not garbage collected after run

2013-08-03 Thread Jean-Paul Calderone

Changes by Jean-Paul Calderone exar...@twistedmatrix.com:


--
nosy:  -exarkun

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue11798
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18532] hashlib.HASH objects should officially expose the hash name

2013-08-03 Thread Jason R. Coombs

Jason R. Coombs added the comment:

It's not obvious to me if the authors originally intended to have the 'name' 
attribute as a formal interface, so I've decided the change should probably be 
added to Python 3.4. Here's a diff I've put together: 
http://paste.jaraco.com/tMdQ2

It updates the documentation and adds a test to guarantee the interface. I'm 
unsure about the RST syntax, so I would appreciate a review of the syntax 
there. Also, I haven't run the test yet, but I'll do that at a later date.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18532
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18532] hashlib.HASH objects should officially expose the hash name

2013-08-03 Thread Jason R. Coombs

Changes by Jason R. Coombs jar...@jaraco.com:


--
keywords: +needs review
stage: needs patch - patch review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18532
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16853] add a Selector to the select module

2013-08-03 Thread Charles-François Natali

Charles-François Natali added the comment:

 Guido van Rossum added the comment:
 Can you try again with the failing assert replaced with this?

   self.assertTrue(0.018 = t2-t0 = 0.028, t2-t0)

 That should be a better way to check that code works.

I'm still getting - less frequent - failures:

==
FAIL: test_run_until_complete_timeout (events_test.SelectEventLoopTests)
--
Traceback (most recent call last):
  File tests/events_test.py, line 194, in test_run_until_complete_timeout
self.assertTrue(0.018 = t2-t0 = 0.028, t2-t0)
AssertionError: False is not true : 0.029771103999337356

--


Looking at strace output:
11:00:47.383145 select(4, [3], [], [], {0, 9765}) = 0 (Timeout) 0.015713

select() takes an extra 5ms (15ms instead of 10ms).

5ms is quite low for a GPOS (the typical quantum is around 4ms for
250Hz timer, and on my machine I have high-resolution timers
configured but probably a crappy hardware).

I'd suggest increasing the timeouts (especially when Tulip gets
merged, it'll likely fail on many buildbots).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16853
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10897] UNIX mmap unnecessarily dup() file descriptor

2013-08-03 Thread Charles-François Natali

Charles-François Natali added the comment:

 This can only be raised (above the hard limit) by a privileged
 process, so I would be out of luck there, as I could not convince
 my sysadmins to raise this further.

We all know that feeling :-)

 Meanwhile, I will just use my own module, so feel free to close
 this if you feel like it :)

OK, I'll close it then, since I don't see any satisfactory solution, and - 
until now - you've been the only user to get bitten.

Cheers.

--
resolution:  - wont fix
stage: patch review - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10897
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16463] testConnectTimeout of test_timeout TCPTimeoutTestCasefailures fails intermittently

2013-08-03 Thread Charles-François Natali

Charles-François Natali added the comment:

The problem is that the test passes a DNS address to connect(), which means 
that it has to perform a name resolution first.
And since there's not timeout on gethostbyname()/getaddrinfo() you can end up 
well above the timeout.
The hostnames should be resolved beforehand.

--
nosy: +neologix

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16463
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18629] future division breaks timedelta division by integer

2013-08-03 Thread Marc-Andre Lemburg

Marc-Andre Lemburg added the comment:

On 03.08.2013 00:47, Alexander Belopolsky wrote:
 
 Alexander Belopolsky added the comment:
 
 Does a result of one and one half seconds make sense as the result of a 
 floor division operation?
 
 Yes.  Timedeltas behave as integers containing the number of microseconds:
 
 timedelta(microseconds=1) / 2
 datetime.timedelta(0)

I think that's a very obscure interpretation of floor division for
timedeltas :-)

IMO, floor division result should work on seconds, not microseconds.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18629
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18629] future division breaks timedelta division by integer

2013-08-03 Thread Mark Dickinson

Mark Dickinson added the comment:

 I think that's a very obscure interpretation of floor division for
 timedeltas :-)

Agreed.

--
nosy: +mark.dickinson

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18629
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18570] OverflowError in division: wrong message

2013-08-03 Thread Mark Dickinson

Mark Dickinson added the comment:

Exception message fixed in revision dab7d6f33b87

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18570
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16463] testConnectTimeout of test_timeout TCPTimeoutTestCasefailures fails intermittently

2013-08-03 Thread Charles-François Natali

Charles-François Natali added the comment:

And here's a patch.

--
keywords: +patch
Added file: http://bugs.python.org/file31137/connect_timeout.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16463
___diff -r 1287d4c9cd39 Lib/test/test_timeout.py
--- a/Lib/test/test_timeout.py  Fri Aug 02 10:22:07 2013 +0200
+++ b/Lib/test/test_timeout.py  Sat Aug 03 13:19:24 2013 +0200
@@ -126,13 +126,23 @@
 self.assertLess(delta, timeout + self.fuzz)
 self.assertGreater(delta, timeout - 1.0)
 
+def resolve_address(self, host, port):
+Resolve an (host, port) to an address.
+
+We must perform name resolution before timeout tests, otherwise it will
+be performed by connect().
+
+with support.transient_internet(host):
+return socket.getaddrinfo(host, port, socket.AF_INET,
+  socket.SOCK_STREAM)[0][4]
+
 
 class TCPTimeoutTestCase(TimeoutTestCase):
 TCP test case for socket.socket() timeout functions
 
 def setUp(self):
 self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
-self.addr_remote = ('www.python.org.', 80)
+self.addr_remote = self.resolve_address('www.python.org.', 80)
 
 def tearDown(self):
 self.sock.close()
@@ -142,7 +152,7 @@
 # to a host that silently drops our packets.  We can't simulate this
 # from Python because it's a function of the underlying TCP/IP stack.
 # So, the following Snakebite host has been defined:
-blackhole = ('blackhole.snakebite.net', 5)
+blackhole = self.resolve_address('blackhole.snakebite.net', 5)
 
 # Blackhole has been configured to silently drop any incoming packets.
 # No RSTs (for TCP) or ICMP UNREACH (for UDP/ICMP) will be sent back
@@ -154,7 +164,7 @@
 # to firewalling or general network configuration.  In order to improve
 # our confidence in testing the blackhole, a corresponding 'whitehole'
 # has also been set up using one port higher:
-whitehole = ('whitehole.snakebite.net', 56667)
+whitehole = self.resolve_address('whitehole.snakebite.net', 56667)
 
 # This address has been configured to immediately drop any incoming
 # packets as well, but it does it respectfully with regards to the
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18642] enhancement for operator 'assert'

2013-08-03 Thread Al Korgun

New submission from Al Korgun:

It would be pretty good, if 'assert' could raise specified exception, like that:

 data = None
 assert isinstance(data, basestring), TypeError('data' must be a string)

sAssertionError/sTypeError: 'data' must be a string

--
components: Interpreter Core
messages: 194250
nosy: WitcherGeralt
priority: normal
severity: normal
status: open
title: enhancement for operator 'assert'
type: enhancement
versions: Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18642
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18642] enhancement for operator 'assert'

2013-08-03 Thread Mark Dickinson

Mark Dickinson added the comment:

What's wrong with:

if not isinstance(data, basestring):
raise TypeError(...)

?

In any case, you appear to be wanting to use assert to check user input.  
That's not its intended use;  instead, it's there for making debugging 
assertions.  Bear in mind that when running in optimized mode (with python -O), 
Python won't execute those asserts at all.  (See 
http://docs.python.org/3.4/reference/simple_stmts.html#the-assert-statement for 
more.)

I think this should be rejected.

--
nosy: +mark.dickinson
versions: +Python 3.4 -Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18642
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18643] implement socketpair() on Windows

2013-08-03 Thread Charles-François Natali

New submission from Charles-François Natali:

socketpair() is quite useful, notably for tests.
Currently, it's not defined on Windows.
Since it's rather easy to implement, it would be nice to have it, if not in the 
stdlib, at least in test.support.

--
components: Library (Lib)
messages: 194252
nosy: neologix, sbt
priority: normal
severity: normal
stage: needs patch
status: open
title: implement socketpair() on Windows
type: enhancement

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18643
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18396] test_signal.test_issue9324() fails on buildbot AMD64 Windows7 SP1 3.x

2013-08-03 Thread Nick Coghlan

Nick Coghlan added the comment:

I checked the getsignal docs, and indeed None is the expected return value for 
signal handler exists, but was not installed from Python. That's accurate 
given the way faulthandler works:

On Linux (Python 3.3.0):

$ python3 -c import signal; print(signal.getsignal(signal.SIGSEGV))
0
$ python3 -X faulthandler -c import signal; 
print(signal.getsignal(signal.SIGSEGV))
None

So Jeremy's patch looks correct to me - when faulthandler is enabled, we need 
to skip over the signals that have those handlers attached.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18396
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18635] Enum sets _member_type_ to instantiated values but not the class

2013-08-03 Thread Chris Lambacher

Chris Lambacher added the comment:

My use case is a generic mixin for Enums and a generic mixin for Django ORM 
fields that uses the Enums to generate choices. 

The Enum mixin has to call cls.__class__._get_mixins_(cls.__bases__) to get the 
member_type so that it can call the member_type.__new__ method (currently using 
this for int and str). I'm currently setting _member_type_ on the class if it 
doesn't already exist in the Enum class.

The Django ORM field mixin has a to_python method where it is supposed to take 
input from the db/web and turn it into the python type (in this case an Enum). 
If we get a str from the web and we are going to an int, we need to run int on 
it. The generic way to do this in the mixin is to pass the value to 
_member_type_ as a function.

I think I have all the bugs out of my implementation so I should be able to 
extract it out of my app and make it open source this week.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18635
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18396] test_signal.test_issue9324() fails on buildbot AMD64 Windows7 SP1 3.x

2013-08-03 Thread Roundup Robot

Roundup Robot added the comment:

New changeset b7834800562f by Nick Coghlan in branch '3.3':
Close #18396: fix spurious test_signal failure on Windows
http://hg.python.org/cpython/rev/b7834800562f

New changeset 6fc71ed6a910 by Nick Coghlan in branch 'default':
Merge #18396 from 3.3
http://hg.python.org/cpython/rev/6fc71ed6a910

--
nosy: +python-dev
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18396
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18396] test_signal.test_issue9324() fails on buildbot AMD64 Windows7 SP1 3.x

2013-08-03 Thread Nick Coghlan

Nick Coghlan added the comment:

I added one slight tweak to Jeremy's patch - an assertion to ensure that test 
loop is checking at least some* signals, even when faulthandler is enabled.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18396
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18642] enhancement for operator 'assert'

2013-08-03 Thread Al Korgun

Al Korgun added the comment:

Mark Dickinson, and I just think it might be useful in debug. PYO is another 
story.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18642
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15233] atexit: guarantee order of execution of registered functions?

2013-08-03 Thread Charles-François Natali

Charles-François Natali added the comment:

Unless anyone objects, I'll backport it soonish.

--
stage:  - commit review

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15233
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue12015] possible characters in temporary file name is too few

2013-08-03 Thread Charles-François Natali

Changes by Charles-François Natali cf.nat...@gmail.com:


--
keywords: +easy, needs review
stage:  - patch review
type:  - enhancement
versions: +Python 3.4 -Python 3.3

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue12015
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18642] enhancement for operator 'assert'

2013-08-03 Thread Mark Dickinson

Mark Dickinson added the comment:

Ah, so I think I don't understand the proposal.  In your original message,  is 
it your intention that the assert raises TypeError, or that it raises 
AssertionError?

Again:  what's the benefit over existing solutions?  Either:

if not isinstance(data, basestring):
raise TypeError(Bad user!  You gave me the wrong type)

or

assert isinstance(data, basestring), data should be a string at this point

?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18642
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-03 Thread Vajrasky Kok

New submission from Vajrasky Kok:

This python is compiled with --with-pydebug option.

[sky@localhost cpython]$ cat /tmp/a.txt
manly man likes cute cat.
[sky@localhost cpython]$ ./python
Python 3.4.0a0 (default:e408e821d6c8, Jul 27 2013, 10:49:54) 
[GCC 4.7.2 20121109 (Red Hat 4.7.2-8)] on linux
Type help, copyright, credits or license for more information.
 from formatter import test
 test('/tmp/a.txt')
manly man likes cute cat.
__main__:1: ResourceWarning: unclosed file _io.TextIOWrapper name='/tmp/a.txt' 
mode='r' encoding='UTF-8'
 
[sky@localhost cpython]$ ./python Lib/formatter.py /tmp/a.txt
manly man likes cute cat.
Lib/formatter.py:445: ResourceWarning: unclosed file _io.TextIOWrapper 
name='/tmp/a.txt' mode='r' encoding='UTF-8'
  test()

--
components: Tests
files: formatter_fix_resource_warning.patch
keywords: patch
messages: 194260
nosy: vajrasky
priority: normal
severity: normal
status: open
title: Got ResourceWarning: unclosed file when using test function from 
formatter module
type: resource usage
versions: Python 3.4
Added file: 
http://bugs.python.org/file31138/formatter_fix_resource_warning.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18644
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-03 Thread Vajrasky Kok

Vajrasky Kok added the comment:

Sorry, I forgot about stdin. Attached the patch to handle stdin gracefully.

--
Added file: 
http://bugs.python.org/file31139/formatter_fix_resource_warning_v2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18644
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-03 Thread Vajrasky Kok

Vajrasky Kok added the comment:

I guess I should not close stdin just in case people are using test function in 
the script.

Attached the patch to only close the open files not stdin.

--
Added file: 
http://bugs.python.org/file31140/formatter_fix_resource_warning_v3.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18644
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18642] enhancement for operator 'assert'

2013-08-03 Thread R. David Murray

R. David Murray added the comment:

I think it would be confusing for assert to raise anything other than an 
AssertionError, so I also think this should be rejected.

It might be interesting for there to be a way to call unittest's assert methods 
in a debug context (that is, without having to have a test case around), but 
that is a very non-trivial (and probably impractical) thought :)

--
nosy: +r.david.murray

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18642
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18595] zipfile: symlinks etc.

2013-08-03 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 * read will raise an exception when trying to read a symlink
  (alternative: do symlink resolving, but that's too magical to my taste)

And perhaps when trying to read a directory entry too.

 * extract and extractall extract the symlink as a symlink
  (but I'm not sure yet what to do on systems that don't support symlinks)

What the tar module do?

 * with the various file types it might be better to also provide
  islink(name), isdir(name) and isfile(name) methods (simular to
  their os.path equivalents)

Or rather as methods of the ZipInfo object. See TarInfo.

--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18595
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18644] Got ResourceWarning: unclosed file when using test function from formatter module

2013-08-03 Thread Martijn Pieters

Martijn Pieters added the comment:

Why is the `formatter` module still part of Python 3? This was a dependency for 
the `htmllib` module in Python 2 only, and that module was deprecated and 
removed from Python 3.

--
nosy: +mjpieters

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18644
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >