Hướng dẫn how do you give a path to a variable in python? - làm thế nào để bạn đưa ra một đường dẫn đến một biến trong python?

Tôi đang cố gắng chuyển đổi một vài hình ảnh được nhấp vào máy ảnh của các ký tự Gujarati viết tay sang dạng dữ liệu MNIST khi tôi dự định chuyển các hình ảnh ký tự viết tay Gujarati sang mô hình học sâu Mnist. Và như một phần của điều đó, tôi đang cố gắng gán một đường dẫn tệp cho một biến có tên là "Datadir". Nhưng khi thực hiện mã dưới đây trong Ubuntu 16.04, thiết bị đầu cuối đã ném lỗi trông như thế này: Tệp "Gujaratinn.py", dòng 7 datadir = /home/cryptoaniket256/desktop/opencv-3.4 Cú pháp không hợp lệ

Show

Lưu ý rằng tên của tệp là gujaratinn.py và tất cả các hình ảnh được nhấp vào camera được lưu trữ trong thư mục thay đổi kích thước.

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("/home/cryptoaniket256/Desktop/opencv- 
3.4.1/project/Resize")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())

Hướng dẫn how do you give a path to a variable in python? - làm thế nào để bạn đưa ra một đường dẫn đến một biến trong python?

cổ vũ người bạn đời

1.8844 huy hiệu vàng17 Huy hiệu bạc26 Huy hiệu đồng4 gold badges17 silver badges26 bronze badges

Đã hỏi ngày 29 tháng 10 năm 2018 lúc 14:03Oct 29, 2018 at 14:03

Hướng dẫn how do you give a path to a variable in python? - làm thế nào để bạn đưa ra một đường dẫn đến một biến trong python?

1

Bạn đang ảnh hưởng đến Datadir với một đường dẫn bạn đã viết trên 2 hàng trong mã của mình?

Cố gắng đặt dòng 7 và 8 trên cùng một hàng hoặc thay đổi các trích dẫn như thế:

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())

Đã trả lời ngày 29 tháng 10 năm 2018 lúc 14:12Oct 29, 2018 at 14:12

2

Đội câu trả lời giáo dục

Biến đường dẫn

Biến đường dẫn là một danh sách các thư mục trong đó mỗi thư mục chứa tệp thực thi cho một lệnh.PATH variable is a list of directories where each directory contains the executable file for a command.

Khi một lệnh được nhập vào dấu nhắc lệnh windows, lời nhắc tìm kiếm trong biến đường dẫn cho một tệp thực thi có cùng tên với lệnh; Tôi không tìm thấy trường hợp tệp cần thiết, nó trả lời với thông báo lỗi nói rằng lệnh được chỉ định không được nhận ra.

Một cách để khắc phục lỗi này là viết thư mục hoàn chỉnh của tệp thực thi thay vì chỉ nhập tên lệnh. Tuy nhiên, đây không phải là một cách tiếp cận rất thân thiện với người dùng.

Một cách khác có thể và dễ dàng hơn để tránh lỗi này là thêm thư mục tệp thực thi vào biến đường dẫn. Thông thường, điều này cần phải được thực hiện khi cài đặt Python.

Đường dẫn hoàn chỉnh của python.exe có thể được thêm vào bởi:python.exe can be added by:

  1. Nhấp chuột phải vào PC này và đi đến thuộc tính.

  2. Nhấp vào cài đặt hệ thống nâng cao trong menu bên trái.

  3. Nhấp vào nút biến môi trường o n phía dưới bên phải.

  4. Trong phần Biến hệ thống, chọn biến đường dẫn và nhấp vào Chỉnh sửa. Màn hình tiếp theo sẽ hiển thị tất cả các thư mục hiện là một phần của biến đường dẫn.

  5. Nhấp vào thư mục cài đặt mới và nhập Python.

Python bây giờ có thể được sử dụng trực tiếp từ dấu nhắc lệnh mà không phải viết vị trí của nó. Hãy thử thực thi lệnh

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
0; Nó sẽ xuất ra phiên bản Python được cài đặt trên hệ thống của bạn.

Thông thường bạn có thể tìm thấy nhị phân được cài đặt Python ở vị trí đường dẫn này:

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
1

THẺ LIÊN QUAN

Python

các cửa sổ

đường dẫn

Biến đổi

thực thi

