Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    Hi Dave, I have attended "Advanced Python Programming" online sessions of your's. Thanks so much for opening up this forum. It helps a lot.
    David Beazley
    @dabeaz
    @skgBanga_twitter I feel that Curio is better served by be smaller and having a smaller API. A lot of things got removed in the transition to v1.0, this being one of them. Part of why it got removed is that it was already a one-line function that called await sleep(0). The other reason is that forcefully causing a context switch isn't something that seems to be required all that often. Also, if someone wanted to call it schedule(), they could make their own one-line function with that name.
    Sandeep Gupta
    @skgBanga_twitter
    @dabeaz that's fair. thanks!
    SandeepSuryaprasad
    @SSuryaprasad_twitter

    Hi Dave,
    I have the following code.a = 'hello!'

    b = 'hello!'
    a is b
    False
    id(a)
    140428602876016
    id(b)
    140428602876208
    Why does python creates two different string objects in the above example. But when you do not have any special character it does not create two new string objects. >>> a = 'hello'
    b = 'hello'
    a is b
    True

    David Beazley
    @dabeaz
    The optimization for not creating a new string only applies to strings that are valid identifiers (i.e., valid variable names).
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    Thanks Dave.
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    I am iterating over a list which has one million items in it and also I am iterating over a tuple which has one million items. When I measure the time taken by list and tuple, there is negligible difference. Some times lists are faster by few milli seconds and some times tuples! When I looked up in stack overflow, it says tuples are little bit faster than lists.
    David Beazley
    @dabeaz
    Tuples might be faster than lists for certain things (creation perhaps), but it's hard to see how there would be any difference at all for iteration given the similarity of implementation.
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    Thanks for your reply Dave.
    Damian Shaw
    @damian_shaw_gitlab
    I am considering joining "Holiday of Compilers!". Is it in danger of filing up in the next week? I'm applying for a tuition reimbursement program my company offers but they require I apply for approval first before I sign up to the course, just submitted the paperwork and am informed it usually takes 5 days to decide on approving
    David Beazley
    @dabeaz
    You should register now. I don't require any payment at time of registration.
    David Beazley
    @dabeaz
    I hold spots all of the time for people waiting for approval. Register first. Then ask permission.
    George Fortunatov
    @qweeze
    Hi @dabeaz :)
    I enjoy watching your talks a lot!
    I was inspired by your experiments with generators and coroutines, and came up with a weird idea of making a function behave both like a normal function and like an async coroutine (kinda). So I thought I might share it here - https://github.com/qweeze/maybe_async
    It would be super cool if you could share your advice or any kind of feedback.
    Vitaliy Litvinov
    @vitalizzare_twitter
    Hi! I came here to say that the Function is a very nice and neat essay. I learned a lot of subtleties in a fairly short time. I like it. Thanks!
    David Beazley
    @dabeaz
    Glad you liked it! (although I was definitely in a strange mood when I recorded that ;-)
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    Dave, I found that instance dictionaries occupy less memory than the normal dict! I have a point class with two instance variables "a" and "b" with values 1 and 2 respectively. When i checked the size of the instance dictionary (using getsizeof()), it came back with 104 bytes. I created a normal dictionary with same keys and values , this time when i checked the size of the dict, i got 232 bytes! Are instance dictionaries more memory efficient than normal dictionaries?
    David Beazley
    @dabeaz
    Yes! (You have a keen eye). See PEP 412. https://www.python.org/dev/peps/pep-0412/
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    Okay.. Thanks Dave.
    cmoher3
    @cmoher3

    Went to pick up an item I won at auction today. As there are Covid delays everywhere, I always bring along something to read. Today it was O'reilly's Python Cookbook, which I had on my dash as I approached the gate keeper. Seeing the book he asked if it was any good. Me wearing a mask and he deaf and only able to read lips, hard to do when we are all wearing masks, I gave him my OK hand gesture. He then went on with a fairly long story of the different snake dishes he had eaten in Florida. I listened with interest until he had finished with the "Soupa Serpente" (Snake Soup) he had in Mexico and for him to ask if there were any favorite python recipes in my book. I finally pulled down my mask and mouthed "No, Computers" and mimicked me typing on a keyboard. He replied that he'd search the internet when he got home for recipes and waved me through.

    Have a Merry Christmas David and stay well.

    David Beazley
    @dabeaz
    This reminds me of the time I told the people in the restaurant I frequent across the street from my office that I wrote the "Python Cookbook." They were highly amused.
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    Constructing a list using list constructor takes less memory than constructing the same list using append method! list(range(10000000)) takes (359992868, 359993060) and using append method it takes (361520804, 361520852) I used tracemalloc to measure the memory.
    David Beazley
    @dabeaz
    Many objects are able to give the list constructor a size hint about how many objects it will contain. Without this, append() tends to slightly overallocate memory since it grabs memory in increasingly large chunks as the list grows in size.
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    Thanks Dave..
    SandeepSuryaprasad
    @SSuryaprasad_twitter
    Can we consider "ceval.c" as a python virtual machine since it is executing compiled byte code.
    Stephen Harding
    @stharding
    Dave, any plans to post any more video series to oreilly?
    David Beazley
    @dabeaz
    No plans for videos at this time.
    Kamil
    @UltraInstinctPL_twitter
    Hey Dave, what about 4th edition of Python Cookbook? Any plans?
    David Beazley
    @dabeaz
    It's extremely unlikely that there will be a 4th Edition Cookbook. Not my me anyways. Sorry.
    Christian W.
    @cew8
    I think I sort of answered my own question. Removing.
    Shivam Vikal
    @sunkgp
    Hi David,
    Chapter 10 - Execution Environment: "The -m option runs a library module as a script which executes inside the main module prior to the execution of the main script". Really can't get my head around what you meant by 'prior to the execution of main script' at the end of the statement. I've tried looking all over the internet for this but can't get any explanation. Would be grateful if you could explain this to me. Thank in advance
    yehnan
    @yehnan
    Hi, Vikal, maybe try the official document: https://docs.python.org/3/using/cmdline.html
    Shivam Vikal
    @sunkgp
    @yehnan thank you for your reply. but the docs do not answer my specific query regarding what David meant by his statement in his book.
    David Beazley
    @dabeaz
    It looks like poor wording to me. The -m option basically runs a module (as would ordinarily be found using import) as the main program.
    Shivam Vikal
    @sunkgp
    @dabeaz I am glad you replied David. This was bothering me for quite some time now. This certainly makes it clear now.
    loneshark99
    @loneshark99
    I have been a long term c# developer but got into python and saw youtube video of David. Really great style of explaining concepts. I got the cookbook and have been learning a lot of new and intuitive way of doing stuff. Thank you David.
    Damian Shaw
    @damian_shaw_gitlab

    With all this discussion of annotations on Python dev I came up with this syntactically correct way of initializing variables in Python that dynamically applies the correct type at run time:

    foo: type(foo := 1)

    Of course 1 here could be a function call or any other expression you like. It made me think a lot about what exactly are annotations? And how PEP 563 changes them from the arbitrary expressions they are now to more glorified in-line doc strings. Not sure anyone else is thinking much about this, but this is where my brain has been for the last couple of days.

    yehnan
    @yehnan
    I noticed that the publish date of the book Python Distilled changed from 30 April to 30 July.
    yehnan
    @yehnan
    On Amazon.com.
    David Beazley
    @dabeaz
    I'd be very surprised if it were available by July 30. The book is basically written, but is still being reviewed and production is only just starting.
    Davide
    @davideclode
    Hi everyone
    Davide
    @davideclode

    Hello Mr. David M. Beazley, first of all I wish you great health.

    I am using your book as study material. I have a simple example of a C program that must be recognized by the parser (using this code as base https://github.com/dabeaz/ply/blob/master/example/classcalc/calc.py).
    The example fo C program that must to be recognized is as fallow:
    int main(void)
    {
    int a, b, resultado;
    a = 4;
    b = 6;
    if(a>= 10){
    resultado = a - b;
    }else{
    resultado = a + b;
    }
    }

    Could you help me understand how to embed this into the code in the link I sent you?

    Cordially ,

    Davide Clode da Silva
    Federal University of Santa Catarina - Brasil

    yehnan
    @yehnan
    Well, the publish date of <<Python Distilled>> on Amazon changed again to 27 Sep. Does Addison-Wesley has some thing like "early release" of O'Reilly?
    David Beazley
    @dabeaz
    I have no idea. Sorry. The delays are mostly on my end anyways. Working on this during the pandemic and everything else has been no picnic. I can say that the entire book is in the production pipeline at the moment however.
    yehnan
    @yehnan
    No worries. I'll focus on Software Design for Flexibility first.
    Bob McDonald
    @ultrabob_gitlab
    I'm going through the Practical Python course to get a refresher on a few things, and in section 7.2 on anonymous and lamda functions I get AttributeError: 'Portfolio' object has no attribute 'sort' when I try to run portfolio.sort(key=stock_name) or any kind of sort on the portfolio object. That file is identical to the solutions with the exception of how total_cost is calculated and some line breaks. What could it be?
    David Beazley
    @dabeaz
    The sort() method is only going to work on lists. So, you'd probably need to go back to earlier code that used lists instead of Portfolio. You might also be able to use the sorted() function as an alternative.
    Bob McDonald
    @ultrabob_gitlab
    Thanks very much for the quick response! I had thought that might be the case and could have sworn that the example was loading the portfolio from report.py, but going back and looking again it appears I was mistaken. Thanks for the very helpful course.
    Bob McDonald
    @ultrabob_gitlab
    I'm working on exercise 8.2 in the practical python course, and no matter what I do, I cannot get the debug log items to show up. I tried using the setLevel() method instead of setting the level property directly, I tried setting the level directly in fileparse.py instead of later in the console. I can print the logger and confirm that it is set to debug level. I've also tried setting it to info level just to see. In no case does it ever print the log.debug messages. Is there something like an environment variable that can prevent lower level log messages from being output? I'm sure I must be doing something silly, but I can't figure out wehat it might be. Even if I copy the solution file for 8.2 fileparse I get the same results.
    I found this stackoverflow post that indicates one more config step is required. I followed that and the debug messages started being output: https://stackoverflow.com/questions/43109355/logging-setlevel-is-being-ignored
    Bob McDonald
    @ultrabob_gitlab
    Ah darnit, I missed a line in the console example, sorry. In case someone else happens to be in here with the same issue before it scrolls into oblivion. After import logging, you need logging.basicConfig()