Re: [Tutor] Beautiful Soup

2015-10-12 Thread Cameron Simpson
On 12Oct2015 21:21, Crusier wrote: I am using Python 3.4. I am trying to do some web scraping at this moment. I got stuck because there is an IndexError: list index out of range if I put stock_code = (18). My desire output is that the script is able to detect print out the recent price whether i

[Tutor] Beautiful Soup

2015-10-12 Thread Crusier
Hi I am using Python 3.4. I am trying to do some web scraping at this moment. I got stuck because there is an IndexError: list index out of range if I put stock_code = (18). My desire output is that the script is able to detect print out the recent price whether it is up, down or unchanged. Attac

Re: [Tutor] Custom Function that Takes argument

2015-10-12 Thread Alan Gauld
On 13/10/15 00:32, Nym City wrote: ans=raw_input("What would you like to do? ") if ans=="1": locality = raw_input("\nEnter City ") break elif ans=="2": region = raw_input("\n Search by State ") break elif ans=="3": zip = raw_input("\n Search by Zip

Re: [Tutor] Guidance on using custom exceptions please

2015-10-12 Thread Cameron Simpson
On 13Oct2015 10:37, Steven D'Aprano wrote: On Mon, Oct 12, 2015 at 02:55:43PM +, David Aldrich wrote: Consider a 'send' method that sends a message to another system via a socket. This method will wait for a response before returning. There are two possible error conditions: [...] So, m

Re: [Tutor] Custom Function that Takes argument

2015-10-12 Thread Nym City via Tutor
Thank you for your response. I updated the first portion of my code to include breaks: import urllib2 import json locu_api = 'redacted' ans=True while ans:     print ("""     1.Search by City     2.Search by Region (State Abbreviation)     3.Search by Zip     4.Exit/Quit     """)     ans=raw_i

Re: [Tutor] Guidance on using custom exceptions please

2015-10-12 Thread Steven D'Aprano
On Mon, Oct 12, 2015 at 02:55:43PM +, David Aldrich wrote: > Hi > > Consider a 'send' method that sends a message to another system via a > socket. This method will wait for a response before returning. There > are two possible error conditions: [...] > So, my question is, what's the pytho

Re: [Tutor] how to unittest cli input

2015-10-12 Thread Steven D'Aprano
On Mon, Oct 12, 2015 at 10:37:51AM -0700, Alex Kleider wrote: > Any comments about when/if to use 'if src != None:' vs 'if src is not > None:'? > (or 'if src == None:' vs 'if src is None:') Short answer: always compare to None using `is` or `is not`. Long answer: If you want to check for src b

Re: [Tutor] how to unittest cli input

2015-10-12 Thread Ben Finney
Alex Kleider writes: > Any comments about when/if to use 'if src != None:' vs 'if src is not > None:'? Express your intention in the code. If you want to express “is this value the ‘None’ singleton?”, compare identity with ‘is’/‘is not’. (This is what you almost always mean when comparing to ‘N

Re: [Tutor] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?

2015-10-12 Thread Oscar Benjamin
On Mon, 12 Oct 2015 17:15 Albert-Jan Roskam wrote: Hi, In Python 2 one can do silly apple-pear comparisons such as 0> "0".*) "CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison a

Re: [Tutor] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?

2015-10-12 Thread Albert-Jan Roskam
> To: tutor@python.org > From: em...@fenx.com > Date: Mon, 12 Oct 2015 09:25:00 -0700 > Subject: Re: [Tutor] 0> "0" --> is there a "from __future__ import to make > this raise a TypeError? > > On 10/12/2015 9:12 AM, Albert-Jan Roskam wrote: >> Hi, >> >> >

[Tutor] Guidance on using custom exceptions please

2015-10-12 Thread David Aldrich
Hi Consider a 'send' method that sends a message to another system via a socket. This method will wait for a response before returning. There are two possible error conditions: 1) Timeout - i.e. no response received 2) Illegal response received I need to communicate these errors

Re: [Tutor] How to read all integers from a binary file?

2015-10-12 Thread David Aldrich
> data = array.array("i", inf.read()) Thanks for all the answers to my question. I used the array method in the end. Best regards David ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mail

Re: [Tutor] Can one use python to concatenate n media files?

2015-10-12 Thread Alan Gauld
On 12/10/15 05:15, Fast Primes wrote: If so, could someone present an example? Yes, and Emile has shown how for a trivial, pure binary case. But to make the catenation sensible you need to know the file type. Many media files hold the actual media data inside an envelope of header information

Re: [Tutor] how to unittest cli input

2015-10-12 Thread Alex Kleider
On 2015-10-11 14:52, Cameron Simpson wrote: Minor remark: I would write "if src is not None:". In principle the empty string is also "falsey" like None, making your plain "if src:" slightly unreliable. Be precise! 'precise' is good! Any comments about when/if to use 'if src != None:' vs 'if s

Re: [Tutor] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?

2015-10-12 Thread Emile van Sebille
On 10/12/2015 9:12 AM, Albert-Jan Roskam wrote: Hi, In Python 2 one can do silly apple-pear comparisons such as 0> "0".*) "CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison a

[Tutor] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?

2015-10-12 Thread Albert-Jan Roskam
Hi, In Python 2 one can do silly apple-pear comparisons such as 0> "0".*) "CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.". In Python3 this h

Re: [Tutor] Can one use python to concatenate n media files?

2015-10-12 Thread Emile van Sebille
On 10/11/2015 9:15 PM, Fast Primes wrote: If so, could someone present an example? target = open(target,'wb') for source in mediafilelist: target.write(open(source,'rb').read()) But you probably want something different anyway. Emile ___ Tu