Bạn có thể cần thêm Python vào

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 nếu bạn đã cài đặt Python, nhưng gõ
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 trên dòng lệnh dường như không hoạt động. Bạn có thể nhận được một tin nhắn nói rằng thuật ngữ
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 không được công nhận, hoặc bạn có thể kết thúc với phiên bản sai của Python đang chạy.

Một bản sửa lỗi phổ biến cho những vấn đề này là thêm Python vào biến môi trường

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2. Trong hướng dẫn này, bạn sẽ học cách thêm Python vào
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2. Bạn cũng sẽ tìm hiểu về
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 là gì và tại sao
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 rất quan trọng đối với các chương trình như dòng lệnh để có thể tìm thấy cài đặt Python của bạn.

Các bước mà bạn sẽ cần thực hiện để thêm một cái gì đó vào

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 sẽ phụ thuộc đáng kể vào hệ điều hành (HĐH) của bạn, vì vậy hãy chắc chắn bỏ qua phần có liên quan nếu bạn chỉ quan tâm đến quy trình này cho một HĐH.

Lưu ý rằng bạn có thể sử dụng các bước sau để thêm bất kỳ chương trình nào vào

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2, không chỉ Python.

Cách thêm Python vào import numpy as np import matplotlib.pyplot as py import os import cv2 from pathlib import Path datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""") fileToOpen = datadir/"practice.txt" f = open(fileToOpen) print(f.read()) 2 trên Windows

Bước đầu tiên là xác định vị trí thư mục trong đó mục tiêu của bạn có thể thực thi được cuộc sống. Đường dẫn đến thư mục là những gì bạn sẽ thêm vào biến môi trường

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2.

Để tìm Python thực thi, bạn sẽ cần tìm một tệp có tên là python.exe. Việc thực thi Python có thể nằm trong một thư mục trong

C:\Users\\AppData\Local\Programs\Python
4 hoặc trong thư mục
C:\Users\\AppData\Local\Programs\Python
5 của bạn. Nếu thực thi có trong
C:\Users\\AppData\Local\Programs\Python
5, thì đường dẫn thường trông giống như thế này:

C:\Users\\AppData\Local\Programs\Python

Trong trường hợp của bạn, phần

C:\Users\\AppData\Local\Programs\Python
7 sẽ được thay thế bằng tên người dùng hiện đang đăng nhập của bạn.

Khi bạn đã tìm thấy thực thi, hãy đảm bảo rằng nó hoạt động bằng cách nhấp đúp vào nó và xác minh rằng nó bắt đầu một python replin trong một cửa sổ mới.

Nếu bạn đang vật lộn để tìm đúng thực thi, bạn có thể sử dụng tính năng tìm kiếm Windows Explorer. Vấn đề với tìm kiếm tích hợp là nó rất chậm. Để thực hiện tìm kiếm hệ thống đầy đủ siêu nhanh cho bất kỳ tệp nào, một giải pháp thay thế tuyệt vời là tất cả:

Hướng dẫn how do you give a path to a variable in python? - làm thế nào để bạn đưa ra một đường dẫn đến một biến trong python?

Những con đường được làm nổi bật với màu vàng, cụ thể là những con đường tại

C:\Users\\AppData\Local\Programs\Python
8 và
C:\Users\\AppData\Local\Programs\Python
9, sẽ là ứng cử viên lý tưởng để thêm vào
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 vì chúng trông giống như các tệp thực thi ở cấp độ gốc của cài đặt. Những người nổi bật trong Red willn phù hợp vì một số là một phần của môi trường ảo, bạn có thể thấy
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
1 trong đường dẫn và một số phím tắt hoặc cài đặt Windows bên trong.

Bạn cũng có thể bắt gặp các tệp thực thi Python được cài đặt trong thư mục cho một chương trình khác. Điều này là do thực tế là nhiều ứng dụng gói phiên bản Python của riêng họ trong đó. Những cài đặt Python đi kèm này cũng sẽ không phù hợp.

Khi bạn đã định vị được thực thi Python của mình, hãy mở menu Bắt đầu và tìm kiếm Chỉnh sửa mục nhập biến môi trường hệ thống, mở ra một cửa sổ thuộc tính hệ thống. Trong tab nâng cao, nhấp vào các biến môi trường nút. Ở đó, bạn sẽ thấy các biến người dùng và hệ thống mà bạn có thể chỉnh sửa:

Trong phần có tên các biến người dùng, nhấp đúp vào mục nhập đường dẫn cho biết. Một cửa sổ khác sẽ bật lên hiển thị một danh sách các đường dẫn. Nhấp vào nút mới và dán đường dẫn đến Python của bạn có thể thực thi ở đó. Sau khi chèn vào đó, chọn đường dẫn mới được thêm vào của bạn và nhấp vào nút di chuyển lên cho đến khi nó ở trên cùng.

Đó là nó! Bạn có thể cần khởi động lại máy tính của mình để có hiệu lực, nhưng giờ đây bạn sẽ có thể gọi

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 từ dòng lệnh.

Để thiết lập biến môi trường

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 từ dòng lệnh, hãy xem phần về cấu hình các biến môi trường trong Hướng dẫn thiết lập mã hóa Windows Python. Bạn cũng có thể tìm thấy hướng dẫn trong các tài liệu bổ sung:

Bạn cũng có thể muốn thiết lập

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 trên máy Linux hoặc MacOS của mình hoặc có lẽ bạn sử dụng hệ thống con Windows cho Linux (WSL). Nếu vậy, hãy đọc phần tiếp theo cho quy trình trên các hệ thống dựa trên UNIX.

Cách thêm Python vào import numpy as np import matplotlib.pyplot as py import os import cv2 from pathlib import Path datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""") fileToOpen = datadir/"practice.txt" f = open(fileToOpen) print(f.read()) 2 trên Linux và MacOS

