Jul-13-2020, 06:01 PM
(Jul-13-2020, 04:10 PM)DeaD_EyE Wrote:(Jul-13-2020, 02:58 PM)12237ee1 Wrote: I am using linux so where should I put the path of the file in the script
I tried it like this
a= "/home/file.txt"
pdf_files = set(a)
but it didn't work .. also I need the result without brackets only the name of one file in each line
thank you
Usually you save your data in your homedirectory.
If your username is12237ee1
, then path to your home directory is:/home/12237ee1/
. Put your file into your home directory. If you open your terminal window, you're already loged in with your user. Usepwd
to show the Path where you are.
Applying the set on a regularstr
does not what you want:
In [1]: set("/home/file.txt") Out[1]: {'.', '/', 'e', 'f', 'h', 'i', 'l', 'm', 'o', 't', 'x'}You need the lines in a sequence and then you can consume them with a set.
with open("/home/12237ee1/file.txt") as fd: unique_lines = set(fd)fd
is an iterator, which yields lines (with line ending).
Theset()
takes those elements. Identical lines are removed and the order is not preserved.
But these are the basics. You need to know what a file object is, what iterables are and what the different data types does with it.
Otherwise, you'll not understand how Python works. I call it brute-force programming, what you do.
how to do it with split() beacuse yes these's more than one link in one line ? in another word how to only print the name between "/" and ".pdf" while including the ".pdf"
if you can put all the script in one box so I can understand better .. thank you again