匯入其他py檔案時提示“unicode error”
1、import sys
sys.path.append("D:\\Users\\hello.py")
2、import sys
sys.path.insert(0,"D:\\Users\\hello.py")
若為:sys.path.append("D:\Users\hello.py"),提示錯誤:SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
因為一個反斜槓則會進行轉義
3、line = f.readline() #逐行讀取
line = f.read() #讀取全部
line = f,read(size) #讀取一定的size
也可用一個while迴圈,每次讀取一行,直到讀完
while line:
print (line)
line = f.readline()
f.close()
4、for line in open("amy.txt"):
print (line) #此方法可自動關閉檔案
相關推薦
匯入其他py檔案時提示“unicode error”
1、import sys sys.path.append("D:\\Users\\hello.py") 2、import sys sys.path.insert(0,"D:\\Users\\hello.py") 若為:sys.path.append("
pycharm匯入本地py檔案時,模組下方出現紅色波浪線時如何解決
有時候匯入本地模組或者py檔案時,下方會出現紅色的波浪線,但不影響程式的正常執行,但是在檢視源函式檔案時,會出現問題 問題如下: 解決方案: 1. 進入設定,找到Console下的Pyth
Python使用import匯入相對路徑的其他py檔案
假如有如下的目錄結構 . ├── setup.py ├── main.py ├── mod/ │ └── mod.py └── sub/ └── sub.py 情況1:setup.py匯入main.py import main from main imp
PostgreSQL copy 時提示:ERROR: invalid byte sequence for encoding "UTF8": 0xb3
color 方式 clas lena 三種 rep schema error val 測試時使用三種文件格式: ISO-8859 Netpbm PBM image ASCII if [ $(file $filename|grep -c "ISO-8859") -gt 0
刪除檔案時提示正在被使用無法刪除問題/刪除dll檔案
刪除執行中的.dll檔案 當我們刪除一個資料夾或者應用程式的時候,總是會遇到當前檔案正在被使用,請關閉後重試的問題,一種情況是當前應用或檔案正在視窗中開啟,另一種情況就是即使應用程式沒有執行,工作管理員中也沒有該應用的程序,重啟還是會遇到提示無法刪除。大多數時候是資料夾中存在dll檔案正
【轉帖】 Windows中解決刪除檔案時提示被程序佔用的問題
原文連結是:https://blog.csdn.net/caodinke/article/details/45101119 應用背景: windows作業系統中,有時我們關閉程式後,一些相關的程序仍在後臺執行,並訪問著一些檔案,使得我們無法對這些檔案及其所屬的資料夾進行刪除、重新命名等操
Pycharm在建立py檔案時,如何自動新增預設檔案頭註釋?
PyCharm是一款很好用的編寫Python工程的IDE,用PyCharm建立一個Python檔案或者向工程新增一個.py檔案時,為了更好的使所編寫的程式碼在各操作環境更好的執行,我們往往需要在.py檔案中新增標頭檔案標註相關資訊。例如: 開啟PyCharm程式,根據選單欄中按照如下進入設定: Fil
C#儲存excel檔案時提示檔案格式與副檔名不匹配
如果儲存生成的excel檔案提示如下錯誤, 可以通過設定儲存excel格式來解決。 【例】 public static string xlsFilePath = @"D:\";//excel檔案存放路徑 &nbs
Redis第一次啟動,SHUTDOWN時提示: (error) ERR Errors trying to SHUTDOWN. Check logs.
今天我也是第一次玩redis,從下載到安裝到HelloWorld一切順風順水,誰知在最後關閉redis時,出現了(error) ERR Errors trying to SHUTDOWN. Check logs.錯誤。下面貼出我的解決過程(可能有點繁瑣):
已解決:執行python manage.py makemigrations時提示錯誤:__init__() missing 1 required positional argument: 'on
報錯資訊如下: (blog) λ python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 15, in <module> e
Eclipse匯入新的tomcat時提示錯誤:Unknown version of Tomcat was specified
最近開啟以前寫的一個專案時,開始總是報HttpServlet的錯誤,一看就想到了了沒有在工程裡匯入Tomcat,但是開啟: Build Path->Add Libraries,發現是有Tomcat的,於是就去Window -->Preferences-->
php 上傳檔案時Internal Server Error或者mod_fcgid: HTTP request length 136136 (so far) exceeds MaxRequestLen
php檔案上傳時遇到這個坑:Internal Server Error,查了Apache下的日誌資訊,才知道: mod_fcgid: HTTP request length 136136 (so fa
安裝CentOS時提示an error has occurred no valid devices were found
安裝CentOS時提示an error has occurred. - no valid devices were found在VMware-server 下裝linux 在建立分割槽的時候提示: an error has occurred. - no valid device
使用pyinstaller打包多個py檔案時,遇到的no module ...,exe檔案一閃而過,自定義模組打包等問題
1.跳過pyinstaller的安裝,自行谷歌 2. 用cmd cd到你想要打包的py檔案所在的資料夾下面,這裡我的資料夾是ceshi;我需要打包的檔案為main.py、a1.py、a2.py 3.執行命令pyi-makespec main.py,這裡將會根據你的mai
appium 用執行時提示Fatal Error: EPIPE: broken pipe, write
# !/usr/bin/env python # -*- coding:utf-8 -*- import os class DosCmd(object): def execute_cmd_result(self, command):
已解決:執行python manage.py makemigrations時提示錯誤:__init__() missing 1 required positional argument: 'on
報錯資訊如下: (blog) λ python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 15, in <module> execute
Win7刪除、移動檔案時提示資料夾正在使用怎麼辦
如何解決Win7系統在刪除或移動檔案時提示,“操作無法完成,因為其中的資料夾或檔案已在另一個程式中開啟,請關閉該資料夾或檔案,然後重試”。 右擊工作列,選擇“啟動工作管理員” 選擇“效能”標籤下的“資源監視器” 在“CPU”標籤下的“關聯的控制代碼”欄輸入該檔案或資料
安裝rebar時提示"Uncaught error in rebar_core"
最近在學Erlang,看到第25章時要安裝一個叫做rebar的軟體,具體怎麼用還不知道,只不過中途出了點問題,花了一下午才解決問題,實在太蛋疼了,所以特整理出此博文,如果有人遇到同樣的問題可以有個參考
刪除檔案時提示“找不到該專案”,怎麼解決?
1.把以下程式碼複製貼上到一新建的txt記事本文件中,並另存為del.bat檔案(或者你喜歡的名字),注意副檔名為批處理檔案bat; DEL /F /A /Q \?\%1 RD /S /Q \?\%
caffe下使用g++編譯cpp檔案時 遇到 fatal error: cublas_v2.h: 沒有那個檔案或目錄
一、前言 在caffe下使用g++編譯cpp檔案生成bin檔案時突然遇到 fatal error: cublas_v2.h: 沒有那個檔案或目錄 這個吐血問題,通過查詢資料找到解決的方法了 二、g++編譯生成bin檔案 本人的編譯命令是 g++