Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting Around in OS X
#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


Messages In This Thread
Getting Around in OS X - by soupking - Jun-26-2019, 01:52 AM
RE: Getting Around in OS X - by Larz60+ - Jun-26-2019, 02:10 PM
RE: Getting Around in OS X - by soupking - Jun-26-2019, 02:27 PM
RE: Getting Around in OS X - by snippsat - Jun-26-2019, 03:23 PM
RE: Getting Around in OS X - by soupking - Jun-26-2019, 03:34 PM

Forum Jump:

User Panel Messages

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