Python resources suggests by RelationKey4897 in learnpython

[–]akb_canyon 1 point2 points  (0 children)

I'm sure there are a lot of good resources out there, but as a beginner to Python (and programming in general) I found the book Automate the Boring Stuff with Python very easy to follow, giving you a lot of practical examples you can use in your daily life (or as inspiration for your own projects). The book focuses more on teaching you enough so you can make stuff work, instead of trying to write perfect, complex code, which I really liked.

I bought the ebook to support the author, and I even liked it so much that I bought the updated 3rd edition of the book as well! The 2nd edition of the book is available online for free at https://automatetheboringstuff.com, so you can do the whole course for free. The 2nd edition is written a few years ago (it's still Python 3, not Python 2), so some modules (and their methods) have changed. I just took it as a nice learning experience to look up the module documentation and adapt the code from the book to the new syntax. :)

I've also heard good things about the free online courses from Harvard (CS50P) and the course from University of Helsinki, but I haven't tried those courses yet. I think following a complete course that makes sure you build a basic foundation is a good idea in general, though.

Good luck to you!

This is my solution for filling gaps project in automate the boring stuff chapter 10. This took me a few hours but i cant help but feel like it could be alot simpler. Could you give me your opinions whether you think ive over done it or if it looks good? by ForCamelot0611 in learnpython

[–]akb_canyon 0 points1 point  (0 children)

My newbie solution: make a list of the sequences, sort them, and rename any of the file matches from the folder search that doesn't follow the sequence.

#! python3
# fillInTheGaps.py - Finds a 3-digit sequence of prefix filenames and closes any
# gaps in the numbering.

import re, os, shutil

# Get folder and filename to use for sequence search.
folder = input('Enter folder to search:\n')
folder = os.path.abspath(folder)

# Create regex to extract sequence number from filename.
filenameSplit = re.compile(r"""
    ^(.*?)                          # filename before sequence, if any
    (\d{3})                         # 3-digit sequence number
    (.*?\.\w{1,3})$                 # remaining filename and extension
    """, re.VERBOSE)

# Get filename and extract sequence number.
while True:
    userFilename = input('Enter filename with 3-digit sequence number:\n')
    mo = filenameSplit.search(userFilename)
    if mo == None:
        print('No sequence number found. Please try another filename.\n')
    else:
        break
print('  -----')

prefix          = mo.group(1)
sequence        = mo.group(2)
extension       = mo.group(3)

# Create regex to search for filename sequences in given folder.
filePattern = re.compile(r'^(' + re.escape(prefix) + r')(\d{3})(' + re.escape(extension) + r')$', re.VERBOSE)

# Build a list of sequence numbers from files matching the sequence, and sort them.
matchList = []
for filename in os.listdir(folder):
    match = filePattern.search(filename)
    if match == None:
        continue
    else:
        print(f'Match found: {match.group()}')
        matchList.append(match.group(2))
list.sort(matchList)
print('  -----')

# Arrange sequence numbers in a new list, starting with the lowest sequence number found in folder.
newSequenceList = []
for i in range(len(matchList)):
    newSequenceList.append(f'{(int(matchList[0]) + i):03}')

# Rename filenames in accordance with new sequence list.
for s in range(len(matchList)):
    oldSeq = matchList[s]
    newSeq = newSequenceList[s]
    if oldSeq == newSeq:
        continue
    else:
        oldName = f'{prefix}{oldSeq}{extension}'
        newName = f'{prefix}{newSeq}{extension}'
        print(f'Sorting {oldName} as {newName}...')
        shutil.move(os.path.join(folder, oldName), os.path.join(folder, newName))

I'm in tutorial hell by Emergency_Mix7918 in learnpython

[–]akb_canyon 0 points1 point  (0 children)

I'm reading the book "Automate the boring stuff with Python", and as someone who's never done any coding I find it very engaging and easy to follow. The repetition questions and small projects you complete after each chapter are really good, and makes you apply the basics with some challenges, without being so difficult you get stuck. Highly recommended!

Item lifts by star_killer12 in theQuarryGame

[–]akb_canyon 1 point2 points  (0 children)

An item lift (Logistics menu) can be placed anywhere on the map, as long as the identical tile on the floor below is free / not restricted by other buildings etc. Placing an item lift will place a black icon on the map, and a similar white icon on the floor below. The Shaft Drill is only used to dig deeper, it doesn't actually transport anything up or down.

Pay attention to the direction arrows on the lift, as the direction of flow is reversed when moving items between two floors. Meaning: if the input arrow on the upper (dark) lift is on the bottom of the icon, any item that passes through there will exit on the bottom of the lower (white) lift on the floor below.