python 提升日常工作_使用Python增强日常工作

python 提升日常工作

We can’t all be programmers — that would be a weird world! However, anyone can benefit from some basic programming skills.

我们不可能所有人都是程序员-那将是一个奇怪的世界! 但是, 任何人都可以从一些基本的编程技能中受益。

Working in accounting? Programming can help you. Are you a designer? Programming can help you. Do you work with computers at all? Programming can help you.

从事会计工作? 编程可以为您提供帮助。 你是设计师吗? 编程可以为您提供帮助。 你是否在所有的电脑吗? 编程可以为您提供帮助。

Do you see the pattern here? If you have done the same task more than once, a useful program is just waiting to be made.

您在这里看到图案了吗? 如果您多次完成同一任务,那么将等待一个有用的程序。

When you write code in a development environment, you have to follow certain rules. This is great because it keeps the programs in order and makes it easy for everyone on the projects to work on the code.

在开发环境中编写代码时,必须遵循某些规则。 这很棒,因为它可使程序保持顺序,并使项目中的每个人都可以轻松地处理代码。

But when you write your own programs, you don’t have to follow all these rules. It might just be a small snippet of code that helps you with a tiny task that only you do. Some companies have a development department that will clean up your code and make it available for everyone else. Maybe someone else has been complaining about what you just solved.

但是,当你编写自己的程序,你没有遵守所有这些规则。 它可能只是一小段代码,可以帮助您完成一个只有您才能完成的小任务。 一些公司有一个开发部门,它将清理您的代码并将其提供给其他所有人。 也许其他人一直在抱怨您刚刚解决的问题。

我们将编写以下工具 (We will write the following tools)

  • A publish tool. Publish working files to let your co-workers know a job is done and they can pick up the files.

    发布工具 。 发布工作文件,以使您的同事知道工作已完成,他们可以提取文件。

  • An ingest tool. Take care of files received from a client and distribute its content to your fellow employees.

    摄取工具 。 请妥善保管从客户那里收到的文件,并将其内容分发给您的同事。

Note: I use Python 3.8 in this article, but most programming languages can do similar tasks. You can also see a slightly different coding level on the two tools. The first one is a bit manual, while the second one tries to be more professional

注意:我在本文中使用Python 3.8,但是大多数编程语言都可以执行类似的任务。 您还可以在两个工具上看到稍微不同的编码级别。 第一个有点手册,而第二个试图变得更专业

一个发布工具 (A Publish Tool)

A publish tool will promote a work-file to a publish-file. A publish-file is a file that is ready for the next department to use. Its publication signals that you’re done with the work (at least for now). This file lives in a predefined location and its name will not change. Therefore any software using this as a reference will get an auto-update when you publish a newer version.

发布工具会将work-file升级为publish-filepublish-file是可供下一个部门使用的文件。 它的发布表明您已完成工作(至少现在是这样)。 该文件位于预定义的位置,其名称不会更改。 因此,当您发布较新的版本时,任何以此为参考的软件都将自动更新。

Image for post
v003 is our current published version. Employees can start using the published ‘male_icon.ai’ file
v003是我们当前发布的版本。 员工可以开始使用发布的“ male_icon.ai”文件
Image for post
v005 is our current published version. Software using the file will get the update as well
v005是我们当前发布的版本。 使用该文件的软件也将获得更新

Most companies in my line of work — VFX and animation — have publish systems sorted. If you work as a freelancer, or as an employee in another random company, you might not have a setup for this yet.

我工作的大多数公司(视觉特效和动画)都已对发布的系统进行了排序。 如果您是自由职业者,或者是另一家随机公司的雇员,则可能尚未为此设置。

In the following example, you are working on a variety of files for the company’s Q1 reports. It can be icons, it can be copywriting, it can be anything. The important part is that you publish your files when they’re ready.

在以下示例中,您正在处理公司Q1报告的各种文件。 它可以是图标,可以是文案,也可以是任何东西。 重要的是,您可以在文件准备好后发布它们。