Vì Python thường được cài đặt sẵn trên các hệ thống dựa trên UNIX, nên vấn đề phổ biến nhất trên Linux và MacOS là để

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 chạy sai, thay vì không tìm thấy bất kỳ
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 nào. Điều đó nói rằng, trong phần này, bạn sẽ khắc phục sự cố không thể chạy
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3.

Bước đầu tiên là định vị thực thi Python mục tiêu của bạn. Nó phải là một chương trình mà bạn có thể chạy bằng cách điều hướng trước tiên đến thư mục chứa và sau đó nhập

# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
9 trên dòng lệnh.

Bạn cần dành cho cuộc gọi đến Python thực thi với đường dẫn tương đối của nó trong thư mục hiện tại (

$ echo export PATH=":$PATH" >> ~/.profile
0) bởi vì nếu không, bạn sẽ gọi bất kỳ Python nào hiện đang được ghi lại trên
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của bạn. Như bạn đã biết trước đó, đây có thể không phải là phiên dịch Python mà bạn muốn chạy.

Thông thường, Python thực thi có thể được tìm thấy trong thư mục

$ echo export PATH=":$PATH" >> ~/.profile
2. Nhưng nếu Python đã có trong thư mục
$ echo export PATH=":$PATH" >> ~/.profile
2, thì rất có thể nó đã có trên
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 vì
$ echo export PATH=":$PATH" >> ~/.profile
2 được hệ thống tự động thêm vào. Nếu đây là trường hợp, thì bạn có thể muốn bỏ qua phần theo thứ tự các đường dẫn trong
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2.

Vì bạn có thể ở đây vì bạn đã cài đặt Python nhưng nó vẫn chưa được tìm thấy khi bạn nhập

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 trên dòng lệnh, bạn sẽ muốn tìm kiếm nó ở một vị trí khác.

Điều đó nói rằng, có thể là

$ echo export PATH=":$PATH" >> ~/.profile
2 đã bị xóa khỏi
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 hoàn toàn, trong trường hợp đó bạn có thể bỏ qua phần về phần mang tính cách diễn xuất
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2.

Khi bạn đã tìm thấy Python thực thi của mình và chắc chắn rằng nó hoạt động, hãy lưu ý đến đường dẫn sau này. Bây giờ, thời gian để bắt đầu quá trình thêm nó vào biến môi trường

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của bạn.

Đầu tiên, bạn sẽ muốn điều hướng đến thư mục nhà của bạn để xem các tập lệnh cấu hình bạn có sẵn:

Bạn sẽ thấy một loạt các tệp cấu hình bắt đầu bằng một khoảng thời gian (

>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
2). Chúng được gọi là thông thường là dotfiles và được ẩn khỏi
>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
3 theo mặc định.

Một hoặc hai dotfiles được thực thi bất cứ khi nào bạn đăng nhập vào hệ thống của mình, một hoặc hai lần chạy khác bất cứ khi nào bạn bắt đầu phiên dòng lệnh mới và hầu hết các ứng dụng khác được sử dụng bởi các ứng dụng khác cho cài đặt cấu hình.

