for what use dot after comand "ls" in linux? ~ ls [duplicate] - python

This question already has answers here:
What is double dot(..) and single dot(.) in Linux?
(4 answers)
Closed 2 years ago.
using the command ~ls allows you to list files, which is difference if I add dot ~ls . ?
sorry for my english, I am practicing

dot shows the folder you are in. If u re in downloads. ls . shows downloads. In your situation, ls (without a directory argument) is going to list directories and files under the current directory(pwd).

Related

Adding a absolute path that has a \f in it [duplicate]

This question already has answers here:
How can I put an actual backslash in a string literal (not use it for an escape sequence)?
(4 answers)
Closed 3 months ago.
While adding an absolute path to my script because it has a \f in it the code won't run properly.
C:\Users\showoi\Desktop\website\repository\fileAdder\softwarelisting.xlsx
The file is in the same directory as the script but using a relative path won't work. No misspellings or anything.
Use python r string
path=r'C:\Users\showoi\Desktop\website\repository\fileAdder\softwarelisting.xlsx'
Use one of the following ways:
r"C:\Users\showoi\Desktop\website\repository\fileAdder\softwarelisting.xlsx"
"C:\\Users\\showoi\\Desktop\\website\\repository\\fileAdder\\softwarelisting.xlsx"
"C:/Users/showoi/Desktop/website/repository/fileAdder/softwarelisting.xlsx

How to get the current directory in python? [duplicate]

This question already has answers here:
How to convert back-slashes to forward-slashes?
(9 answers)
Closed 1 year ago.
I'm trying to get the current directory using the OS module, like that:
directory=os.getcwd()
However, when I do this, the directory comes with \, like 'C:\Users\...', and I need to use directory with \\ or /.
Is that anyway to get the directory with \\ or /?
You can just replace the \ with /. Note that the former must be escaped with another \, like below:
import os
directory = os.getcwd().replace('\\', '/')

How to get exact match while writing dataframe in file in pyspark using escape or quote? [duplicate]

This question already has answers here:
Propagate all arguments in a Bash shell script
(12 answers)
Closed 2 years ago.
I am trying to load Data frame into file but not able to get exact match. Can you please help me on this?
example:
"From...............\"dawood\"...........\"oral use\"........"
but i am getting:
"From................\"dawood\"...........\\"oral use\\\"......"
i am using below code to write the dataframe:
df.repartition(1).write.format('com.databricks.spark.csv').mode('overwrite').save(output_path,quote='"', sep='|',header='True',nullValue=None)
Can you please help me how to get exact match for all the reords.
either just copy this inside your shell script:
python imed_consump.py 'Smart Source'
but then your parameter is always fixed. should this not be desired, then do following inside shell
python imed_consump.py "$1"
and execute your shell like:
bash imed_consump.sh 'Smart Source'

Python path separator [duplicate]

This question already has answers here:
How to get the PATH environment-variable separator in Python?
(5 answers)
Closed 4 years ago.
Is there a proper platform-dependent (or independent?) path separator character somewhere in the Python standard library?
I am not asking about the directory separator / and \, but rather about the PATH separator: : and ;.
Java has java.io.File.pathSeparatorChar and java.io.File.pathSeparator to fulfill this need. Does Python have something similar? A fairly exhaustive search in os.path and pathlib docs yielded nothing, so I am beginning to lose hope.
I am not particularly hung up on the character itself. A function that behaves like os.path.join but for entire paths instead of path elements would be perfectly acceptable, preferable even.
Maybe this is what you're looking for:
import os
os.pathsep
os.pathsep is : or ; while os.path.sep is \ or /.

use os.system('MyCommand') in the next command [duplicate]

This question already has answers here:
Equivalent of Bash Backticks in Python [duplicate]
(11 answers)
Closed 8 years ago.
As far as you know, we can use OS console commands, (For example dir,time and format in Windows) in Python programing using os.system('TheCommand') module. But this function return the state of Operation (0 for successful and 1 for failed).
I want to know if is there any way to use the output of the commands in the next commands? I mean (For example) I run os.system('dir') and save the list of directories in a variable!
This is fairly easy to do. Here I define the working directory and the edit time of a file as variables which I used later in my script.
#!/usr/bin/env python
PWD = os.getcwd()
edit_time=os.path.getmtime(file.txt)

Categories