When you’re done with your work, the presenters will take over and use your published files in their presentations. If the presenter needs to ask you where the files are stored, you’ve already failed. But if you publish the files, the next person in line will always know where to look.

完成工作后,演示者将接管并使用您在演示文稿中发布的文件。 如果演示者需要询问您文件的存储位置,则您已经失败了。 但是,如果您发布文件,则下一个排队的人将始终知道在哪里查找。

Let’s say this is your file and folder structure:

假设这是您的文件和文件夹结构:

screenshot of project folder structure with work files.
potential folder structure
潜在的文件夹结构

It looks structured and the files are living nicely in their folders. Now, let’s make sure the presenter knows exactly which male_icon ai file they will pick up for the presentation.

看起来结构清晰,文件很好地保存在其文件夹中。 现在,让我们确保演示者确切知道他们将为演示文稿选择的male_icon ai文件。

This is what we’re looking for:

这就是我们要寻找的:

screenshot of project folder structure with a publish file.
Steven just got hit by a bus! No problem, I know where his published files are…
史蒂文刚被公共汽车撞了! 没问题,我知道他发布的文件在哪里…

让我们编码吧! (Let’s code!)

import os


def publish(search_path):


    print(f'working on: {search_path}')
    #list folders in search path
    scan_search_path = [folder.name for folder in os.scandir(search_path) if folder.name != '.DS_Store']


    #if there is a work folder available, we can start working
    if 'work' in scan_search_path:


        #list all work files (assume naming convension)
        #create work path
        work_path = os.path.join(search_path , 'work')
        #create publish path
        pub_path = os.path.join(search_path , 'publish')
        scan_work_files = [file.name for file in os.scandir(work_path) if file.is_file() and not file.name.startswith('.')]


        #check for files in the work folder
        if scan_work_files:
            #create publish folder if it doesn't exist
            if 'publish' not in scan_search_path:
                os.mkdir(pub_path)


            #naming convension is vXXX so last item will be latest.
            source_file = scan_work_files[-1]
            #remove vXXX from filename
            file_data = list(os.path.splitext(source_file))
            remove_version = '_'.join(file_data[0].split('_')[0:-1])
            publish_file = remove_version + file_data[1]


            # set up the source and destination for the link
            symlink_source = work_path + '/' + source_file
            symlink_destination = pub_path + '/' + publish_file


            #delete the symlink if it already exists
            if os.path.exists(symlink_destination):
                os.remove(symlink_destination)


            #create symlink
            os.symlink(symlink_source , symlink_destination)
            print (f'{symlink_destination} published...')
        else:
            print ('There are no work files to publish in the work folder')


    #if there is no work folder, script can't publish
    else:
        print('There is no work folder. Nothing to publish')




def main():
    #define path and scan it for folders
    root_path = '/Users/martinandersson/Desktop/example_project/reports/Q1/'
    folder_list = [folder.name for folder in os.scandir(root_path) if folder.is_dir()]


    #print menu for user
    for index,folder in enumerate(folder_list):
        print (f'{index+1}: {folder}')


    #select folders to publish
    #use comma to select many
    input_folder = input('select the folder(s) you would like to publish: ')


    #execute publish
    split_input = input_folder.split(',')
    for current_folder in split_input:
        publish(root_path+folder_list[int(current_folder)-1])




if __name__ == "__main__":
    main()

The program uses two procedures: publish() and main()

该程序使用两个过程: publish()main()

发布(search_path): (publish(search_path):)

The publish procedure asks for a search path. In this path, it will look for a work folder and a publish folder. If the work folder exists and it contains any files, we can start working.

发布过程要求搜索路径。 在此路径中,它将查找工作文件夹和发布文件夹。 如果工作文件夹存在并且包含任何文件,我们就可以开始工作。

scan_search_path uses list comprehension to store all the folders in the project folder we passed.

scan_search_path使用列表scan_search_path将所有文件夹存储在我们传递的项目文件夹中。

if folder.name != ‘.DS_Store’ is there to make sure we don’t list the .DS_Store folder — we’re only interested in the “real” folders.