Bạn đang tìm kiếm các tệp chạy khi bạn bắt đầu hệ thống hoặc phiên dòng lệnh mới. Họ có thể có tên tương tự như sau:

  • >>> PATH = "/home/realpython/apps:/bin"
    >>> PATH = f"/home/realpython/python:{PATH}"
    >>> PATH
    '/home/realpython/python:/home/realpython/apps:/bin'
    
    4
  • >>> PATH = "/home/realpython/apps:/bin"
    >>> PATH = f"/home/realpython/python:{PATH}"
    >>> PATH
    '/home/realpython/python:/home/realpython/apps:/bin'
    
    5
  • >>> PATH = "/home/realpython/apps:/bin"
    >>> PATH = f"/home/realpython/python:{PATH}"
    >>> PATH
    '/home/realpython/python:/home/realpython/apps:/bin'
    
    6
  • >>> PATH = "/home/realpython/apps:/bin"
    >>> PATH = f"/home/realpython/python:{PATH}"
    >>> PATH
    '/home/realpython/python:/home/realpython/apps:/bin'
    
    7
  • >>> PATH = "/home/realpython/apps:/bin"
    >>> PATH = f"/home/realpython/python:{PATH}"
    >>> PATH
    '/home/realpython/python:/home/realpython/apps:/bin'
    
    8

Các từ khóa để tìm kiếm là hồ sơ và đăng nhập. Về mặt lý thuyết, bạn chỉ nên có một trong số này, nhưng nếu bạn có nhiều hơn một, bạn có thể cần đọc các bình luận trong đó để tìm ra cái nào chạy trên đăng nhập. Ví dụ: tệp

>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
4 trên Ubuntu thường sẽ có nhận xét sau:

# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.

Vì vậy, nếu bạn có

>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
4 nhưng cũng
>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
5, thì bạn sẽ muốn sử dụng
>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
5.

Bạn cũng có thể sử dụng tệp

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
3 hoặc
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
4, là các tập lệnh chạy bất cứ khi nào bạn bắt đầu phiên dòng lệnh mới. Các tệp Run Command (RC) là nơi phổ biến để đặt cấu hình
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2.

Để thêm đường dẫn Python vào đầu biến môi trường

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của bạn, bạn sẽ thực hiện một lệnh duy nhất trên dòng lệnh.

Sử dụng dòng sau, thay thế

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
7 bằng đường dẫn thực tế của bạn đến thực thi Python và thay thế
>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
4 bằng tập lệnh đăng nhập cho hệ thống của bạn:

$ echo export PATH=":$PATH" >> ~/.profile

Lệnh này thêm

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
9 vào cuối
>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
4. Lệnh
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
9 đã chuẩn bị
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
7 cho biến môi trường
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2. Nó tương tự như hoạt động sau đây trong Python:

>>>

>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 chỉ là một chuỗi được phân tách bởi các đại kết, việc chi tiêu một giá trị liên quan đến việc tạo một chuỗi với đường dẫn mới, một dấu hai chấm, sau đó là con đường cũ. Với chuỗi này, bạn đặt giá trị mới của
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2.

Để làm mới phiên dòng lệnh hiện tại của bạn, bạn có thể chạy lệnh sau, thay thế

>>> PATH = "/home/realpython/apps:/bin"
>>> PATH = f"/home/realpython/python:{PATH}"
>>> PATH
'/home/realpython/python:/home/realpython/apps:/bin'
4 bằng bất kỳ tập lệnh đăng nhập nào mà bạn đã chọn:

Bây giờ, bạn sẽ có thể gọi trực tiếp

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 từ dòng lệnh. Lần tới khi bạn đăng nhập, Python sẽ tự động được thêm vào
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2.

Nếu bạn nghĩ rằng quá trình này có vẻ hơi mờ, bạn không đơn độc! Đọc tiếp để biết thêm về một cuộc lặn sâu vào những gì đang diễn ra.

