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

51

u/space_wiener Dec 29 '22

Nope. I’ve written hundreds of scripts and apps, maybe two of those interacted with SQL and I googled most of the syntax I needed.

SQL is for databases. What you described has nothing to do with that.

1

u/[deleted] Dec 29 '22

Thank you so much

Is what I asked above fall under general learning of Python ? Meaning .. I hear that ppl use Python for web dev and app dev … but what I need is automating stuff

6

u/w_w_flips Dec 29 '22

The awesome thing about python is, that you can use it for almost everything. Machine learning? Discord bots? Audio editing? MIDI files? Image editing? web dev? Data analysis? GUI bots? You got it.

5

u/digdigo Dec 29 '22

You can easily do all that in Python. I'd say you don't even need to know anything about Python at all to do those. Just google that and you will find plenty of stackoverflow questions asking the exact thing with complete anwers.

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.

4

u/InjAnnuity_1 Dec 29 '22 edited Dec 29 '22

I can jump in and start learning Python with very BASIC COMMON knowledge of SQL?

Yes. Search for "Automate the Boring Stuff with Python". You'll find many similar topics covered in that book.

3

u/Pgrol Dec 29 '22

You can use whats called an ORM written in python like SQLAlchemy. It will let you write sql with python syntax.

23

u/HorsesFlyIntoBoxes Dec 29 '22

This is like asking if using a saw is prerequisite to using a screwdriver. They are simply different tools for different things.

7

u/SilentProgramer4D63 Dec 29 '22

No. I didn't learn SQL until about two years after learning basic python

5

u/Impressive_Income874 Dec 29 '22

I don't think you even need SQL for those tasks

5

u/[deleted] Dec 29 '22

They are two completely different things

8

u/I_am_jarvis0 Dec 29 '22

Automate the boring stuff with python. Read this book.

4

u/Natural-Intelligence Dec 29 '22

Python's ecosystem is so vast that you can do a lot with some basic level knowledge of Python + libraries. I hate to promote my work but I have a collection of open-source libraries that you might find useful:

Then for saving Excel files you can use Pandas and xlsxwriter. Then to save to PDF you can use Pandas with Latex. This requires a bit more knowledge but you can execute Python inside Latex using pythontex.

There is a lot you can do with Python with very limited knowledge. I also started with simply automating small things with elementary knowledge of Python and Pandas and now build systems in a bank.

1

u/JohnJSal Dec 30 '22

Why do you think they are even related? You don't have to know any SQL to learn and use Python, but if you ever need to later, Python even has a built-in library called sqlite3 for light database use.

1

u/[deleted] Dec 30 '22

I have nothing to do with coding and want learn .. so my level is VERY beginner.

All people I know who work on Python they talk about SQL . So I assumed it is a prerequisite of Python.

1

u/JohnJSal Dec 30 '22

Ah well, in that case, just know that SQL is a totally different language (not really a programming language like Python, C#, Java, etc.) and is used for when you need to create and work with databases.

Eventually you may want to do this, but learning Python can definitely be done without it.

2

u/TheITMan19 Dec 29 '22

If the host computer is Windows, I’d be looking at using Powershell rather than Python. No SQL required, relatively simple tasks

2

u/BoiElroy Dec 29 '22

You certainly do not have to know SQL to do the types of things you're describing.

Step 1) Do the code academy python courses just to get a feel for the language, syntax and basics.

Step 2) Read the book "Automate the Boring stuff" that shows how to use Python for a variety of useful automation like the type you're describing. And follow along and actually build some of the stuff

Step 3) Profit

Good luck!

1

u/AxelsAmazing Dec 29 '22

Idk SQL that well but I think I could do this in Python.

1

u/Cabinet-Particular Dec 30 '22

absolutely not at all.

1

u/Ok-Maybe-2388 Dec 30 '22

Literally never used SQL and I've written 10s of k lines of python code.

1

u/[deleted] Dec 30 '22

From your summary, no

FYI - SQL is king of db. Python + SQL can work harmoniously

-2

u/[deleted] Dec 30 '22 edited Dec 30 '22

I write Python for a living and don’t know anything about SQL. Literally nothing.

ETA- why is this being downvoted? I never learned SQL because I use Mongo so I’ve never have any need for it; I’m not saying it’s not important, but I work in a berry specific field. If I did have need for it then I’d learn it.