if folder.name != '.DS_Store'在那里,以确保我们没有列出.DS_Store文件夹-我们只对“真实”文件夹感兴趣。

scan_work_files does something similar. It lists the files as long as they do not start with a ..

scan_work_files做类似的事情。 只要文件不以开头,它就会列出文件.

A publish-file will be a symlink to the latest work-file. We assume our naming convention has v001, v002, v003 etc. This way, the latest number is the latest file we worked on — the one we want to publish. You can also look into using datestamps to find the latest file or have the user define the file to be published.

发布文件将是最新工作文件的符号链接。 我们假设我们的命名约定包含v001,v002,v003等。这样,最新编号就是我们正在处理的最新文件,即我们要发布的文件。 您还可以研究使用日期戳来查找最新文件,或者让用户定义要发布的文件。

However, the publish file does not need a version number — if you reference the file into another software, it will update automatically. This means that the published file could symlink to v001 on Monday and v005 on Friday. The published file name would not change.

但是,发布文件不需要版本号-如果将文件引用到其他软件中,它将自动更新。 这意味着已发布的文件可以在星期一与v001和在星期五与v005符号链接。 发布的文件名不会更改。

This code removes the versioning from the published file:

此代码从发布的文件中删除版本控制:

file_data = list(os.path.splitext(source_file))
remove_version = '_'.join(file_data[0].split('_')[0:-1])
publish_file = remove_version + file_data[1]

主要() (main())

Since this is your internal script to help you publish your files, the root_path is hardcoded in this example (check the ingest tool below for a better way to handle file paths).

由于这是帮助您发布文件的内部脚本,因此在此示例中root_path是硬编码的(请检查下面的摄取工具,以获取处理文件路径的更好方法)。

The root_path is our project folder. We want to look through the folders inside to see what we want to publish.

root_path是我们的项目文件夹。 我们想浏览内部的文件夹以查看我们要发布的内容。

We have created a menu for ourselves so we can publish what we want. The code is simply looking for the available folders and asks for input. We can use commas to select multiple folders. The split_input takes care of that

我们已经为自己创建了一个菜单,以便我们可以发布所需的菜单。 该代码只是在寻找可用的文件夹并要求输入。 我们可以使用逗号选择多个文件夹。 split_input负责

The reason we use index+1 in the for loop is to present an option ranging from 1 to many. 0 as the first index is not something the average user would consider normal.

我们在for循环中使用index+1的原因是要提供一个范围从1到很多的选项。 0作为第一个索引不是一般用户认为正常的东西。

We use the correct index when we do the actual publishing:

在进行实际发布时,我们使用正确的索引:

publish(root_path+folder_list[int(current_folder)-1])

Here is the interaction with the user

这是与用户的互动

screenshot of terminal where user picks folders to publish
creating a menu can be nice for others and yourself
创建菜单可能对他人和您自己都有利

In addition, I would consider a few more options for this program

另外,我会考虑该程序的更多选择

  • Add a metadata file that shares timestamps of publishes and the history of what files were used earlier in case of errors like corrupt files, etc.

    添加一个元数据文件,该文件共享发布的时间戳记以及在损坏的文件等错误的情况下较早使用哪些文件的历史记录。
  • An option to select all folders so you can publish everything in one go.

    选择所有文件夹的选项,以便您可以一次发布所有内容。

提取工具 (An Ingest Tool)

An ingest tool handles files you receive from outside your studio. Someone has to unpack client files and make sure they are located in the correct location on disk for all the employees working on the project.

提取工具可以处理您从工作室外部收到的文件。 有人必须解压缩客户端文件,并确保它们对于项目中的所有员工都位于磁盘上的正确位置。

If you are responsible for client files, you want to have a setup where you can unpack the files and sort them nicely. The files will normally come compressed. You would then unpack the zip file (our example only supports zip) and sort the material.

如果您负责客户端文件,则需要进行设置,以便将文件解压缩并进行很好的排序。 文件通常会被压缩。 然后,您将解压缩zip文件(我们的示例仅支持zip)并对材料进行排序。

Let’s pretend we still work for the same company. This is the content the client will send us:

