[Tutor] Long Lines techniques

2018-12-13 Thread Avi Gross
Simple question: When lines get long, what points does splitting them make sense and what methods are preferred? Details. I am used to many languages where you can continue a statement across multiple lines. What they share in common is the fact they do not use indenting for the use Pyt

[Tutor] Open webpage and save CSV

2018-12-13 Thread Sammy Lee
I need help on the problem below, Given a URL, open the webpage and save the CSV to a given file path. def save_url_to_csv_file(url, savefile): ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.

[Tutor] Import CSV

2018-12-13 Thread Sammy Lee
I need help on how to open a webpage and save the HTML to a given file path, given a URL. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

[Tutor] Python function

2018-12-13 Thread Sammy Lee
How do I create a python function that opens a CSV file and determines how many columns of data are in the file? The CSV files have been randomly generated from https://www.mockaroo.com/ def csv_column_count(openfile): ___ Tutor maillist - Tutor@pyth

Re: [Tutor] Import CSV

2018-12-13 Thread Sammy Lee
def save_url_to_file(url, savefile): This is the starting code. > On December 13, 2018 at 11:56 AM Sammy Lee wrote: > > > I need help on how to open a webpage and save the HTML to a given file > path, given a URL. > ___ Tutor maillist - Tu

[Tutor] Extract URL

2018-12-13 Thread Sammy Lee
I need help on the problem stated below. Given a URL, open the webpage and return the first anchor link url (a href). def extract_url_link(url): ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python

Re: [Tutor] Open webpage and save CSV

2018-12-13 Thread Bob Gailer
On Dec 13, 2018 1:51 PM, "Sammy Lee" wrote: > > I need help on the problem below, Could you be more specific? What kind of help do you need? Have you made any attempt to write a program? We are happy to help but we're not going to do all the work for you. So tell us what you do know about the va

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Bob Gailer
On Dec 13, 2018 1:51 PM, "Avi Gross" wrote: > > Simple question: Avi: when I see an email from you I tend to ignore it because it always seems to lead to something that is long, time consuming and complex. Would you consider finding ways to make your questions or comments a lot briefer? I will b

Re: [Tutor] Python function

2018-12-13 Thread Bob Gailer
On Dec 13, 2018 1:55 PM, "Sammy Lee" wrote: > > How do I create a python function that opens a CSV file and determines how many columns > of data are in the file? The CSV files have been randomly generated from https://www.mockaroo.com/ > > def csv_column_count(openfile): Same comments as I made

Re: [Tutor] Extract URL

2018-12-13 Thread Bob Gailer
On Dec 13, 2018 2:01 PM, "Sammy Lee" wrote: > > I need help on the problem stated below. > > > Given a URL, open the webpage and return the first anchor link url (a href). > > > def extract_url_link(url): Same comments as my other two emails. ___ Tutor

Re: [Tutor] Open webpage and save CSV

2018-12-13 Thread Mark Lawrence
On 13/12/2018 17:16, Sammy Lee wrote: I need help on the problem below, Given a URL, open the webpage and save the CSV to a given file path. def save_url_to_csv_file(url, savefile): Run up your favourite text editor and type up some code. Try to run it. Tell us what problems you get. Fai

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Mark Lawrence
On 13/12/2018 19:33, Bob Gailer wrote: On Dec 13, 2018 1:51 PM, "Avi Gross" wrote: Simple question: Avi: when I see an email from you I tend to ignore it because it always seems to lead to something that is long, time consuming and complex. Would you consider finding ways to make your questi

Re: [Tutor] Import CSV

2018-12-13 Thread Adam Eyring
Take a look at the book Automating the Boring Stuff with Python (free PDF): https://automatetheboringstuff.com/ There's a couple of chapters in there for downloading CSV files and extracting the data. On Thu, Dec 13, 2018 at 1:57 PM Sammy Lee wrote: > I need help on how to open a webpage and sa

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Steven D'Aprano
On Thu, Dec 13, 2018 at 12:36:27PM -0500, Avi Gross wrote: > Simple question: > > When lines get long, what points does splitting them make sense and what > methods are preferred? Good question! First, some background: Long lines are a potential code smell: a possible sign of excessively ters

Re: [Tutor] Import CSV

2018-12-13 Thread Alan Gauld via Tutor
On 13/12/2018 16:56, Sammy Lee wrote: > I need help on how to open a webpage and save the HTML to a given file path, > given a URL. You can use the standard library urllib module to fetch the file but most folks find the requests module easier to use. requests is a 3rd party module you will need

Re: [Tutor] Python function

2018-12-13 Thread Alan Gauld via Tutor
On 13/12/2018 17:21, Sammy Lee wrote: > How do I create a python function that opens a CSV file and determines how > many columns > of data are in the file? The CSV files have been randomly generated from > https://www.mockaroo.com/ > > def csv_column_count(openfile): You will find a bunch of s

Re: [Tutor] Extract URL

2018-12-13 Thread Alan Gauld via Tutor
On 13/12/2018 17:14, Sammy Lee wrote: > I need help on the problem stated below. > > > Given a URL, open the webpage and return the first anchor link url (a href). You will find a very similar example in the Web Client topic of my tutorial, see below... -- Alan G Author of the Learn to Program

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Alan Gauld via Tutor
On 13/12/2018 17:36, Avi Gross wrote: > When lines get long, what points does splitting them make sense and what > methods are preferred? Its down to personal preference and convenience plus a smidge of idiom. > Yes, I am aware of ways to break up something long by breaking in into > multiple st

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Avi Gross
Just for you Bob, I will make this short. Here is the most bizarre solution as you might agree. Edit a file of python code. Use lines as long as it takes. Make sure it works. Edit the file again and split lines in a way that does not mess up indentation. Meaning, use a normal text edi

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Steven D'Aprano
On Fri, Dec 14, 2018 at 01:03:55AM +, Alan Gauld via Tutor wrote: > I'd probably suggest > > stgs = ''.join([ > "long string", > "another string", > ... > "last string" > ]) That's certainly better than using the + operator, as that will be quite inefficient for large numbers of strings. Bu

Re: [Tutor] Long Lines techniques

2018-12-13 Thread Steven D'Aprano
On Thu, Dec 13, 2018 at 11:07:59PM -0500, Avi Gross wrote: [...] > There are cases where it may make sense to have a long like connected by AND > or OR given how python does short-circuiting while returning the last thing > or two it touched instead of an actual True/False. For example, you may wa

[Tutor] Obfuscated Python [was Long Lines techniques]

2018-12-13 Thread Steven D'Aprano
On Thu, Dec 13, 2018 at 11:07:59PM -0500, Avi Gross wrote: > Python may claim to be straightforward but I can easily see ways > to fool people in python too with dunder methods or function closures or > decorators or ... Dunder methods shouldn't fool anyone. Each dunder method has a straightforw