Python - requests - forms - web scraping - how to deal with multi stage forms
https://stackoverflow.com/questions/50383210/python-requests-how-to-post-few-stages-forms -- https://mail.python.org/mailman/listinfo/python-list
Re: what does := means simply?
On Thu, 17 May 2018 05:33:38 +0400, Abdur-Rahmaan Janhangeer wrote: > what does := proposes to do? Simply, it proposes to add a new operator := for assignment (or binding) as an expression, as an addition to the = assignment operator which operates only as a statement. The syntax is: name := expression and the meaning is: 1. evaluate 2. assign that value to 3. return that same value as the result A simple example (not necessarily a GOOD example, but a SIMPLE one): print(x := 100, x+1, x*2, x**3) will print: 100 101 200 100 Today, we would write that as: x = 100 print(x, x+1, x*2, x**3) A better example might be: if mo := re.search(pattern1, text): print(mo.group(0)) elif mo := re.match(pattern2, text): print(mo.group(3)) elif mo := re.search(pattern3, text): print(mo.group(2)) which today would need to be written as: mo = re.search(pattern, text) if mo: print(mo.group(0)) else: mo = re.match(pattern2, text) if mo: print(mo.group(3)) else: mo := re.search(pattern3, text) if mo: print(mo.group(2)) -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: syntax oddities
On Thu, 17 May 2018 05:25:44 +0400, Abdur-Rahmaan Janhangeer wrote: > weird, still not much traffic on this thread How many ways would you like us to answer the question? It is a FAQ: https://docs.python.org/3/faq/design.html Here's an older version: http://www.effbot.org/pyfaq/why-does-python-use-methods-for-some-functionality-e-g-list-index-but-functions-for-other-e-g-len-list.htm -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: why does list's .remove() does not return an object?
On Wednesday, May 16, 2018 at 7:42:01 PM UTC-7, Abdur-Rahmaan Janhangeer wrote: > why is x = list.remove(elem) not return the list? > > Abdur-Rahmaan Janhangeer > https://github.com/Abdur-rahmaanJ 1) If you are naming your list "list," you're asking for trouble. Shadowing builtin names is risky. Ten years ago I named a variable "max". Oops. 2) list.remove() operates in-place. Would you expect it to return a copy? Making that copy could potentially use a lot of memory and time. 3) If you do want a copy, construct it from two slices of your original list. Let's say the element you want to remove is at position 6. Then: new_list = old_list[:6] + old_list[7:] 3) -- https://mail.python.org/mailman/listinfo/python-list
Re: why does list's .remove() does not return an object?
On 5/16/18 10:41 PM, Abdur-Rahmaan Janhangeer wrote: why is x = list.remove(elem) not return the list? Methods in Python usually do one of two things: 1) mutate the object and return None; or 2) leave the object alone and return a new object. This helps make it clear which methods mutate and which don't. Since .remove mutates the list, it returns None. --Ned. -- https://mail.python.org/mailman/listinfo/python-list
why does list's .remove() does not return an object?
why is x = list.remove(elem) not return the list? Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ -- https://mail.python.org/mailman/listinfo/python-list
Re: what does := means simply?
meaning that's precisely what i'm asking for Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Thu, 17 May 2018, 05:45 Chris Angelico, wrote: > On Thu, May 17, 2018 at 11:33 AM, Abdur-Rahmaan Janhangeer > wrote: > > what does := proposes to do? > > > > pep572 > > > > If you read the PEP, you'll find an answer to your question. > > https://www.python.org/dev/peps/pep-0572/ > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Edge index problem
Am trying to get the edge index of selected edges in polygon.. (Maya).. don't how to query and get the values. Pls help me to find out.. -- https://mail.python.org/mailman/listinfo/python-list
Re: what does := means simply?
On Thu, May 17, 2018 at 11:33 AM, Abdur-Rahmaan Janhangeer wrote: > what does := proposes to do? > > pep572 > If you read the PEP, you'll find an answer to your question. https://www.python.org/dev/peps/pep-0572/ ChrisA -- https://mail.python.org/mailman/listinfo/python-list
what does := means simply?
what does := proposes to do? pep572 Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ -- https://mail.python.org/mailman/listinfo/python-list
Re: syntax oddities
weird, still not much traffic on this thread Abdur-Rahmaan Janhangeer https://github.com/Abdur-rahmaanJ On Tue, 15 May 2018, 23:15 Tobiah, wrote: > Why is it len(object) instead of object.len? > > Why is it getattr(object, item) rather then object.getattr(item)? > > etc... > > > Thanks > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: Simplest way to clobber/replace one populated directory with another?
On 15May2018 09:37, Travis Griggs wrote: I have a directory structure that might look something like: Data Current A B C Previous A X In as simple/quick a step as possible, I want to rename Current as Previous including the contents and wiping out the original such that it is now: Data Previous A B C I've tried something like: from pathlib import Path src = Path('Data/Current’) dest = Path('Data/Previous’) src.replace(dest) The docs led me to hope this would work: "If target points to an existing file or directory, it will be unconditionally replaced.” But it *does* appear to be conditional. I get a "Directory not empty" exception. I guess I could recursively delete the ‘Previous' directory first. Is that basically the only solution? Or is there a better way to achieve this? When I do this and want speed I go: 1) rename Previous to a scratch name (eg .rmtmp-$$-Previous; the mkstemp function will help pick a free name for you). Make sure it is in the same directory i.e. rename blah/blah/Previous to blah/blah/.rmtmp-$$-Previous) - avoids accidentally crossing filesystem boundaries. 2) rename Current to previous 3) remove the old previous (I do this asynchronously in shell scripts) In fact I do this so often in the shell that I have a trite script called "rmr" that does 1+3, and routinely type: rmr Previous && mv Current Previous Prompt back instantly, "rm" of the temp name proceeding siletnly in the background. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: stock quotes off the web, py style
On 05/16/2018 06:21 PM, Mike McClain wrote: On Wed, May 16, 2018 at 02:33:23PM +0200, Friedrich Rentsch wrote: I didn't know the site you mention. I've been getting quotes from Yahoo daily. The service they discontinued was for up to 50 symbols per page. I now parse a separate page of some 500K of html for each symbol! This site is certainly more concise and surely a lot faster. Thank you sir for the response and code snippet. As it turns out iextrading.com doesn't supply data on mutuals which are the majority of my portfolio so they are not goimng to do me much good after all. If you please, what is the URL of one stock you're getting from Yahoo that requires parsing 500K of html per symbol? That's better than not getting the quotes. If AlphaVantage ever comes back up, they send 100 days quotes for each symbol and I only use today's and yesterday's, but it is easy to parse. You would do multiple symbols in a loop which you enter with an open urllib object, rather than opening a new one for each symbol inside the loop. At the moment I can't see how to do that but will figure it out. Thanks for the pointer. Mike -- "There are three kinds of men. The ones who learn by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." --- Will Rogers I meant to check out AlphaVantage myself and registered, since it appears to be a kind of interest group. I wasn't aware it is down, because I haven't yet tried to log on. But I hope to do so when it comes back. The way I get quotes from Yahoo is a hack: 1. Get a quote on the Yahoo web page. 2. Copy the url. (https://finance.yahoo.com/quote/IBM?p=IBM&guccounter=1). 3. Compose such urls in a loop one symbol at a time and read nearly 600K of html text for each of them. 4. Parse the text for the numbers I want to extract. Needles in a haystack. Slow for a large set of symbols and grossly inefficient in terms of data traffic. Forget my last suggestion "You would do multiple symbols . . ." that was wrong. You have to open a urllib object for every symbol, the same way you'd open a file for every file name. And thanks to the practitioners for the warnings against using 'eval'. I have hardly ever used it, never in online communications. So my awareness level is low. But I understand the need to be careful. Frederic You would do multiple symbols "You would do multiple symbols -- https://mail.python.org/mailman/listinfo/python-list
Re: Simplest way to clobber/replace one populated directory with another?
On 2018-05-15 11:37, Travis Griggs wrote: I have a directory structure that might look something like: Data Current A B C Previous A X In as simple/quick a step as possible, I want to rename Current as Previous including the contents and wiping out the original such that it is now: Data Previous A B C Is this what you need? username@hostname$ ll */* -rw-rw-r-- 1 username username 7 May 16 15:54 Current/1 -rw-rw-r-- 1 username username 7 May 16 15:54 Current/2 -rw-rw-r-- 1 username username 11 May 16 15:54 Current/3 -rw-rw-r-- 1 username username 18 May 16 15:55 Previous/1 -rw-rw-r-- 1 username username 18 May 16 15:55 Previous/2 -rw-rw-r-- 1 username username 14 May 16 15:55 Previous/3 username@hostname$ python Python 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import shutil, os >>> shutil.rmtree("Previous") >>> os.rename("Current","Previous") >>> username@hostname$ ll */* -rw-rw-r-- 1 username username 7 May 16 15:54 Previous/1 -rw-rw-r-- 1 username username 7 May 16 15:54 Previous/2 -rw-rw-r-- 1 username username 11 May 16 15:54 Previous/3 username@hostname$ (I am running on Linux) If you can do this from a bash script rather than a python program, you could just do: #!/bin/bash rm -r Previous mv Previous Current -- Michael F. Stemper This email is to be read by its intended recipient only. Any other party reading is required by the EULA to send me $500.00. -- https://mail.python.org/mailman/listinfo/python-list
Re: object types, mutable or not?
On Thu, May 17, 2018 at 1:03 AM, Ned Batchelder wrote: > On 5/16/18 10:06 AM, Steven D'Aprano wrote: >> >> On Wed, 16 May 2018 09:23:02 -0400, Ned Batchelder wrote: >> >>> I've also experimented with different ways to better say "everything is >>> an object". One possibility is, "any right-hand side of an assignment >>> is an object," though that is a bit tortured. >> >> What if there's no assignment? >> >>> Now I'm thinking of trying, "Any piece of data is an object." >> >> Is None data? How about True and False? >> >> Surely object() isn't data... and if it is, what about len? >> > This is what I meant by the complication when you get to a deeper discussion > of all the possible kinds of Python values. I think even beginners would > consider True and False as data. The others take more explanation. > None takes only a little more explanation. It's data that says you have no data. It's like asking "is zero a number?" - yes, there's a mental leap to be made, but since it is so _exactly_ like zero's status, it's not too hard to explain. (Nothing like as bad as explaining SQL's NULL, which sometimes is a value, sometimes is a placeholder meaning "there is no value here", sometimes is a non-value, and sometimes just defies categorization.) Explaining that *len* is data requires the concept of "functions are things, too", which definitely takes some grokking. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: syntax oddities
On Tue, May 15, 2018, 6:00 PM Steven D'Aprano < steve+comp.lang.pyt...@pearwood.info> wrote: > On Tue, 15 May 2018 12:10:07 -0700, Tobiah wrote: > > > Why is it len(object) instead of object.len? > > Because we're not serfs in the Kingdom of Nouns: > > https://steve-yegge.blogspot.com/2006/03/execution-in-kingdom-of-nouns.html No, then it would be written LengthGetter(object).getLength() -- https://mail.python.org/mailman/listinfo/python-list
Re: seeking deeper (language theory) reason behind Python design choice
On Wed, May 16, 2018 at 10:06 AM, bartc wrote: > On 16/05/2018 16:09, Ian Kelly wrote: >> >> On Tue, May 15, 2018, 6:36 PM bartc wrote: >> >>> On 16/05/2018 01:04, Steven D'Aprano wrote: >>> I'm not a C coder, but I think that specific example would be immune to the bug we are discussing, since (I think) you can't chain assignments in C. Am I right? >>> >>> >>> Assignments can be chained in C (with right-to-left precedence) as can >>> augmented assignments (+= and so on). >>> >> >> Yes, but not in the particular example that Steven was referring to, which >> you elided from your quoting. > > > I was responding to the chained assignment bit: > > a = b = c = d = x; > > is allowed, but (depending on implementation details), the first = might be > a different kind of assignment from the other three. > >> open(...) is not a valid LHS for assignment. > > > The LHS needs to be an lvalue. A function result by itself won't be. open() > would need to be a macro that expands to an lvalue, or used like this when > open() returns a pointer: > >a = *open() = x; > > So it only needs an extra * (subject to the correct types of everything > involved) for both these "=" to be plausible. Sure, but that wasn't the example. The macro possibility is a good point, but that's technically the C preprocessor, not the C language itself. -- https://mail.python.org/mailman/listinfo/python-list
Re: stock quotes off the web, py style
On Wed, May 16, 2018 at 02:33:23PM +0200, Friedrich Rentsch wrote: > > I didn't know the site you mention. I've been getting quotes from > Yahoo daily. The service they discontinued was for up to 50 symbols > per page. I now parse a separate page of some 500K of html for each > symbol! This site is certainly more concise and surely a lot faster. Thank you sir for the response and code snippet. As it turns out iextrading.com doesn't supply data on mutuals which are the majority of my portfolio so they are not goimng to do me much good after all. If you please, what is the URL of one stock you're getting from Yahoo that requires parsing 500K of html per symbol? That's better than not getting the quotes. If AlphaVantage ever comes back up, they send 100 days quotes for each symbol and I only use today's and yesterday's, but it is easy to parse. > You would do multiple symbols in a loop which you enter with an open > urllib object, rather than opening a new one for each symbol inside > the loop. At the moment I can't see how to do that but will figure it out. Thanks for the pointer. Mike -- "There are three kinds of men. The ones who learn by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." --- Will Rogers -- https://mail.python.org/mailman/listinfo/python-list
Re: stock quotes off the web, py style
For Friedrich's, Peter's and the many other responses, many thanks. I will get a handle on python eventually and the many teachers on this list are making that easier. Mike -- "There are three kinds of men. The ones who learn by reading. The few who learn by observation. The rest of them have to pee on the electric fence for themselves." --- Will Rogers -- https://mail.python.org/mailman/listinfo/python-list
Re: seeking deeper (language theory) reason behind Python design choice
On 16/05/2018 16:09, Ian Kelly wrote: On Tue, May 15, 2018, 6:36 PM bartc wrote: On 16/05/2018 01:04, Steven D'Aprano wrote: I'm not a C coder, but I think that specific example would be immune to the bug we are discussing, since (I think) you can't chain assignments in C. Am I right? Assignments can be chained in C (with right-to-left precedence) as can augmented assignments (+= and so on). Yes, but not in the particular example that Steven was referring to, which you elided from your quoting. I was responding to the chained assignment bit: a = b = c = d = x; is allowed, but (depending on implementation details), the first = might be a different kind of assignment from the other three. open(...) is not a valid LHS for assignment. The LHS needs to be an lvalue. A function result by itself won't be. open() would need to be a macro that expands to an lvalue, or used like this when open() returns a pointer: a = *open() = x; So it only needs an extra * (subject to the correct types of everything involved) for both these "=" to be plausible. -- bartc -- https://mail.python.org/mailman/listinfo/python-list
Re: stock quotes off the web, py style
thank you for that tip. I missed that somehow... На 16 май 2018 г. 16:31:37 GMT+02:00, Peter Otten <__pete...@web.de> написа: >Friedrich Rentsch wrote: > >> >>> ibm = urllib2.urlopen >> ("https://api.iextrading.com/1.0/stock/IBM/quote";).read() >> >>> ibm = eval (ibm) > >Dont do this. You are allowing the guys at iextrading.com to execute >arbitrary code on your machine. Use > >ibm = json.loads(ibm) > >instead or > >import urllib.request, json >ibm = urllib.request.urlopen( >"https://api.iextrading.com/1.0/stock/IBM/quote"; >).read() >ibm = json.loads(ibm.decode("utf-8")) > >if you are using Python 3. > > >-- >https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: stock quotes off the web, py style
>It serves a naked set of data, which happens to conform to the python source code specification for dictionaries and consequently can be compiled into a dictionary with 'eval', like so: I would highly discourage any long-term usage (or any usage) of eval() in this sort of context. If iextrading was compromised, a malicious third party could simply start serving arbitrary python expressions (instead of the dictionary-like data currently) and your script would execute it unquestioningly. Consider using ast.literal_eval() - https://docs.python.org/3/library/ast.html#ast.literal_eval for parsing string representations of basic python datatypes. On 16 May 2018 at 13:33, Friedrich Rentsch wrote: > > > On 05/16/2018 02:23 AM, Mike McClain wrote: > >> Initially I got my quotes from a broker daily to plug into a >> spreadsheet, Then I found Yahoo and wrote a perl script to grab them. >> When Yahoo quit supplying quotes I found AlphaVantage.co and rewrote >> the perl script. >> AlphaVantage.co has been down since last week and I found >> iextrading.com has a freely available interface. Since it needs >> a rewrite and I'm trying to get a handle on python this seems >> like a good opportunity to explore. >> If someone would please suggest modules to explore. Are there any >> upper level modules that would allow me to do something like: >> >> from module import get >> def getAquote(symbol): >> url = 'https://api.iextrading.com/1.0/stock/()/quote'.format(symbol) >> reply = module.get(url) >> return my_parse(reply) >> >> Thanks, >> Mike >> -- >> Men occasionally stumble over the truth, but most of them pick >> themselves up and hurry off as if nothing ever happened. >> - Churchill >> > > I didn't know the site you mention. I've been getting quotes from Yahoo > daily. The service they discontinued was for up to 50 symbols per page. I > now parse a separate page of some 500K of html for each symbol! This site > is certainly more concise and surely a lot faster. It serves a naked set of > data, which happens to conform to the python source code specification for > dictionaries and consequently can be compiled into a dictionary with > 'eval', like so: > > >>> ibm = urllib2.urlopen ("https://api.iextrading.com/1.0/stock/IBM/quote > ").read() > >>> ibm = eval (ibm) > >>> for item in sorted (ibm.items()): print '%-24s%s' % item > > avgTotalVolume 5331869 > calculationPriceclose > change -0.56 > changePercent -0.00388 > close 143.74 > closeTime 1526414517398 > companyName International Business Machines Corporation > delayedPrice143.74 > delayedPriceTime1526414517398 > high143.99 > iexAskPrice 0 > iexAskSize 0 > iexBidPrice 0 > iexBidSize 0 > iexLastUpdated 0 > iexMarketPercent0 > iexRealtimePrice0 > iexRealtimeSize 0 > iexVolume 0 > latestPrice 143.74 > latestSourceClose > latestTime May 15, 2018 > latestUpdate1526414517398 > latestVolume4085996 > low 142.92 > marketCap 131948764304 > open143.5 > openTime1526391000646 > peRatio 10.34 > previousClose 144.3 > primaryExchange New York Stock Exchange > sector Technology > symbol IBM > week52High 171.13 > week52Low 139.13 > ytdChange -0.0485148849103 > > You would do multiple symbols in a loop which you enter with an open > urllib object, rather than opening a new one for each symbol inside the > loop. > > Frederic > > -- > https://mail.python.org/mailman/listinfo/python-list > -- Chris Open Cosmos Any opinions given above are my own. -- https://mail.python.org/mailman/listinfo/python-list
Re: seeking deeper (language theory) reason behind Python design choice
On Tue, May 15, 2018, 6:36 PM bartc wrote: > On 16/05/2018 01:04, Steven D'Aprano wrote: > > > I'm not a C coder, but I think that specific example would be immune to > > the bug we are discussing, since (I think) you can't chain assignments in > > C. Am I right? > > Assignments can be chained in C (with right-to-left precedence) as can > augmented assignments (+= and so on). > Yes, but not in the particular example that Steven was referring to, which you elided from your quoting. open(...) is not a valid LHS for assignment. -- https://mail.python.org/mailman/listinfo/python-list
Re: object types, mutable or not?
On 5/16/18 10:06 AM, Steven D'Aprano wrote: On Wed, 16 May 2018 09:23:02 -0400, Ned Batchelder wrote: I've also experimented with different ways to better say "everything is an object". One possibility is, "any right-hand side of an assignment is an object," though that is a bit tortured. What if there's no assignment? Now I'm thinking of trying, "Any piece of data is an object." Is None data? How about True and False? Surely object() isn't data... and if it is, what about len? This is what I meant by the complication when you get to a deeper discussion of all the possible kinds of Python values. I think even beginners would consider True and False as data. The others take more explanation. --Ned. -- https://mail.python.org/mailman/listinfo/python-list
Re: seeking deeper (language theory) reason behind Python design choice
On Thu, May 17, 2018 at 12:25 AM, Grant Edwards wrote: > On 2018-05-16, Steven D'Aprano wrote: >> On Tue, 15 May 2018 22:21:15 +0200, Peter J. Holzer wrote: >> >>> On 2018-05-15 00:52:42 +, Steven D'Aprano wrote: >> [...] By 1991 there had already been *decades* of experience with C >>> >>> About one and a half decades. >> >> That would still be plural decades. > > So would zero. ;) > > The only plural in English implies is that the quantity is not 1. It > does _not_ imply the quantity is greater than 1. By 1991 there had already been AT LEAST negative seven decades of experience with C. It's mathematically provable! And completely useless. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: stock quotes off the web, py style
Friedrich Rentsch wrote: > >>> ibm = urllib2.urlopen > ("https://api.iextrading.com/1.0/stock/IBM/quote";).read() > >>> ibm = eval (ibm) Dont do this. You are allowing the guys at iextrading.com to execute arbitrary code on your machine. Use ibm = json.loads(ibm) instead or import urllib.request, json ibm = urllib.request.urlopen( "https://api.iextrading.com/1.0/stock/IBM/quote"; ).read() ibm = json.loads(ibm.decode("utf-8")) if you are using Python 3. -- https://mail.python.org/mailman/listinfo/python-list
Re: seeking deeper (language theory) reason behind Python design choice
On 2018-05-16, Steven D'Aprano wrote: > On Tue, 15 May 2018 22:21:15 +0200, Peter J. Holzer wrote: > >> On 2018-05-15 00:52:42 +, Steven D'Aprano wrote: > [...] >>> By 1991 there had already been *decades* of experience with C >> >> About one and a half decades. > > That would still be plural decades. So would zero. ;) The only plural in English implies is that the quantity is not 1. It does _not_ imply the quantity is greater than 1. -- Grant Edwards grant.b.edwardsYow! ! Now I understand at advanced MICROBIOLOGY and gmail.comth' new TAX REFORM laws!! -- https://mail.python.org/mailman/listinfo/python-list
Re: object types, mutable or not?
On Wed, 16 May 2018 09:23:02 -0400, Ned Batchelder wrote: > I've also experimented with different ways to better say "everything is > an object". One possibility is, "any right-hand side of an assignment > is an object," though that is a bit tortured. What if there's no assignment? > Now I'm thinking of trying, "Any piece of data is an object." Is None data? How about True and False? Surely object() isn't data... and if it is, what about len? *wink* -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: object types, mutable or not?
On 16 May 2018 at 14:23, Ned Batchelder wrote: > I've also experimented with different ways to better say "everything is an > object". One possibility is, "any right-hand side of an assignment is an > object," though that is a bit tortured. C++ called that an "rvalue". And then went on to define things that could go on the left hand side of an assignment as "lvalues". And now we have two confusing concepts to explain - see what happens when you let a standards committee define your language? :-) Paul -- https://mail.python.org/mailman/listinfo/python-list
Re: object types, mutable or not?
On 5/16/18 3:17 AM, Steven D'Aprano wrote: On Wed, 16 May 2018 17:03:22 +1000, Ben Finney wrote: So, no, I think the more useful – and less problematic – framing is that every object *has* a value, and mutable objects may change to a different value while remaining the same object. What's an object? That's not a rhetorical question. When I started learning Python, I had *no idea* what "object oriented programming" was, or what classes and objects and instances were. I still don't know if there is a precise, accurate, unambiguous definition. If you're going to describe Python in terms of objects for pedagogical purposes, you better be prepared to explain in simple, plain English, non- technical, unambiguous terms what an object is. Without reference to the CPython (or any other Python) implementation. It is true that "value" has a multitude of meanings. But "object" is even worse. Not only does it also have a multitude of meanings (Websters lists at least 7 for the noun, WordNet gives 5), but it ALSO has a technical meaning in computer science, AND a specific meaning in Python as the name of the type "object", AND also is used as a synonym for "instance". I expect that most people understand that the ordinary English word "value" has a multitude of meanings, and so will avoid thinking of it as a precise technical term. I don't think you can say the same for "object". I've also experimented with different ways to better say "everything is an object". One possibility is, "any right-hand side of an assignment is an object," though that is a bit tortured. Now I'm thinking of trying, "Any piece of data is an object." I think that might work well, with some complications arising when you have to explain that functions (and modules and classes and ...) are also a kind of data. At least it will let me use the word "data" so I can pretend to be one of the cool kids :) --Ned. -- https://mail.python.org/mailman/listinfo/python-list
Re: stock quotes off the web, py style
On Wed, May 16, 2018 at 8:33 AM, Friedrich Rentsch wrote: > > > On 05/16/2018 02:23 AM, Mike McClain wrote: >> >> Initially I got my quotes from a broker daily to plug into a >> spreadsheet, Then I found Yahoo and wrote a perl script to grab them. >> When Yahoo quit supplying quotes I found AlphaVantage.co and rewrote >> the perl script. >> AlphaVantage.co has been down since last week and I found >> iextrading.com has a freely available interface. Since it needs >> a rewrite and I'm trying to get a handle on python this seems >> like a good opportunity to explore. >> If someone would please suggest modules to explore. Are there any >> upper level modules that would allow me to do something like: >> >> from module import get >> def getAquote(symbol): >> url = 'https://api.iextrading.com/1.0/stock/()/quote'.format(symbol) >> reply = module.get(url) >> return my_parse(reply) >> >> Thanks, >> Mike >> -- >> Men occasionally stumble over the truth, but most of them pick >> themselves up and hurry off as if nothing ever happened. >> - Churchill > > > I didn't know the site you mention. I've been getting quotes from Yahoo > daily. The service they discontinued was for up to 50 symbols per page. I > now parse a separate page of some 500K of html for each symbol! This site is > certainly more concise and surely a lot faster. It serves a naked set of > data, which happens to conform to the python source code specification for > dictionaries and consequently can be compiled into a dictionary with 'eval', > like so: > ibm = urllib2.urlopen ("https://api.iextrading.com/1.0/stock/IBM/quote";).read() ibm = eval (ibm) for item in sorted (ibm.items()): print '%-24s%s' % item > > avgTotalVolume 5331869 > calculationPriceclose > change -0.56 > changePercent -0.00388 > close 143.74 > closeTime 1526414517398 > companyName International Business Machines Corporation > delayedPrice143.74 > delayedPriceTime1526414517398 > high143.99 > iexAskPrice 0 > iexAskSize 0 > iexBidPrice 0 > iexBidSize 0 > iexLastUpdated 0 > iexMarketPercent0 > iexRealtimePrice0 > iexRealtimeSize 0 > iexVolume 0 > latestPrice 143.74 > latestSourceClose > latestTime May 15, 2018 > latestUpdate1526414517398 > latestVolume4085996 > low 142.92 > marketCap 131948764304 > open143.5 > openTime1526391000646 > peRatio 10.34 > previousClose 144.3 > primaryExchange New York Stock Exchange > sector Technology > symbol IBM > week52High 171.13 > week52Low 139.13 > ytdChange -0.0485148849103 > > You would do multiple symbols in a loop which you enter with an open urllib > object, rather than opening a new one for each symbol inside the loop. > > Frederic > > -- > https://mail.python.org/mailman/listinfo/python-list Many people find the library called Requests a better alternative to urllib. It is more intuitive -- Joel Goldstick http://joelgoldstick.com/blog http://cc-baseballstats.info/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Re: stock quotes off the web, py style
On 05/16/2018 02:23 AM, Mike McClain wrote: Initially I got my quotes from a broker daily to plug into a spreadsheet, Then I found Yahoo and wrote a perl script to grab them. When Yahoo quit supplying quotes I found AlphaVantage.co and rewrote the perl script. AlphaVantage.co has been down since last week and I found iextrading.com has a freely available interface. Since it needs a rewrite and I'm trying to get a handle on python this seems like a good opportunity to explore. If someone would please suggest modules to explore. Are there any upper level modules that would allow me to do something like: from module import get def getAquote(symbol): url = 'https://api.iextrading.com/1.0/stock/()/quote'.format(symbol) reply = module.get(url) return my_parse(reply) Thanks, Mike -- Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened. - Churchill I didn't know the site you mention. I've been getting quotes from Yahoo daily. The service they discontinued was for up to 50 symbols per page. I now parse a separate page of some 500K of html for each symbol! This site is certainly more concise and surely a lot faster. It serves a naked set of data, which happens to conform to the python source code specification for dictionaries and consequently can be compiled into a dictionary with 'eval', like so: >>> ibm = urllib2.urlopen ("https://api.iextrading.com/1.0/stock/IBM/quote";).read() >>> ibm = eval (ibm) >>> for item in sorted (ibm.items()): print '%-24s%s' % item avgTotalVolume 5331869 calculationPrice close change -0.56 changePercent -0.00388 close 143.74 closeTime 1526414517398 companyName International Business Machines Corporation delayedPrice 143.74 delayedPriceTime 1526414517398 high 143.99 iexAskPrice 0 iexAskSize 0 iexBidPrice 0 iexBidSize 0 iexLastUpdated 0 iexMarketPercent 0 iexRealtimePrice 0 iexRealtimeSize 0 iexVolume 0 latestPrice 143.74 latestSource Close latestTime May 15, 2018 latestUpdate 1526414517398 latestVolume 4085996 low 142.92 marketCap 131948764304 open 143.5 openTime 1526391000646 peRatio 10.34 previousClose 144.3 primaryExchange New York Stock Exchange sector Technology symbol IBM week52High 171.13 week52Low 139.13 ytdChange -0.0485148849103 You would do multiple symbols in a loop which you enter with an open urllib object, rather than opening a new one for each symbol inside the loop. Frederic -- https://mail.python.org/mailman/listinfo/python-list
Re: object types, mutable or not?
On Wed, 16 May 2018 17:03:22 +1000, Ben Finney wrote: > So, no, I think the more useful – and less problematic – framing is that > every object *has* a value, and mutable objects may change to a > different value while remaining the same object. What's an object? That's not a rhetorical question. When I started learning Python, I had *no idea* what "object oriented programming" was, or what classes and objects and instances were. I still don't know if there is a precise, accurate, unambiguous definition. If you're going to describe Python in terms of objects for pedagogical purposes, you better be prepared to explain in simple, plain English, non- technical, unambiguous terms what an object is. Without reference to the CPython (or any other Python) implementation. It is true that "value" has a multitude of meanings. But "object" is even worse. Not only does it also have a multitude of meanings (Websters lists at least 7 for the noun, WordNet gives 5), but it ALSO has a technical meaning in computer science, AND a specific meaning in Python as the name of the type "object", AND also is used as a synonym for "instance". I expect that most people understand that the ordinary English word "value" has a multitude of meanings, and so will avoid thinking of it as a precise technical term. I don't think you can say the same for "object". -- Steve -- https://mail.python.org/mailman/listinfo/python-list
Re: object types, mutable or not?
Steven D'Aprano writes: > On Wed, 16 May 2018 11:30:26 +1000, Ben Finney wrote: > > > An object is not a value; an object *has* a value. The object > > retains its identity even when its value changes. > > Here you have hit on the crux of the matter. Why cannot both > statements be true? The above assertion was in the context of saying what is pedagogically useful. If we have someone with the patience of a philosophy academic, one can of course choose to explore the definitions of all terms. Then, by choosing the definitions appropriately, we can make those statements both true. For teaching Python, we should not assume that kind of limitless patience for ruthlessly abandoning prior meanings of terms before using them. For the purpose of teaching Python, I maintain that teaching “every value is an object” will lead the learner to infer “an object is whatever the value is”. That's a false inference, and we should avoid it by not stating such an equivalence in the first place. So, no, I think the more useful – and less problematic – framing is that every object *has* a value, and mutable objects may change to a different value while remaining the same object. -- \ “He who allows oppression, shares the crime.” —Erasmus Darwin, | `\ grandfather of Charles Darwin | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list