假设我们仍在同一家公司工作。 这是客户将向我们发送的内容:

screenshot of what will be the content of the zip file
These files will be sent to us in a zip file.
这些文件将以zip文件格式发送给我们。

There are some files we recognize right away. PDF files are documents with written information in them. A client brief, a note, or something we want to read. Then we have several image files and, finally, we have an Autodesk Maya file (.ma) and a Python script we need to run something.

我们立即识别出一些文件。 PDF文件是其中包含书面信息的文档。 客户简介,说明或我们要阅读的内容。 然后,我们有几个图像文件,最后还有一个Autodesk Maya文件(.ma)和一个运行某些脚本所需的Python脚本。

Time to zip it up and pretend it is from a client:

是时候压缩它并假装是从客户端进行的:

screenshot of the zip file
That’s more like it!
这还差不多!

Here is our pseudo code explaining the steps we need to take:

这是我们的伪代码,说明我们需要采取的步骤:

# unzip the file# create a folder for the current date# create folders for the files based on pre-defined filetypes# move the files into the correct folders# archive the zip file

Here’s the final code:

这是最终代码:

import sys
from zipfile import ZipFile
from datetime import datetime
import os
from pathlib import Path
import shutil


def get_file_path(filename):
    '''
    function returning the full path of the file passed
    '''
    return Path(filename).resolve()




def get_date_path():
    '''
    function returning today's date
    '''
    return datetime.date(datetime.now())




def get_directory_path(filename):
    '''
    function returning directory path without the file
    '''
    return os.path.split(str(get_file_path(filename)))[0]




def unpack_file(zipfile):
    '''
    procedure unpacking zip file
    '''


    #working directory plus todays date to pack into
    working_date_dir = os.path.join(get_directory_path(zipfile),str(get_date_path()))


    #delete the folder if it exists.
    if os.path.exists(working_date_dir):
        shutil.rmtree(working_date_dir)


    #create the date folder in the working directory
    os.mkdir(working_date_dir)


    #unzip into date directory
    with ZipFile(get_file_path(zipfile) , 'r') as current_file:
        current_file.extractall(working_date_dir)


    #feeback for user
    print (f'files unpacked')




def filetype():
    '''
    function returning currently supported filetypes
    '''
    filetype_dict = {'documents' : ['pdf','doc','docx'] ,
                     'project_files' : ['ma','py'] ,
                     'reference' : ['png','jpg']}


    return filetype_dict
    # create folders for the files based on pre-defined types




def list_folders_in_dir(scan_dir):
    '''
    function returning directories in a given directory
    '''
    return [dir for dir in os.listdir(scan_dir) if os.path.isdir(os.path.join(scan_dir,dir))]




def list_files_in_dir(scan_dir):
    '''
    function returning files in a given directory
    '''
    return [file for file in os.listdir(scan_dir) if os.path.isfile(os.path.join(scan_dir,file))]




def place_files(input_file):
    '''
    procedure moving files to the correct place on disk
    '''
    working_date_dir = os.path.join(get_directory_path(input_file),str(get_date_path()))


    #list files and directories:
    unpacked_files = list_files_in_dir(working_date_dir)
    unpacked_folders = list_folders_in_dir(working_date_dir)


    for file in unpacked_files:
        #get ext:
        extension = os.path.splitext(file)[1][1:]
        #get valid filetypes
        filetype_lists = filetype()
        #copy file from this path
        from_dir = os.path.join(working_date_dir,file)


        #check if it is in our list of predefined extensions:
        for key, values in filetype_lists.items():
            if extension in values:
                #create directory if it does not exist
                dict_value_dirs = os.path.join(working_date_dir,key)
                if not os.path.isdir(dict_value_dirs):
                    os.mkdir(dict_value_dirs)


                #move file into directorty
                os.rename(from_dir , os.path.join(dict_value_dirs,file))




    #place remaining files in undefined_dir
    remaining_files =list_files_in_dir(working_date_dir)
    #create undefined directory
    undefined_dir = os.path.join(working_date_dir,'_not_defined')
    for file in remaining_files:
        #delete folder if it exists (it should never exist)
        if not os.path.isdir(undefined_dir):
            os.mkdir(undefined_dir)


        #move the files
        from_dir = os.path.join(working_date_dir,file)
        os.rename(from_dir,os.path.join(undefined_dir,file))


    #delete _MACOSX
    potential_macosx_dir = os.path.join(working_date_dir,'__MACOSX')
    if os.path.isdir(potential_macosx_dir):
        os.rmdir(potential_macosx_dir)


    #feedback to user
    print(f'files moved')




