Stop Using Print in Python

Поделиться
HTML-код
  • Опубликовано: 11 янв 2025

Комментарии • 143

  • @codewithjoshoffical
    @codewithjoshoffical  2 месяца назад +2

    👉 Join my Python Newsletter ~ www.thenerdnook.io
    👉Join our Discord Community ~ discord.gg/dvrcpXSwyc
    👉Get my Python Courses, Free ~ zerotoknowing.gumroad.com

  • @karthik448
    @karthik448 2 месяца назад +174

    Would be helpful if you can make your videos more concise. You don't need a 10min long video to say use ic instead of print. Too much fluff is usually not helpful in the long run.

    • @Joooooooooooosh
      @Joooooooooooosh 2 месяца назад +20

      I'm gonna use print twice as much now.

    • @amitkjha
      @amitkjha 2 месяца назад +4

      He did mention to use IC around 1 min. That’s not very long I would say.

    • @LT-uq6dg
      @LT-uq6dg 2 месяца назад +7

      But then he wouldn't make much from ad revenue 🤷

    • @Pseudothink
      @Pseudothink 2 месяца назад +6

      10 minute videos with 30 seconds of value are all about satisfying The Algorithm.

    • @purplemonkeydishwasher5269
      @purplemonkeydishwasher5269 Месяц назад +5

      I'm a novice programmer, so I'm happy for someone to take 10minutes to go through the build

  • @fus3n
    @fus3n 2 месяца назад +66

    first problem you can use f-strings if you don't wanna add unnecessary modules
    a, b, c = 3, 5, 75
    print(f"{a=} {b=} {c=}")
    # output: a=3 b=5 c=75
    Adding an equal after variable name will also print the variable name along with the value

    • @codewithjoshoffical
      @codewithjoshoffical  2 месяца назад +9

      You're right! I covered this tactic in my f-strings video already, if you don't want unnecessary modules then sure.
      ice cream is still less typing than f-strings though and the added ability to disable it which we can't do with print

    • @fus3n
      @fus3n 2 месяца назад +6

      ​@@codewithjoshoffical honestly if someone wants to turn off, they should use the logger module built into python, has more features.
      Can do the same things with extra features.

    • @angelsaint6555
      @angelsaint6555 Месяц назад

      @@codewithjoshoffical this is 101 python how u dont know that xD

  • @mikhailmcrae5924
    @mikhailmcrae5924 Месяц назад +7

    Print is redundant. Replaces print with redundant code. Print is slow. Imports a module.

  • @Stiffsen
    @Stiffsen Месяц назад +22

    One should use neither print, nor icecream. Pythons built-in logging module is the defacto way too go here, with different log levels, ability to pipe to different outputs. Combine that with f-strings and you got everything you need.

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад +6

      Yup, True! I find ice cream to be a fun module but on a larger scale logging is far superior. I've been listening to you guys in the comments and I've got a logging episode in the works now 😁

  • @BRLN1
    @BRLN1 Месяц назад +3

    I see 3 major use cases for print:
    1) you are learning python and you literally print out all the answeres to your programming excercises
    2) you are writing a comand line tool
    3) for debugging
    Print is fine to all those use-cases. Only in case of 3) you should switch to proper logging at some point
    In any case I don't really see the point of icecream. It does a slightly better job (at best) for the cost of another third-party library .... meh

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад

      You’re right, while it’s fun and all I think the best use case is #1 as you said, working on programming exercises. Maybe a little debugging but logging still has it beat

  • @nathanielcallejas
    @nathanielcallejas Месяц назад +2

    I was highly skeptical when you said never use print again, but then my mind was blown when you showed me the ice cream!

  • @donjindra
    @donjindra 2 месяца назад +13

    I don't know why print doesn't give you the information you need. It always gives me the information I need. So, no thanks to an extra module. Btw, speaking of redundant, you repeat yourself too much.

  • @vickoza1
    @vickoza1 Месяц назад +4

    The print function should be used for user output, not for debugging. icecream is better as a debugging tool but break-points as looking at variables should be better.

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад +1

      You’re right, print statements are more for user output while learning code but in real world applications we aren't using print for our own sake more for lazy debugging 😆. That is why I think Ice Cream is pretty cool, print on a new level.

  • @shinstorm3473
    @shinstorm3473 2 месяца назад +3

    Great vid I'm absolutely going to use this from now on. Thanks buddy

  • @brokencooking
    @brokencooking 2 месяца назад +3

    Love your content Josh! Big thank you!

    • @codewithjoshoffical
      @codewithjoshoffical  2 месяца назад +1

      Absolutely, thanks for being here! I’m glad you like it 😁

  • @jeffdavies2824
    @jeffdavies2824 Месяц назад +2

    Great tip. Long time SW Eng here, but fairly new to Python. This is definitely a better approach than print()!

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад

      Thanks! Definitely a fun module, for larger scale projects logging module is probably better

  • @ShaunDaniels-uq8mi
    @ShaunDaniels-uq8mi 2 месяца назад +7

    You can do this with f strings, no need to import another library.

    • @codewithjoshoffical
      @codewithjoshoffical  2 месяца назад +2

      Yup you’re right too, I covered that in an f-strings video too!
      Perk of this is you can disable it without have to delete it all 😁

    • @vliopard
      @vliopard Месяц назад

      ​@@codewithjoshoffical I wrote an iprint function that uses f-strings and print, which I can disable. The advantage of my own function is that I can customize my output using regional formats and various colors with colorama. I can also create horizontal separators (lines) with the terminal's width automatically. With icecream, I am limited to what the author provides. They choose the color, format, indentation, etc. In general, I prefer creating my own solutions using the basics.

    • @ClemensHolleis
      @ClemensHolleis Месяц назад +1

      ​@@codewithjoshoffical you could disable print on top of your function (or file) replacing it with an empty lambda function like this:
      print = lambda *args, **kwargs: None
      combine this with f string printing for labels like print(f'{x=}') and you get basically the same functionality and workflow with only builtin python modules

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад

      @@ClemensHolleis This is interesting! Thanks for sharing

  • @ErnestGWilsonII
    @ErnestGWilsonII Месяц назад +3

    Thank you for making this video and sharing it with all of us.
    Some constructive feedback:
    In production, we would not prefer to use ice cream or any other third-party module.
    Use the python logger and set logging levels and format.
    Then you can have a standard and you can toggle things on and off by setting the logging level to debug or set the logging level to whatever you desire while you’re programming and turn off debug mode when you go into production.
    I did like the fact that ice cream automatically informed on which variable was being printed.
    Maybe a combination of using ice cream and the python logging module would make an even nicer solution?
    I will give it some thought.
    Either way, I gave this video a thumbs up, and I subscribed for more!

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад +1

      Thanks for your comment! Also you are so right, I find ice cream to be a fun module but on a larger scale it can't compete with logging. I've got a logging episode in the works now! Anyways, have a great day 😁

  • @valentinrafael9201
    @valentinrafael9201 2 месяца назад +2

    So, use an abstraction, like icecream , which uses other abstractions, like pprint + others, who are just abstractions over the print function, which itself is an abstraction on top of C?

  • @malcolmanderson6735
    @malcolmanderson6735 2 месяца назад +6

    F Strings cover most of this functionality. When I saw "So using print" I assumed the video was going to be about logging.
    Keep putting out videos.

    • @codewithjoshoffical
      @codewithjoshoffical  2 месяца назад

      Thanks, yeah can be done with f-stings which I covered in a past video.
      This is just a helpful module and the fact that it can quickly be disabled is a huge plus 😄

  • @nuynobi
    @nuynobi Месяц назад +1

    Whoa whoa WHOA! What dark wizardry is this at 7:20? Please explain how you did that.

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад +1

      I’m on a Mac, when you hold command you can click to multiple places at once 😁

    • @TheDonutGuy0
      @TheDonutGuy0 28 дней назад +1

      you can do this on vs code. just select the word and right click and edit all occurrences .

  • @agentm10
    @agentm10 2 месяца назад +2

    Interesting module, reminds me of C macros used for debugging. For python I usually use pdb and logging for debugging. Will try out ic to see what difference it makes. Thanks for the video.

    • @codewithjoshoffical
      @codewithjoshoffical  2 месяца назад +1

      There’s so many modules I lose count 😂

    • @agentm10
      @agentm10 2 месяца назад

      @@codewithjoshoffical actually, a tutorial on pdb could be quite useful for beginning python students. Students learning C learn about debugger (like GDB) and linters fairly early, but from my experience, python students don't get to see pdb, logging, pytest, and pylint until much later in their learning cycle.

  • @malathinaik1971
    @malathinaik1971 2 месяца назад +2

    Thanks Josh I was looking for this 😂❤

  • @Yafet-e2j
    @Yafet-e2j Месяц назад

    Wow that is interesting, thanks for sharing. What kind of environment you are using for this module

  • @lucietee2296
    @lucietee2296 2 месяца назад +1

    Haha, nice one! love your humor as always!

  • @GereHadush
    @GereHadush 2 месяца назад +1

    Cool tool. Thank you for sharing such wonderful tips

    • @codewithjoshoffical
      @codewithjoshoffical  2 месяца назад

      Thank you! I hope you can have some fun with this one 😁

  • @venkatabhi7169
    @venkatabhi7169 Месяц назад +3

    IC is much better than print ()
    Thanks 👍

  • @dsarons
    @dsarons День назад +1

    Oh come on, debugging the the fun part 🙃
    ic does save the formatting of the print stmts with the auto labels - good to know.

  • @kreont1
    @kreont1 Месяц назад +1

    What is perfomance IC vs Print ???

  • @subhamgiri2000
    @subhamgiri2000 Месяц назад +2

    Thanks Man you are awesome

  • @AashAli-d7b
    @AashAli-d7b 2 месяца назад +2

    Can you make discurd channel to learn pyton together

  • @senrimizoe1253
    @senrimizoe1253 2 месяца назад +1

    Thank you. Helpful hint to pynoobs.

  • @Pawlo370
    @Pawlo370 Месяц назад +1

    ok I'm not using print:
    import sys
    sys.stdout.write("Hello world!")

  • @ilirshabaku.youtube
    @ilirshabaku.youtube Месяц назад +1

    Perfect.
    Thank you

  • @cbbcbb6803
    @cbbcbb6803 Месяц назад

    I hears somewhere that the RUclips algorithms are friendlier to the poster if fluff is added.

  • @__christopher__
    @__christopher__ 2 месяца назад +1

    If your console is flooded with debugging output, I think you are doing something wrong. If I use print for debugging, I add very few lines. Ant typically remove them as soon as the problem is found, as I don't want to have thau now useless output disturb me while debugging another problem.
    If the output may be useful for debugging later on, the right way to do it is through logging.
    And no, I won't stop using print because my programs often print as part of their normal operation.

  • @h2w..
    @h2w.. Месяц назад +1

    "Dont use print it is slow!" Instead "use print with additional serialize to stringr" 😂

  • @smartwashington1455
    @smartwashington1455 2 месяца назад +1

    🎉excellent, thank you so much

  • @jhengroup
    @jhengroup 2 месяца назад +1

    Really cool. Thanks.

  • @Mathguy1729
    @Mathguy1729 Месяц назад

    So where do I get the icecream module? You said a bunch of stuff about how good ic is and didn’t mention how to obtain it…

  • @ueihgnurt
    @ueihgnurt Месяц назад

    Python Debug Log: All of that just for a bit of a log

  • @azzazulius
    @azzazulius Месяц назад +1

    if you like icecream, rich will mos def blow your mind

  • @Chalisque
    @Chalisque 2 месяца назад

    ic is nice, but is yet another dependency, and something that needs to be installed. You are guaranteed that print() is available. And of course print gives you much more control over what is actually printed.

  • @ALVSTORIES
    @ALVSTORIES Месяц назад +1

    Logging is the best

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад

      Yeah, I’ll try to get a logging episode sometime here for you all

  • @alandmcleod5988
    @alandmcleod5988 Месяц назад +1

    this is good!

  • @eddieherrera951
    @eddieherrera951 Месяц назад

    When you printed the data it looked like the data was reversed ?

  • @sridiptah3186
    @sridiptah3186 Месяц назад +1

    thank you!

  • @mattstroker
    @mattstroker Месяц назад +1

    Im probably the biggest n00b out here but that is very useful. I shouldn't learn myself bad habits but once learned i can imagine this being useful. Lemme continue on my text adventure game using print now.... 😁😅😊

  • @ENetArch
    @ENetArch Месяц назад +1

    Ok, so use a library to replace the print statement. The library extracts the name of the variable, and prints the value of the variable .. using a print statement.

    • @toddkes5890
      @toddkes5890 Месяц назад +1

      Sounds like the EVALUATE statement from COBOL

  • @thesattary
    @thesattary Месяц назад +2

    import icecream as print :) haha

  • @ansahbritwum6439
    @ansahbritwum6439 Месяц назад

    Pls can you do a video in Dart programming language.

  • @davidlu1003
    @davidlu1003 Месяц назад +1

    Thx.😁😁😁

  • @andytraiger4079
    @andytraiger4079 Месяц назад +1

    Great. Now I'm going to gain a lot of weight. Every time I type and ice cream statement I'm going to start craving ice cream. Why couldn't it be called "vomit?"

  • @MrFrondoso
    @MrFrondoso Месяц назад +1

    Chouette! Merci

  • @mdsegara101
    @mdsegara101 2 месяца назад +1

    4 minutes long is more than enough for this video.

  • @el_pato_manco
    @el_pato_manco Месяц назад +1

    just use the damn debug

  • @stevenshrii
    @stevenshrii Месяц назад +1

    Sherbert?

  • @RAHUDAS
    @RAHUDAS Месяц назад +1

    What r u out of your mind , why would I do that, print is simpler and without any 3rd party dependency.

  • @ParalyticAngel
    @ParalyticAngel 29 дней назад

    Does Python not have a debugger or what?
    If your programming language doesn't have a debugger, you can use print() (or something similar) to debug. Of course, in all other cases you should use the debugger. You debug and your code remains untouched. There's nothing to think about.^^ However, for longer periods of time it makes sense to also use unit tests. They are not really suitable for debugging, but are very useful for finding hidden errors during further development. By the way, I really don't like Python. In my opinion it is only suitable for mathematically compliant calculating and plotting. ^^ I learned to program using Java, a mature programming language, but my favorite language is probably C/C++. Incredibly efficient and if you really want to master programming, C is a must. You will learn so much more about what programming really is and about the PC and how it works.

  • @leahnjr
    @leahnjr 2 месяца назад

    Would be nice to see some benchmarks. I'd also shy away from saying never do this or always use this. Different scenarios call for different tools. Two minutes in before you got to the content.

  • @TheSlimbee
    @TheSlimbee Месяц назад

    Write a function called p()

  • @XEONFX23
    @XEONFX23 2 месяца назад +1

    What if your name is Josh. 🤔 Does that make him Code?

  • @JoeBarr-b5v
    @JoeBarr-b5v Месяц назад +1

    lol I thought this would be a logging module video

    • @codewithjoshoffical
      @codewithjoshoffical  Месяц назад

      Not yet, this was for fun. Logging module will drop soon ✌🏼

  • @johnmoff9324
    @johnmoff9324 2 месяца назад +1

    Ever heard of f-string?

    • @codewithjoshoffical
      @codewithjoshoffical  2 месяца назад

      Yes, I’ve covered this in another video but still more typing and can’t be disabled 😁

    • @johnmoff9324
      @johnmoff9324 2 месяца назад +1

      @@codewithjoshoffical ah you should have started this video with a statement like, "hold on to your pitchforks people, bear with me this does more than f-string" most persons will likely ignore and not watch the whole video cause you are basically telling them to use a library for something f string does. Anyway this is not on you but the name of the library couldn't be worse for its use, ice cream?

  • @TeckTales
    @TeckTales 2 месяца назад +1

    Very nice..

  • @luisflores616
    @luisflores616 2 месяца назад +1

    Nice🎉🎉🎉

  • @girishkuvalekar3965
    @girishkuvalekar3965 Месяц назад +1

    Nice

  • @zuxel6
    @zuxel6 2 месяца назад

    stop calling to stop

  • @eboyd53
    @eboyd53 2 месяца назад +1

    If you don't want to go through and change all of those "print" statements to "ic" you can reassign print to be ic during the import.
    ```from icecream import ic as print```

    • @codewithjoshoffical
      @codewithjoshoffical  2 месяца назад

      This is a fantastic point here! Absolutely correct and still works!

  • @venomplays_official7560
    @venomplays_official7560 Месяц назад +1

    🫡❤

  • @MusiGod
    @MusiGod Месяц назад

    im 2 min into the video and he is still yapping about something i dont even care about, dude i came here to watch wats in the title not your yapping

  • @mrnabby4178
    @mrnabby4178 Месяц назад

    Stop using python.

  • @SamJ-l8p
    @SamJ-l8p Месяц назад +1

    WTF 🔥

  • @camzilla8733
    @camzilla8733 Месяц назад

    WOT

  • @randyriegel8553
    @randyriegel8553 2 месяца назад

    first problem is using Python.

  • @skiller.X
    @skiller.X 2 месяца назад

    stop using python. write 80% more code in C and make your app run faster!

    • @youtubeacc666
      @youtubeacc666 2 месяца назад +4

      🥱

    • @gemilangrahmandhika7509
      @gemilangrahmandhika7509 Месяц назад +1

      And develop 20x slower yea right. 80% would still use Python even if it's 1000x slower than C.

  • @codetechpro
    @codetechpro Месяц назад +1

    Cool

  • @perfectpython8950
    @perfectpython8950 Месяц назад +1

    Useful, thanks.