Hiểu import numpy as np import matplotlib.pyplot as py import os import cv2 from pathlib import Path datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""") fileToOpen = datadir/"practice.txt" f = open(fileToOpen) print(f.read()) 2 là gì

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 là một biến môi trường chứa một danh sách các đường dẫn đến các thư mục. Mỗi đường dẫn trong
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 được phân tách bằng dấu hai chấm hoặc dấu chấm phẩy một dấu hai chấm cho các hệ thống dựa trên UNIX và dấu chấm phẩy cho Windows. Nó giống như một biến Python với một chuỗi dài như giá trị của nó. Sự khác biệt là
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 là một biến có thể truy cập bởi hầu hết các chương trình.

Các chương trình như dòng lệnh sử dụng biến môi trường

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 để tìm các tệp thực thi. Ví dụ: bất cứ khi nào bạn nhập tên của một chương trình vào dòng lệnh, dòng lệnh sẽ tìm kiếm nhiều địa điểm khác nhau cho chương trình. Một trong những nơi mà các tìm kiếm dòng lệnh là
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2.

Tất cả các đường dẫn trong

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 cần phải là thư mục, họ không nên trực tiếp là tệp hoặc thực thi. Các chương trình sử dụng
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 lần lượt thực hiện từng thư mục và tìm kiếm tất cả các tệp trong đó. Mặc dù vậy, các thư mục con trong các thư mục trong
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 don don được tìm kiếm, mặc dù. Vì vậy, nó không tốt chỉ cần thêm đường dẫn gốc của bạn vào
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2!

Nó cũng rất quan trọng cần lưu ý rằng các chương trình sử dụng

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 thường không tìm kiếm bất cứ thứ gì ngoại trừ các tệp thực thi. Vì vậy, bạn có thể sử dụng
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 như một cách để xác định các phím tắt cho các tệp thường được sử dụng.

Hiểu tầm quan trọng của trật tự trong import numpy as np import matplotlib.pyplot as py import os import cv2 from pathlib import Path datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""") fileToOpen = datadir/"practice.txt" f = open(fileToOpen) print(f.read()) 2

Nếu bạn nhập

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 vào dòng lệnh, dòng lệnh sẽ tìm trong mỗi thư mục trong biến môi trường
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 cho một thực thi
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
3 có thể thực thi. Khi nó tìm thấy một, nó sẽ ngừng tìm kiếm. Đây là lý do tại sao bạn dành cho con đường đến Python của bạn có thể thực thi thành
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2. Có đường dẫn mới được thêm vào đầu tiên đảm bảo rằng hệ thống của bạn sẽ tìm thấy Python này có thể thực thi được.

Một vấn đề phổ biến là có cài đặt Python thất bại trên

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của bạn. Nếu thực thi bị hỏng là giao dịch đầu tiên mà dòng lệnh xuất hiện, thì dòng lệnh sẽ thử và chạy nó và sau đó hủy bỏ bất kỳ tìm kiếm nào nữa. Bản sửa lỗi nhanh chóng cho việc này chỉ là thêm thư mục Python mới của bạn trước thư mục Python cũ, mặc dù bạn cũng có thể muốn làm sạch hệ thống cài đặt Python xấu của mình.

Việc sắp xếp lại

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 trên Windows tương đối đơn giản. Bạn mở bảng điều khiển GUI và điều chỉnh thứ tự bằng cách sử dụng các nút di chuyển lên và di chuyển xuống. Tuy nhiên, nếu bạn trên một hệ điều hành dựa trên UNIX, quá trình này có liên quan nhiều hơn. Đọc để tìm hiểu thêm.

