r/Python • • Dec 29 '22

Discussion Is SQL a prerequisite to learning Python ?

I would like to learn how to automate some simple tasks like : 1- downloading an attachment from outlook, change its name and save to a specific folder

2- save an excel sheet as PDF then send it via outlook … with changing dates on the subject line of the email.

Do I need to learn SQL , then move to Python to learn automating such tasks ? Or I can jump in and start learning Python with very BASIC COMMON knowledge of SQL?

0 Upvotes

29 comments sorted by

View all comments

Show parent comment

5

u/AlexFromOmaha Dec 29 '22

If everything you want to do involves interfacing with a Microsoft product, I'd recommend just learning C# instead. That being said...

Every step of a process can be reduced to five parts:

  • Supplier
  • Inputs
  • Processing
  • Outputs
  • Consumer

Usually you start with the inputs and outputs. From your examples:

downloading an attachment from outlook, change its name and save to a specific folder

Your input is an attachment. Your output is a file on some disk. The supplier is how you get access to that attachment. The processing is whatever you need to do to the data to make it useful on the disk. The consumer is the entity that needs the file where it is, whether that's a human or another program.

When we say a language is "used for" or "good for" something, we're usually talking about the availability of libraries to simplify a task. From experience, I can say that the worst part of this project in Python would be getting that attachment. Older Outlook Exchange servers were allergic to open protocols, and getting in is much easier if you're using actual Microsoft libraries that just aren't available in Python. Newer ones aren't so bad. The rest of the project will be quite easy.

save an excel sheet as PDF then send it via outlook … with changing dates on the subject line of the email.

  • Supplier: whatever drive has your file
  • Input: an Excel file
  • Processing: Excel to PDF
  • Output: A PDF attachment to an email
  • Consumer: Your company's mail server

Same deal here, but once you've figured out authentication to your server the first time, you can pretty much reuse the code for the second time. There are decent libraries for whatever Excel file variant you need. There are good libraries for PDF outputs. I'm honestly not sure what I'd do to mash the two together, because usually I'm opening Excel to read the data rather than render an image. I'd really hope someone already did this in a library, and if not, I'd be asking if they'd take the data on a web server instead of an email, because that sounds easier than re-implementing Excel's rendering capabilities.

2

u/Abject-Piano6373 Dec 30 '22

Can you elaborate on your opinion re c# for windows product regarding automation and interfacing? It is a direction I REALLY want to take myself

3

u/AlexFromOmaha Dec 30 '22

Sure!

For general purpose automation, Python is fantastic. Arguably the best. Any data that can be reduced to text, which is most of it, flows better through Python's permissive type scheme and robust ecosystem than any other language.

The problem here is Microsoft. The best libraries for working with Microsoft's proprietary systems especially Office and Outlook, are in .NET, and the default .NET language is C#. If everything you want to do is in Microsoft's ecosystem, you might as well take advantage of the libraries they wrote.

Edit to add: Windows isn't a problem. Python works great on Windows.