Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting Around in OS X
#1
Hi everybody,

I know this is a real general question, but I'm using the docs and not really getting anywhere.

I'm trying to use Python as a SSH alternative. That seems like a mistake thus far.

For instance, I'm trying to do SSH ls in python which is os.listdir() as far as I can tell. It does nothing. If I put something in the () is says there's too many values.

Instance 2, sys.path just spits out a bunch of compiled info with no white space.

Also I'm not trying to target a specific path. I'm just trying to swim in the OS, get familiar like SSH.

Is there a guide out there for this specifically or is this just a bad idea?
Reply
#2
How do you expect to use something as complex as a computer language without knowing the very basics?
I strongly suggest that you spend the time to take a tutorial.
Recommended: https://www.python-course.eu/python3_course.php
or
https://interactivepython.org/runestone/...index.html
Reply
#3
(Jun-26-2019, 02:10 PM)Larz60+ Wrote: How do you expect to use something as complex as a computer language without knowing the very basics?
I strongly suggest that you spend the time to take a tutorial.
Recommended: https://www.python-course.eu/python3_course.php
or
https://interactivepython.org/runestone/...index.html

Well, I've worked with object-oriented scripting in Actionscript 2/3 and Javascript for a number of years. So it's not like I don't know anything about programming. Python is more like Java or C#, so...I hear you. It's a more complex language than what I'm used to. It's also got a slew of libraries. I didn't know it had a such a reach.

I'm used to mostly picking up an API and toying/running with it. For Python I was thinking that I might be able to treat it like SSH or VI editor but it seems that it needs a more directive based approach. Like it behaves more like a runtime language than an environment.

For instance, if I can find all the files in a directory that's great. But if there's no white space, it's totally illegible and only of useful for data. Know what I mean? Like if I have to to write out an entire path string then parse all this data just to look at where I am in a PWD (present working directory) I'm better off using Shell than Python for OS environment purposes. I'll use Shell to position myself then put together a Python code once in position if that's the case.

But I'm new at this and just trying to understand the just of this.

I hope that makes sense.
Reply
#4
(Jun-26-2019, 01:52 AM)soupking Wrote: For instance, I'm trying to do SSH ls in python which is os.listdir() as far as I can tell. It does nothing. If I put something in the () is says there's too many values.
It take a string as Path or eg '.' present directory.
import os

for fn in os.listdir('.'):
    print(fn)

Quote:Instance 2, sys.path just spits out a bunch of compiled info with no white space.
As it suppose do,sys.path just show a list over where Python look for modules/packages or simpler therms files .py.

Quote:For instance, if I can find all the files in a directory that's great. But if there's no white space, it's totally illegible and only of useful for data. Know what I mean? Like if I have to to write out an entire path string then parse all this data just to look at where I am in a PWD (present working directory) I'm better off using Shell than Python for OS environment purposes. I'll use Shell to position myself then put together a Python code once in position if that's the case.
PWD (present working directory) is in Python os.getcwd().
I think you mix up some stuff,yes using shell commands is easier for the daily navigation as we all use.
Can navigate with Python to,but the point for eg using Python os module is that want do stuff that are little more complicated than just navigate eg rename,move,copy,delete...ect file/dir.
Reply
#5
(Jun-26-2019, 03:23 PM)snippsat Wrote:
(Jun-26-2019, 01:52 AM)soupking Wrote: For instance, I'm trying to do SSH ls in python which is os.listdir() as far as I can tell. It does nothing. If I put something in the () is says there's too many values.
It take a string as Path or eg '.' present directory.
import os

for fn in os.listdir('.'):
    print(fn)

Quote:Instance 2, sys.path just spits out a bunch of compiled info with no white space.
As it suppose do,sys.path just show a list over where Python look for modules/packages or simpler therms files .py.

Quote:For instance, if I can find all the files in a directory that's great. But if there's no white space, it's totally illegible and only of useful for data. Know what I mean? Like if I have to to write out an entire path string then parse all this data just to look at where I am in a PWD (present working directory) I'm better off using Shell than Python for OS environment purposes. I'll use Shell to position myself then put together a Python code once in position if that's the case.
PWD (present working directory) is in Python os.getcwd().
I think you mix up some stuff,yes using shell commands is easier for the daily navigation as we all use.
Can navigate with Python to,but the point for eg using Python os module is that want do stuff that are little more complicated than just navigate eg rename,move,copy,delete...ect file/dir.

Ah, gotcha. Makes sense. Python has os, sys libraries but their intention is not for navigation but rather execution.

Cool, I'll rely on shell for system/os runaround unless I'm in a project mindset and ready to do something in runtime where I'm like interested in doing a batch script or something.

Thanks, man! (sorry for the lack of python quotes, I'll try to use those next time!)
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020