def archive_zip(zipfile):
    #solve paths
    file_path = get_file_path(zipfile)
    to_path = os.path.join(get_directory_path(zipfile),'_archive')


    #get filename without any path dirs
    isolated_file = zipfile
    if '/' in zipfile:
        split_zipfile = zipfile.split('/')[-1]
        isolated_file = split_zipfile


    #create archive dir if it does not exist
    if not os.path.isdir(to_path):
        os.mkdir(to_path)


    #move the file
    os.rename(file_path,os.path.join(to_path,isolated_file))


    #feedback to the user
    print(f'client file archived')




def create_meta_file(source_file):
    #create txt file
    working_date_dir = os.path.join(get_directory_path(source_file),str(get_date_path()))
    full_path = os.path.join(working_date_dir, 'metafile.txt')


    #write filename to metafile
    with open (full_path , 'w') as metafile:
        metafile.write(source_file)


    #feedback to the user
    print(f'metafile created')




def ingest():
    working_file = sys.argv[1]


    unpack_file(working_file)


    place_files(working_file)


    archive_zip(working_file)


    create_meta_file(working_file)




if __name__ == '__main__':
    ingest()

This is a big one and we have a lot to cover. Let’s jump right into it.

这是一个很大的问题,我们还有很多要讲的。 让我们直接跳进去。

def ingest() (def ingest())

If we look at the last procedure first we can see that we define the working file: sys.argv[1]

如果我们首先查看最后一个过程,则可以看到我们定义了工作文件: sys.argv[1]

This means we can execute the Python script from the terminal and pass an argument directly while executing the program. You should quickly see that this is a better approach than hard-coding a root path as we did for the publish tool.

这意味着我们可以从终端执行Python脚本,并在执行程序时直接传递参数。 您应该很快就会发现,与像对发布工具那样对根路径进行硬编码相比,这是一种更好的方法。

Let’s say we decide that we want to keep our Python file outside the from_client folder:

假设我们决定要将Python文件保留在from_client文件夹之外:

screenshot of folder structure before we execute our program

Now we can run this command from the terminal to execute the script from the client_files folder and work on the selected zip file (from_client/inconsistentNaming_convensionFromclient13.zip)

现在,我们可以从终端运行此命令以从client_files文件夹执行脚本并处理所选的zip文件( from_client/inconsistentNaming_convensionFromclient13.zip )

screenshot of execution of the program

The reason we use sys.argv[1] is that [0] is reserved for the filename itself.

我们使用sys.argv[1]的原因是[0]保留用于文件名本身。

import sysprint(sys.argv[0])
>>> main.py

This way we can pass any path to a file as an argument for the program to work on — pretty clever!

这样,我们可以将文件的任何路径传递为程序可以运行的参数,这非常聪明!

When we have the file we want to work with stored in a variable, we can start executing all sorts of commands. working_file is passed to several functions and procedures. We’re going to look at each of them one by one.

当我们要使用的文件存储在变量中时,我们可以开始执行各种命令。 working_file传递给几个函数和过程。 我们将逐一查看它们。

unpack_file(zipfile) (unpack_file(zipfile))

This is pretty straightforward. We pass a filename to the procedure so it can unpack our file.

这很简单。 我们将文件名传递给该过程,以便它可以解压缩我们的文件。

It is using a few support functions, get_directory_path(zipfile) ,get_date_path() , and get_file_path(). Let’s have a look at these.

它使用了一些支持功能,即get_directory_path(zipfile)get_date_path()get_file_path() 。 让我们来看看这些。

  • get_directory_path(filename): This function returns the path we are working from.

    get_directory_path(filename) 此函数返回我们正在使用的路径。

  • get_date_path(): This function uses the datetime library to return today’s date.

    get_date_path() 此函数使用datetime库返回今天的日期。

  • get_file_path(): This function returns the full path of the file including its filename.

    get_file_path() :此函数返回文件的完整路径,包括文件名。

def place_files(输入文件) (def place_files(input_file))

Now that the zip file is unpacked, we can start working on our files. We want to place the files based on file type, so we need to define these. We don’t want the extension to be the folder name, because we need several filetypes to live in the same folder.

现在,压缩文件已解压缩,我们可以开始处理文件了。 我们要根据文件类型放置文件,因此我们需要定义它们。 我们不希望扩展名成为文件夹名称,因为我们需要几种文件类型才能驻留在同一文件夹中。

This procedure is also using several support functions. When we list files and folders, we use both list_files_in_dir(scan_dir) and list_folders_in_dir(scan_dir).

此过程还使用了几种支持功能。 当我们列出文件和文件夹时,我们同时使用list_files_in_dir(scan_dir)list_folders_in_dir(scan_dir)

def list_folders_in_dir(scan_dir) (def list_folders_in_dir(scan_dir))

List comprehension is used to return the folders living in the folder of your choice. In our case, it is the folder we unpacked our files into.

列表推导用于返回位于您选择的文件夹中的文件夹。 在我们的例子中,这是我们将文件解压缩到的文件夹。

def list_files_in_dir(scan_dir) (def list_files_in_dir(scan_dir))

Can you guess what this does?

你能猜出这是什么吗?

Now that we have stored all the files and folders in variables, we start looping to sort them. All files are sent to sorted folders. If you pay extra attention, you can see that there is a dictionary loop inside the file loop. this is because we’re using a dictionary to define our filetypes. We’re using the function filetype() to get an overview of where the files should be placed.

现在,我们已将所有文件和文件夹存储在变量中,我们开始循环进行排序。 所有文件都发送到已排序的文件夹。 如果您格外注意,可以看到文件循环中有一个字典循环。 这是因为我们使用字典来定义文件类型。 我们正在使用函数filetype()来概述文件的放置位置。

def filetype() (def filetype())

Filetype is a clever way to maintain control over your sorting. In this example, I’ve chosen to define three categories: documents, project_files, and reference.

文件类型是一种保持对排序的控制的聪明方法。 在这个例子中,我选择来定义三类: documentsproject_files reference

You can update this dictionary at any time to add or remove extensions to your liking. I excluded .txt from documents to show you what we do with files that are unlisted.

您可以随时更新此词典以添加或删除自己喜欢的扩展名。 我从文档中排除了.txt,以向您展示我们如何处理未列出的文件。

After all the defined filetypes are cleaned up, the program looks at the remaining files. These files didn’t have a home to go to so they are all sent to a folder called _not_defined (or whatever you want to call it.)

清除所有定义的文件类型后,程序将查看其余文件。 这些文件没有家,因此它们都被发送到一个名为_not_defined的文件夹(或任何您想调用的文件夹)。

In my case, I also want to remove the __MACOSX folder from the unpacking, so I added the last part of the code to deal with this. This is optional and will vary depending on your software

就我而言,我也想从解包中删除__MACOSX文件夹,因此我添加了代码的最后一部分来处理此问题。 这是可选的,具体取决于您的软件

def archive_zip(zipfile) (def archive_zip(zipfile))

In this case, I want to archive the zip file when it is unpacked. This way, IT can always go to the archive folder to delete or back up the original zip files.

在这种情况下,我想在解压缩后将zip文件存档。 这样,IT部门始终可以转到存档文件夹以删除或备份原始zip文件。

There’s no magic here. It’s using the functions from earlier to handle paths and it strips out any dashes from the argument to move the file to its correct location.

这里没有魔术。 它使用较早版本的函数来处理路径,并从参数中去除所有破折号以将文件移至正确的位置。

You might have noticed I am using os.rename() to move files. You can also use shutil.move() to do the same thing. os.rename() requires the filename in both destination and source, while shutil.move() doesn’t need the filename in the path you move to. I have no personal preference, I just wanted to try os.rename()

您可能已经注意到我正在使用os.rename()移动文件。 您也可以使用shutil.move()来执行相同的操作。 os.rename()在目标和源中都需要文件名,而shutil.move()在移动到的路径中则不需要文件名。 我没有个人喜好,我只想尝试os.rename()

def create_meta_file(源文件) (def create_meta_file(source_file))

I often talk about metafiles, but I rarely show you any code for it. What this does is to add the filename from which we unpacked our files into a text file. This way we can backtrack where the files came from. Remember, we archived our zip file to clean things up.

我经常谈论图元文件,但是我很少向您显示任何代码。 这样做是将文件解压缩后的文件名添加到文本文件中。 这样,我们可以回溯文件的来源。 记住,我们存档了zip文件以进行清理。

We are using os.path.join() to create the paths we want to use. Then we create a file using with. I like this method more than file.opendo thingsfile.close because actions are encapsulated in a prettier manner and it closes itself when it is done. To me, that’s more Pythonic:

我们正在使用os.path.join()创建我们要使用的路径。 然后,我们使用with创建文件。 我比file.opendo thingsfile.close更喜欢此方法,因为操作以更漂亮的方式封装,并且操作完成后会自行关闭。 对我来说,这更像Pythonic:

with open (full_path , 'w') as metafile:
metafile.write(source_file)

The feedback is printed in the terminal for the user

反馈将打印在终端中供用户使用

screenshot of user feedback printed in the terminal

We just went from a single zip file to this:

我们只是从单个zip文件转到了:

screenshot of unpacked and organized folder structure
files are unpacked and sorted nicely
文件被解压并很好地排序

Files are sent to their homes:

文件被发送到他们的家:

screenshot of content inside the ‘reference’ folder
both the png and jpg live in this folder as they are both defined as references
png和jpg都位于此文件夹中,因为它们都被定义为引用

And the metafile contains the name of the zip:

图元文件包含zip的名称:

from_client/inconsistentNaming_convensionFromclient13.zip

Pat yourself on your shoulder — you just took an hour to write a program that will save you days. The current version does not support folders in the unzipped directory, but you should be able to write that in by now.

轻拍自己的肩膀-您只花了一个小时就编写了一个可以节省几天时间的程序。 当前版本不支持解压缩目录中的文件夹,但是您现在应该可以将其写入。

结论 (In conclusion)

Programming is something you can have others do for you or you can learn just enough to do small snippets — like the ones we have looked at today.

编程是您可以让其他人为您做的事情,或者您可以学习足够的内容来编写小片段,就像我们今天所看到的那样。

If you write the program yourself, it will happen there and then. You will do it right away when you face an issue and you aren’t tied down by any rules. Be careful though — it also means you can make mistakes a dev team would not. It can be pretty scary to delete entire projects just because you don’t know what you are doing!

如果您自己编写程序,那么它将在那里发生。 当您遇到问题并且不受任何规则约束时,您将立即进行操作。 但是要小心-这也意味着您可能会犯错开发团队不会犯的错误。 仅仅因为您不知道自己在做什么而删除整个项目可能会非常可怕!

Most of the time you will be fine and your workday will feel a lot better. Trust me, I have coded myself out of weeks of work!

在大多数情况下,您会感觉很好,并且工作日会感觉好很多。 相信我,我已经在数周的工作中为自己编写了代码!

One cool thing to think about is that, theoretically, you’re now a professional programmer since you get paid to write programs — cool bonus!

要考虑的一件很酷的事情是,从理论上讲,由于您有报酬来编写程序,因此您现在是一名专业程序员—很棒的奖金!

Thanks for your time.

谢谢你的时间。

翻译自: https://medium.com/better-programming/how-to-use-python-to-power-up-your-day-job-c6cd835a7c92

python 提升日常工作

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值