Re: [Tutor] Problem
if you print the values of a, b ,c that satisfy and don't satisfy the condiction cm == 50 at the same time, you can't know what works and what did not work. here is the code that i wrote and worked well for a in range(1, 11): # i replaced 10 by 11 to include the 10 for b in range(1, 6): # same as before put 6 to include 5 for c in range(1, 6): mc = (6*a) + (9*b) + (20*a) if mc == 50: print(a, b, c) notice that i am using python 3.5, range is a generator like xrange in python 2 and the result is 2 for a and b and 1 for c I wish this coold help you for what you said, here is the hard coded solution: for a in range(1, 11): for b in range(1, 6): for c in range(1, 6): mc = 6*a + 9*b + 20*c if mc == 50: print('for 50 McNuggets, "a"= {}, "b"={}, "c"={}'.format(a, b, c)) if mc == 51: print('for 51 McNuggets, "a"= {}, "b"={}, "c"={}'.format(a, b, c)) if mc == 52: print('for 52 McNuggets, "a"= {}, "b"={}, "c"={}'.format(a, b, c)) if mc == 53: print('for 53 McNuggets, "a"= {}, "b"={}, "c"={}'.format(a, b, c)) if mc == 54: print('for 54 McNuggets, "a"= {}, "b"={}, "c"={}'.format(a, b, c)) if mc == 55: print('for 55 McNuggets, "a"= {}, "b"={}, "c"={}'.format(a, b, c)) and the result was for 55 McNuggets, "a"= 1, "b"=1, "c"=2 for 53 McNuggets, "a"= 1, "b"=3, "c"=1 for 50 McNuggets, "a"= 2, "b"=2, "c"=1 for 53 McNuggets, "a"= 4, "b"=1, "c"=1 Or you can write a more elegant one: for a in range(1, 11): for b in range(1, 6): for c in range(1, 6): mc = 6*a + 9*b + 20*c if mc in range(50, 56): print('for {} McNuggets, "a"= {}, "b"={}, "c"={}'.format(mc, a, b, c)) i used range(50, 56) to include the value 56 know , i wanted to know the purpose of this code: > a=+1 > b=b+1 > c=c+1 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem
The " {} " is the place holder of the values of a, b and c argument passed to format. this example maybe can help to understand print('I like the python {}'.format('mailing-list')) will output >>> I like the python mailing-list The format methode will substitute the {} with the argument it takes. if you want to insert more than one string in the string 'I like python' you have to use multiple {} example: print('Il like the {} {}'.format('Python', 'mailing-list')) will output >> I like the python mailing-list you can google it under the term of "string formating python" and learn more if you want > 1) why is it printing backwards? it is giving that order of result because of the values that takes a, b, c in across the different iteration. the outer loop over the fisrt iteration gives set a to 1 the middel loop over the fisrt iteration gives set b to 1 the inner loop over the fisrt iteration gives set c to 1 and that dont give any result so the inner loop continue to run until it sets c to 4 witch gives the result of 55. this output is conditioned by the algorythm used > 2) why is it skipping 51,52 and 54? Are you shure those values are possible. Can you give me the values of a, b and c you calculated by hand for those different results? regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python memory management
Is there any practical usage of using reference cycling? On Sat, 2016-09-03 at 14:56 +0100, Alan Gauld via Tutor wrote: > On 03/09/16 04:25, monik...@netzero.net wrote: > > > > > Is this what you mean? > > a = 5 > > b = a > > a = b > > No, you are confusing variable names with objects. > Here you only have one object - the number 5. > For a cycle you need at least 2 objects and those > objects must be able to reference another object. > In practice that means a collection or an instance > of a class. > > a = [] > b = [a] > a.append(b) > > The two lists are now cyclically referring to each > other. We can now delete the names a and b and > the two list objects will continue to exist > in memory even though no variables refer to them. > This is where the second garbage collector comes > into play, it can recognise the link between the > lists and the fact that no variable refers to them. > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Question
I am working on a program where I found the line: x,y,z = np.loadtext('abcabc.txt', unpack= True, skiprows =1) What does the x, y, z thing mean? What does the unpack= True mean? Thank you -- Khabbab Zakaria Dept of Power Engineering Jadavpur University Calcutta India ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Fwd: How python keeps track of data types
-- Forwarded message -- From: Abhishek Kumar Date: 2016-03-29 7:15 GMT+01:00 Subject: Re: [Tutor] How python keeps track of data types To: Tutor@python.org Thanks everyone for answers and links.I wasn't aware of fact that python names are just references to Objects. Abhishek On Tue, Mar 29, 2016 at 1:01 AM, Abhishek Kumar wrote: > Hello > I am a computer science student,I want to know how python keeps track of > data types of variables and is there a way to get data types of variables > without actually running the script(with type() function). I think python > AST can help, but am unable to figure out.Please help me. > I've explored compiler library but could not find anything helpful. > > Thanks > Abhishek Kumar > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor Hi Abhishek You may also take a look at this video tutorials serie that was done by Doctor Philip Guo if you are iterested at looking to the python internal and how it works under the hood https://www.youtube.com/watch?v=ngkl95AMl5M&list=PLzV58Zm8FuBL6OAv1Yu6AwXZrnsFbbR0S Best regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Python OOP question
Hi, Other_hand seems to be a tuple object which is immutable (unchangeable) so you can't alter it. By the way, what other_hand is supposed to be? A variable that you declared as tuple? An instance of a class? As other people said to you, we can only guess because we don't see where "other_hand" is declared. Regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Understanding error in recursive function
Hi, I think your function runs forever because the only thing it done is calling it self when entering the for loop when you call your function in the for loop it jump to the definition (def howMany(aDict)) then initialise count and bond the value 0 to it then enter a for loop then call the function 'howMany' again and so on! before the for loop there is nothing happening to the function you defined or the argument is not modified in the recursive call, so i don't understand why you used a recursion there! i think you have to replace the howMany(aDict) in the for loop by aDict it self and it will be ok. for value in aDict: ... Regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Tutor Digest, Vol 146, Issue 9
Hi, there is one place i think you have to have a look at it and it's the python official site. One thing i love about python is the so well written documentation, i remember when i was learning ruby and had to go to the official doc! it was hard to understand for the beginner how i was. so, here is the link https://docs.python.org/3/tutorial/index.html Good luck Regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Behavior of dictionary in mapping keys that evaluate equal
Hi, Suppose we have a dict Dic = { True: 'yes', 1: 'No'} According to the Python 3 documentation, the keys must have a unique value so True is converted to integer because of the type coercion (boolean are subtype of integer) so boolean are winded to integer to be compared. Am I missing something? If that's what happen, why when running Dic.items() it return [(True, 'No')] instead of [(1, 'No')] ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Behavior of dictionary in mapping keys that evaluate equal
Steven D'Aprano wrote: > On Wed, May 11, 2016 at 02:00:47PM +0100, khalil zakaria Zemmoura wrote: >> Hi, >> >> Suppose we have a dict >> Dic = { True: 'yes', 1: 'No'} >> >> According to the Python 3 documentation, the keys must have a unique >> value so True is converted to integer because of the type coercion >> (boolean are subtype of integer) so boolean are winded to integer to be >> compared. > > No, not quite. Keys aren't converted to anything. The above is > equivalent to: > > Dic = {} > Dic[True] = 'yes' > Dic[1] = 'no' > > That part is straight-forward. But remember that True == 1: > > py> True == 1 > True > > and they have the same hash: > > py> hash(True), hash(1) > (1, 1) > > so as far as Python is concerned, they are the same key. The same > applies to the float 1.0: > > py> d = {True: 'yes'} > py> d[1] > 'yes' > py> d[1.0] > 'yes' > > > One last fact to remember: if the key is already found in the dict, it > isn't replaced. So: > > py> d = {1: 'no'} > py> d[True] = 'yes' > py> d > {1: 'yes'} > > > Does this now explain why > > {True: 'yes', 1: 'no'} > > returns {True: 'no'}? As Steven says, there is no conversion. The mechanism is completely general: The first of a sequence of equal keys wins. Here is an example with a custom class: >>> class Key: ... def __eq__(self, other): ... return other == 1 ... def __hash__(self): ... return 1 ... def __repr__(self): ... return "" ... >>> int(Key()) Traceback (most recent call last): File "", line 1, in TypeError: int() argument must be a string, a bytes-like object or a number, not 'Key' Even though there is no way to convert a Key to int the dict literals behave as with bool and int: >>> d = {1: "a", Key(): "b"} >>> d {1: 'b'} >>> d = {Key(): "a", 1: "b"} >>> d {: 'b'} Thanks a lot, what I was missing is the behavior of dict constructor, so that's gives me more understanding. Regards ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Downloading Slack Files
I noticed that you didn't store what requests downloaded in a new file you created. The usual pattern to use is to download a file and writing it to the HD drive. You have to create a file with "With open(file_name.extention, "wb") as f: " and write to that file. Here is the code that I suggest With open(filename, 'wb') as fd: for chunk in r.iter_content(chunk_size): fd.write(chunk) I apologize if the display of the email is messy since I am using Gmail on my phone. Le 17 août 2016 00:56, "Malcolm Boone" a écrit : > Hello everyone! > > I'm trying to run a python script that will download all files uploaded to > my companies Slack account from the past 30 days. I'm new to Python, so to > achieve this, I've just been editing a script that I use to delete all > Slack files from the past 30 days. > > Here is the code I'm using currently with error: > > import requests > import json > import urllib > import calendar > from datetime import datetime, timedelta > > _token = "REDACTED" > _domain = "REDACTED" > > if __name__ == '__main__': > while 1: > files_list_url = 'https://slack.com/api/files.list' > date = str(calendar.timegm((datetime.now() + timedelta(-30)) > .utctimetuple())) > data = {"token": _token, "ts_to": date} > response = requests.post(files_list_url, data = data) > if len(response.json()["files"]) == 0: > break > for f in response.json()["files"]: > print ("Downloading file" + f["name"] + "...") > timestamp = str(calendar.timegm(datetime. > now().utctimetuple())) > urllib.urlretrieve = "https://"; + _domain + ". > slack.com/api/files.list" + timestamp > requests.post(urllib.urlretrieve, data = { > "token": _token, > "file": f["id"], > "set_active": "true", > "_attempts": "1"}) > print ("DONE!") > > So far, when I run this script, all that appears to be happening is it's > printing a list of all of the file names. But from what I can tell, it's > not actually downloading anything. The internet in our office isn't the > greatest and it's printing a new file name every second, but since most of > these are video files, I know that it isn't actually downloading anything > in this amount of time. I've also tried searching my PC for any of the file > names, with nothing turning up. My HD space also goes through no change > after running the script. > > The other issue, is that the script never ends (probably a simple solution, > but again I'm pretty new to this). It keeps printing the list of file names > over and over until I manually close out of Python. > > Any help would be greatly appreciated! > > I'm using a Windows 10 PC running Python 3. > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Downloading Slack Files
Just replace r.iter_content(...) By response.iter_content(...) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Problem
Can you please rewrite the python code using proper indentation, since, as you know, indentation matters in Python Le 28 août 2016 18:40, "shahan khan" a écrit : Hello I'm teching myself Python using MIT opencourse ware. I'm a beginner and have some what knowledge of c and c++. I'm using Python version Here is the problem: McDiophantine: Selling McNuggets In mathematics, a Diophantine equation (named for Diophantus of Alexandria, a third century Greek mathematician) is a polynomial equation where the variables can only take on integer values. Although you may not realize it, you have seen Diophantine equations before: one of the most famous Diophantine equations is: xn + yn= zn. For n=2, there are infinitely many solutions (values for x, y and z) called the Pythagorean triples, e.g. 32 + 42 = 52. For larger values of n, Fermat’s famous “last theorem” states that there do not exist any positive integer solutions for x, y and z that satisfy this equation. For centuries, mathematicians have studied different Diophantine equations; besides Fermat’s last theorem, some famous ones include Pell’s equation, and the Erdos-Strauss conjecture. For more information on this intriguing branch of mathematics, you may find the Wikipedia article of interest. We are not certain that McDonald’s knows about Diophantine equations (actually we doubt that they do), but they use them! McDonald’s sells Chicken McNuggets in packages of 6, 9 or 20 McNuggets. Thus, it is possible, for example, to buy exactly 15 McNuggets (with one package of 6 and a second package of 9), but it is not possible to buy exactly 16 nuggets, since no non-negative integer combination of 6’s, 9’s and 20’s adds up to 16. To determine if it is possible to buy exactly n McNuggets, one has to solve a Diophantine equation: find non-negative integer values of a, b, and c, such that 6a + 9b + 20c = n. Problem 1. Show that it is possible to buy exactly 50, 51, 52, 53, 54, and 55 McNuggets, by finding solutions to the Diophantine equation. You can solve this in your head, using paper and pencil, or writing a program. However you chose to solve this problem, list the combinations of 6, 9 and 20 packs of McNuggets you need to buy in order to get each of the exact amounts. Given that it is possible to buy sets of 50, 51, 52, 53, 54 or 55 McNuggets by combinations of 6, 9 and 20 packs, show that it is possible to buy 56, 57,…, 65 McNuggets. In other words, show how, given solutions for 50-55, one can derive solutions for 56-65. Theorem: If it is possible to buy x, x+1,…, x+5 sets of McNuggets, for some x, then it is possible to buy any number of McNuggets >= x, given that McNuggets come in 6, 9 and 20 packs. Here is my code: for a in range(1,10): for b in range(1,5): for c in range(1,5): mc=(6*a)+(9*b)+(20*c) if mc==50: print a,b,c else: print a,b,c a=+1 b=b+1 c=c+1 and this is the output: 1 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4 2 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4 3 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4 4 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4 5 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4 6 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4 7 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4 8 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4 9 1 1 1 2 2 1 3 3 1 4 4 1 2 1 1 3 2 1 4 3 1 5 4 1 3 1 1 4 2 1 5 3 1 6 4 1 4 1 1 5 2 1 6 3 1 7 4. Can someone please tell me whats wrong with my code?. I'm using for loops to give possible valutes to a,b and c and then using the equation (6*a)+(9*b)+(20*c) to determine possible values for a,b and c for satisfying the equation. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Inheritance vs Assignment
Assignment and inheritance are not comparable at all In the inheritance you are extending the base class (a) and in "a=b()" you are instantiating it - you create an object according to the blueprint that you difining. To understand the difference. Inheritance: Say you defined a costume type (a class ) and classes are really that. After that you needed an other kind of object that share the same code with "class a" with additional attribute and actions you want to apply to them. Instead of duplicating the code in "b" just inherit from "a" and write your extra code in "b" and you are done. You still need to instantiate "b" to get an object and work with. Assignment is a different thing that doesn't have any thing to do with inheritance, since what you are doing here is creating an object in the memory and binding it to a name to access it later. Is that make sense? Now I can see some interest in using the "b inherit from a" that way. It's a common technique to just inherit from an exception class to just catch an exception with a meaningful name. The second case that I see is that when using multiple inheritance that's allow you to linearize the parents classes to get the code works. Since I am responding from a smartphone, It's tedious to expand the explanation, I wanted to give you an overview of some concepts and ideas on how they work. Google working with exceptions and you'll get a tons of tutorials that shows you how it works. And search a talk about "super" named "super consider super". It'll give you more information about the inheritance model of Python, especially the multiple inheritance model and the "method resolution order called 'mro' ". I hope that helps you. If it doesn't, just ask again. Regards. Le 1 sept. 2016 09:51, "kay Cee" a écrit : > > Suppose there is -> > > Class a(): > def__init__(self, var): > pass > > Class b(a): > def__init__(self): > super().__init__(self, var) > pass > > Note: syntax may be incorrect ... > > Is it better to do > > b = a() > > Instead of making b its own class? > Also, what would be the benefit of making a separate class for b if any at > all? > > Thanks in advance > > Unee0x > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Inheritance vs Assignment
Let me clarify some ideas that I spoke about in my last email. I talked about extending exception and linearization from the perspective of inheriting from a class without adding behavior or some extra attributes, because the code you provided was doing that. Reading the Alan response made me realize that my last email wasn't very clear and can lead to validating bad implementation. So to clarify. Extending classes without adding behavior can be useful in custom exception or resolving problems with super() by linearization of the parents classes. The implementation is a different thing. We do that by defining an abstract class that inherit from its parent. We do that that way class B(A): pass And no need to a second init method and calling super on it because instantiating the B class will call implicitly the __init__ of it's parent But as Alan mentioned before, maybe your purpose was to give just an example to explain your question. Regards. Le 1 sept. 2016 11:28, "Alan Gauld via Tutor" a écrit : > On 01/09/16 04:18, kay Cee wrote: > > > Class a(): > > def__init__(self, var): > > pass > > > > Class b(a): > > def__init__(self): > > super().__init__(self, var) > > pass > > > Is it better to do > > > > b = a() > > > > Instead of making b its own class? > > Also, what would be the benefit of making a separate class for b if any > at all? > > I'm afraid your question is too abstract to answer. > The use of classes depends on the context and in this > case we have no context on which to base a judgement. > > Looking strictly at your code it makes no sense to > have either a or b as classes since there is no > state (variables) involved and no operations(methods) > are provided. Both are zero impact classes. But I'm > guessing you intended that to be indicative of a > more complex scenario. > > In general, inheritance is used to specialise a class. > It should be true to say that b *is an* a. > So if b were to add some specialized content > to 'a' then inheritance would make sense. > > But b = a() makes b an instance of 'a' not a class. > So the two things are entirely different, it's like > asking which is better: a mountain or Mount Everest? > > > -- > Alan G > Author of the Learn to Program web site > http://www.alan-g.me.uk/ > http://www.amazon.com/author/alan_gauld > Follow my photo-blog on Flickr at: > http://www.flickr.com/photos/alangauldphotos > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] What's the correct way to define/access methods of a member variable in a class pointing to an object?
Hi, Composition is a technique that allows you to express the 'has a' relationship between your object. I'm not a specialist of the OOP but I can see some issues in the model that you expose in your mail. Encapsulation and abstraction are all about designing an API. It allows you to expose simple usable API'S and hiding all the complexity from the user of your classes. If a user have to use your classes in inheritance or composition, he/she doesn't have to worry about the internal details. Wrapping methods of class Foo is a good thing I think. In the case you don't use encapsulation: If Foo is used in Bar, Bat, Baf and after that, the three classes are used anywhere in your code, if you change the API of Foo, you'll end up making changes in all the places where Foo is mentioned! and that's tedious Now, if you use encapsulation The same scenario is not a big deal anymore because you'll end up making less changes than before. That's makes the life easier Abstracting irrelevant details also makes the process of developing easier because you don't have to deal with low level of details to make a code working and helps you to reason about your code in a more efficient way. That techniques lower the level of complexity you have to deal with. I hope that helps a little bit. Regards. Le 3 sept. 2016 10:24, "Sharad Singla" a écrit : > Hi Pythonistas > > What's the correct way to define/access methods of a member variable in a > class pointing to an object? > > For example, I have a class Foo that has a method foo_method: > > class Foo: > def foo_method(self): > return 'bar' > > Now, in another class Bar, I'd like to store an object to this class (I do > not want Bar to inherit Foo). > > What is the correct/recommended way to define class Bar? > > class Bar: > def __init__(self): > self.foo = Foo() > # OR > class Bar: > def __init__(self): > self.foo = Foo() > > def bar_method(self): > return self.foo.bar() > > The former will allow me to use: > > x = Bar() > x.foo.foo_method() > > But, with this I'm directly accessing methods of a member variable (strong > coupling). > > The benefits I see with this approach are: > >- I don't have to wrap every new method that gets added to class Foo. >- Bar may contain more member variables pointing to other classes. Not >wrapping them keeps Bar smaller and manageable in size. >- The auto-completion facility from IDE (PyCharm, etc.) or IPython helps >inspect bar like a menu (x.foo) followed by a sub-menu ( >x.foo.foo_method(), x.bar.foobar(), etc.) making it easier to develop >code. >- Functional programming look-n-feel (not sure if this a pro or con) > > The cons are strong coupling, not encapsulating internal details of foo, > etc. > > I wanted to check if this a recommended practice? And/or if there are any > guidelines related to this (kind of implementing a composite pattern)? > > There may be more classes (Bat(), etc.) in future and I'd like to extend > Foo in future to store an object of these classes. Foo() is a part of a > library and my intent is to make Foo() as the entry point for the target > users (to allow them auto-completion via dotted notation) rather than > having them remember all the classes Bar(), Bat(), etc. > > Any inputs/pointers will be highly appreciated! > > > Regards > > Sharad > > > PS> I've posted this in SO at > http://stackoverflow.com/questions/39231932/whats-the- > correct-way-to-access-methods-of-a-member-variable-in-a- > class-pointin/39237874#39237874 > but I'm looking for more information/ideas/thoughts/opinions on this. > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] global interpreter lock
Basically, what that said is the global interpreter lock is something that allows only one thread at a time to be executed when you launch a python program in opposition of executing multiple threads at the same time (parallelism). when you launch a python program it create a process in memory. because of the GIL you cannot do parallelism in an efficient way, but if you are not using threads, you shouldn't care about. The GIL was relevant when we had one processor in our machine and honestly it facilitate the development of the core maintainers of the CPython. Now we have multicore processor, it start to be restrictive for some people, not all but some of them who need to compute data and want to use all the power they have. Instead of giving you some examples I'll give you a link of some great presentations made by David Beazly Understanding the GIL: https://m.youtube.com/watch?v=Obt-vMVdM8s Embracing the GIL: https://m.youtube.com/watch?v=fwzPF2JLoeU Concurrency from the ground: https://m.youtube.com/watch?v=MCs5OvhV9S4 This guy will explain to you better than I I'll do. Hope that helps. Regards. Le 15 sept. 2016 09:18, "anish singh" a écrit : > Can someone explain global interpreter lock with > some source code examples? > > I didn't understand explanation offered here: > https://docs.python.org/3/glossary.html#term-global-interpreter-lock > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] file opened by open() are closed automaticaly
Hi, I am playing with python3.6 and i noticed a change in the behaviour of the open() builtin function. The file opened using open() is closed automaticaly after iterationg over it in the python shell Here is the dummy code i am using: # Beggin testfile = open('test.txt') for line in testfile: print(line) # End the first time the code runs well and gives me the expected result. the secod time that i run the loop, nothing is printed on the screen. when i type: testfile.close and press the tab key to autocomplete: here is what i get >>> testfile.close( testfile.closed when i run that commande and ignore the message: testfile.close() nothing is prined on the terminal, and python runs the commande as if the file is still opened. i searched in the doc and this behaviour is not documented. I don't now if it is a bug or i didn't search in the right place. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] file opened by open() are closed automaticaly
Thanks a lot. that helped me to understand that behaviour. Best regards. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor