Питхон: користите наредбу за копирање датотеке - како то функционише
Овај водич за Питхон показује како можете користити копију датотеке копирања у Питхон-у за копирање датотеке. Користећи једноставан пример, лако то можете учинити и сами.
Користите наредбу за копирање датотеке у Питхон-у
Помоћу команде за копирање датотеке у Питхону датотеке се могу лако копирати:
- На почетак кода додајте наредбу „фром схутил импорт цопифиле“ (без наводника) да бисте касније могли користити наредбу.
- Синтакса наредбе је "цопифиле (срц, дст)". Зато само убаците вредности које су вам потребне за ваш програм.
- Примјер за то би био: "цопифиле ('/ срц / дир / филе.ткт', '/дст/дир/филе_витх_нев_наме.ткт')".
- Као што видите, не можете само копирати датотеку, већ и променити име датотеке у циљном директорију.
- Савет: У команди можете да користите и "/ дст / дир /" уместо "/дст/дир/филе_витх_нев_наме.ткт". Ово копира датотеку с оригиналним именом датотеке и смешта је у циљни директориј.
Питхон: Копирај датотеку - друге опције
Да бисмо копирали датотеку у Питхон, увели смо метод схутил у претходном параграфу. Међутим, датотеку можете копирати и без модула схутил:
- Пре свега, морате да додате команду "импорт ос" на врх вашег кода.
- Под Виндовсом сада можете копирати датотеку са командом "ос.систем ('копирај Д: /тест.ткт Ф: /')".
- С Линуком морате користити наредбу "ос.систем ('цп /хоме/усер/тест.ткт / тмп /')".
- У оба случаја извршава се наредба копирања. Између заграда можете написати и друге команде које се затим извршавају у терминалу или у ЦМД-у.
Више савета о Питхону у нашим ЦХИП водичима
Савет: Додатне туторијале за програмирање можете пронаћи на нашој страници теме Питхон језика за програмирање. На пример, показаћемо вам како да креирате и користите низове у Питхон-у.