Help needed: excecute scripts

python

#1

Hello fellow coders!
I recently completed the Python course (woohoo!), and it felt pretty good!
However, I felt like not all my questions were answered in the last topic, that otherwise dealt with writing to and from txt files.

What i want to know is this: how can i create my own scripts (outside of the code academy environment) and execute them?

I am not a computer science student (biomedicine rather, so coding is not within my comfort zone), but previously i had a introductory course in Perl programming at my university.
I learned Perl 5 (of course..), but also how to write scripts, and what to type in the "Strawberry Perl" command terminal to make it work.
Something like this:
Perl bin/somescript.pl > data/some_output.txt

I was wondering if you can do something similar with Python - I'm sure you can, but so far I haven't been able to figure it out.

I downloaded "Python" for windowns through their website, but it doesn't appear to function quite like Strawberry perl (that is a command promt window like "cmd"). Does this mean i should only use cmd to execute my scripts?

One last thing: in all my Perl scripts i start by typing:
#!/usr/bin/perl -ws
I guess you need a similar "code" to tell notepad++ you work with python right? and to tell the interpreter you are working with python? What should i type?

if answer == True:
[tab] Jonesomg = "happy"

Jones


#2

Replace perl with python pretty much.
and .py
-ws is some argument to perl I'm gussing, so skip that


This'll most likely only work on linux/others, since it's a unix path
#!/usr/bin/perl -ws
But you'd do the same for python. Again, I don't think this is working for you even with perl if you're on windows.
#!/usr/bin/python
you might have been executing them with just windows' association from .pl to your perl interpreter.


if
$ python my_code.py
isn't starting your code, then you'll need to add python to your PATH


I think you were typing that into bash, not inside perl. And your Perl would have to be all lower letters: perl, because the executable file is named that way, and in unix, file name capitalization matters (unlike in windows)


#3

Keep asking if any of this is unclear.

If you want to compare linux and windows to help you figure this out, you can pop your head into this track:
https://www.codecademy.com/en/courses/learn-the-command-line
Which is a bash course, you don't necessarily need to do the course itself, but the track uses ubuntu (a linux distro) instances, they have both perl and python installed - so you can experiment there.

I suggest using nano for editing files in that environment (your easiest option of terminal editors) You save/exit with ctrl + some key, they are listed inside the nano program

You can also install a virtual machine and put linux on that if you'd like to have that environment instead of having to deal with windows.

If all you want to do is get perl to run anything, then obviously windows is fine.


#4

After googling strawberry perl for a tiny while, apparently it mimics some unix features.

So if you've been using windows the whole time, then a lot of what you've said is strawberry perl acting as if you're on a unix system.

Python just runs code, it doesn't try be another operating system. (That would just be very weird, that's not the purpose of Python or for that matter Perl)