Python Forum
First time with Python.. need help with simple script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
First time with Python.. need help with simple script
#8
(May-06-2018, 02:06 AM)shakir_abdul_ahad Wrote: One question; after looking at the last part of your code, beginning on like 32, how would I have known to do that? Being a noob and all. Thanks again.
Well... have you seen this in the python documentation
Quote:keep this under your pillow
it is not a joke.

Really that part off the code will not look so special to you in a few weeks using python. It has different just my use of the continue to quickly discard the non interesting passes of a loop -other people prefer using an if-then-else, is just your preference- and the break to stop testing once the file is already moved. The rest is just read the os entry in the python library.

One thing that is really important and does not look part of the code are the comments. My professional code has even more comments, describing what I expect to find in each part of the code a little bit complex. Always think that your code must be understood -and fixed- by someone who has less experience than you...
When you plan to use something complex (like the nested for loops in the previous code or a long regex) write the comment before the writing code. If you cannot summarise it in a few sentences, your code will be too complex and might backfire in any moment.

Good luck learning python!
Reply


Messages In This Thread
RE: First time with Python.. need help with simple script - by killerrex - May-06-2018, 09:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,352 Jun-29-2023, 11:57 AM
Last Post: gologica
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,320 May-10-2023, 02:13 PM
Last Post: Calab
  How to change UTC time to local time in Python DataFrame? SamKnight 2 1,633 Jul-28-2022, 08:23 AM
Last Post: Pedroski55
  Clock\time calculation script Drone4four 3 1,507 Jan-21-2022, 03:44 PM
Last Post: ibreeden
  Simple Python script, path not defined dubinaone 3 2,734 Nov-06-2021, 07:36 PM
Last Post: snippsat
  Real-Time output of server script on a client script. throwaway34 2 2,077 Oct-03-2021, 09:37 AM
Last Post: ibreeden
  PyCharm Script Execution Time? muzikman 3 8,513 Dec-14-2020, 11:22 PM
Last Post: muzikman
  Need help creating a simple script Nonameface 12 4,663 Jul-14-2020, 02:10 PM
Last Post: BitPythoner
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,956 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,322 May-28-2020, 05:27 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020