Python 3 Simple Examples get current folder and go to parent

Pubblicato il: 12 settembre 2018
sul canale di: Softhints - Python, Linux, Pandas
2,305
13

Python change current directory(up to parent) 3 Examples

https://blog.softhints.com/python-cha...

os.chdir("..")
pathlib - p.parent
os.chdir(os.path.dirname(os.getcwd()))

Example 1

import os
print(os.path.abspath(os.curdir))
os.chdir("..")
print(os.path.abspath(os.curdir))

Example 2

from pathlib import Path
p = Path("/home/user/myfile.txt")
print(p.parent)
print(p.parent.parent)


Example 3

import os
print(os.path.dirname(os.getcwd()))
os.chdir(os.path.dirname(os.getcwd()))
print(os.path.dirname(os.getcwd()))

---------------------------------------------------------------------------------------------------------------------------------------------------------------
Code store

https://bitbucket.org/softhints/

Socials

Facebook:   / 435421910242028  
Facebook:   / softhints  
Twitter:   / softwarehints  
Discord:   / discord  


If you really find this channel useful and enjoy the content, you're welcome to support me and this channel with a small donation via PayPal.

PayPal donation https://www.paypal.me/fantasyan


In questa pagina del sito puoi guardare il video online Python 3 Simple Examples get current folder and go to parent della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Softhints - Python, Linux, Pandas 12 settembre 2018, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 2,305 volte e gli è piaciuto 13 spettatori. Buona visione!