I am complete newbie on linux and ubuntu. So my apologies for the dumb question. I have written python code in windows and want to run it in ubuntu, it uses an text file for input. the 'path-to-file' in windows looks as follows c:user\documents\python\file.txt, how is the location written for ubuntu?
Rather than hardcoding paths in your Python script we should make use of the path operation from the module os.
os.path.expanduser(path) expands the path to the user's home directory
I don't have permission to add comments...so I will just try to answer.
The path at UNIX will be like:
When you at any folder and want to get the absolute path of a file, you could use the
example at our server:
File paths are written as-
Everything in your home folder is located inside /home/username/
So, if you have a file on your desktop, it is located in /home/username/Desktop/
Other partitions are mounted in /media by default.
If you directly want to get the path of a file, you can copy the file, and paste it into your text editor, this should give you the path to your file. Put a \ before every space in the path to 'escape' the space. e.g. "/media/myuseraccount/Desktop/an awesome file" would be written as -
Another thing to note is that in Linux, your file names are case sensitive, so 'desktop' is not the same as 'Desktop'.
Finally, a shortcut to your home folder is to type ~
So, you can access your desktop by typing -
and you can access your home folder by typing -