Quản lý import numpy as np import matplotlib.pyplot as py import os import cv2 from pathlib import Path datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""") fileToOpen = datadir/"practice.txt" f = open(fileToOpen) print(f.read()) 2 của bạn trên các hệ thống dựa trên UNIX

Thông thường, nhiệm vụ đầu tiên của bạn khi quản lý

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của bạn là để xem những gì trong đó. Để xem giá trị của bất kỳ biến môi trường nào trong Linux hoặc MacOS, bạn có thể sử dụng lệnh
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
00:

$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

Lưu ý rằng ký hiệu

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
01 được sử dụng để nói với dòng lệnh rằng định danh sau là một biến. Vấn đề với lệnh này là nó chỉ bỏ tất cả các đường dẫn trên một dòng, cách nhau bởi các dấu chấm. Vì vậy, bạn có thể muốn tận dụng lệnh của lệnh
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
02 để dịch các dấu chấm vào Newlines:

$ echo $PATH | tr ":" "\n"
/usr/local/sbin
/usr/local/bin
/usr/sbin
/home/realpython/badpython
/usr/bin
/sbin
/bin
/usr/games
/usr/local/games

Trong ví dụ này, bạn có thể thấy rằng

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
03 có mặt trong
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2. Quá trình hành động lý tưởng sẽ là thực hiện một số khảo cổ học
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 và tìm ra nơi nó được thêm vào
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2, nhưng bây giờ, bạn chỉ muốn xóa nó bằng cách thêm một cái gì đó vào tập lệnh đăng nhập của bạn.

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 là một chuỗi shell, bạn không có quyền truy cập vào các phương pháp thuận tiện để loại bỏ các phần của nó, giống như bạn sẽ làm nếu đó là danh sách Python. Điều đó nói rằng, bạn có thể cùng nhau đặt một vài lệnh shell để đạt được một cái gì đó tương tự:

export PATH=`echo $PATH | tr ":" "\n" | grep -v 'badpython' | tr "\n" ":"`

Lệnh này lấy danh sách từ lệnh trước đó và cung cấp nó vào

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
08, cùng với công tắc
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
09, sẽ lọc ra bất kỳ dòng nào chứa chuỗi con
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
03. Sau đó, bạn có thể dịch các dòng Newlines trở lại Colons và bạn có chuỗi
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 mới và hợp lệ mà bạn sử dụng ngay để thay thế chuỗi
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 cũ của bạn.

Mặc dù đây có thể là một lệnh tiện dụng, giải pháp lý tưởng sẽ là tìm ra nơi mà con đường xấu đó được thêm vào. Bạn có thể thử xem các tập lệnh đăng nhập khác hoặc kiểm tra các tệp cụ thể trong

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
13. Ví dụ, trong Ubuntu, có một tệp có tên
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
14, thường xác định đường dẫn khởi đầu cho hệ thống. Trong macOS, đó có thể là
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
15. Cũng có thể có các tệp và thư mục
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
16 trong
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
13 có thể chứa các tập lệnh khởi động.

Sự khác biệt chính giữa các cấu hình trong

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
13 và trong thư mục nhà của bạn là những gì mà trong
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
13 có toàn hệ thống, trong khi bất cứ điều gì trong thư mục nhà của bạn sẽ được đưa vào người dùng của bạn.

Nó thường có thể liên quan đến một chút khảo cổ học để theo dõi nơi một cái gì đó được thêm vào

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của bạn. Vì vậy, bạn có thể muốn thêm một dòng trong tập lệnh đăng nhập hoặc RC của bạn để lọc ra một số mục từ
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 dưới dạng sửa lỗi nhanh.

Bản tóm tắt

Trong hướng dẫn này, bạn đã học cách thêm Python hoặc bất kỳ chương trình nào khác vào biến môi trường

import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của bạn trên Windows, Linux và MacOS. Bạn cũng đã học được nhiều hơn một chút về
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 là gì và tại sao trật tự nội bộ của nó là rất quan trọng để xem xét. Cuối cùng, bạn cũng đã phát hiện ra cách bạn có thể quản lý
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của mình trên một hệ thống dựa trên UNIX, vì nó phức tạp hơn so với việc quản lý
import numpy as np
import matplotlib.pyplot as py
import os
import cv2
from pathlib import Path

datadir = Path("""/home/cryptoaniket256/Desktop/opencv-3.4.1/project/Resize""")
fileToOpen = datadir/"practice.txt"
f = open(fileToOpen)
print(f.read())
2 của bạn trên Windows.

Làm thế nào để bạn gán một đường dẫn đến một biến?

Windows..
Trong tìm kiếm, tìm kiếm và sau đó chọn: Hệ thống (bảng điều khiển).
Nhấp vào liên kết Cài đặt hệ thống nâng cao ..
Nhấp vào các biến môi trường.....
Trong cửa sổ Biến hệ thống chỉnh sửa (hoặc biến hệ thống mới), chỉ định giá trị của biến môi trường đường dẫn.....
Reo lại cửa sổ nhắc lệnh và chạy mã Java của bạn ..

Làm thế nào để bạn nhập một đường dẫn trong Python?

Để lấy đường dẫn tệp từ đầu vào của người dùng:..
Sử dụng hàm input () để lấy đường dẫn tệp làm đầu vào từ người dùng ..
Sử dụng hệ điều hành.đường dẫn.Phương thức tồn tại () để kiểm tra xem đường dẫn được chỉ định có tồn tại không ..