【发布时间】:2019-01-23 21:04:11
【问题描述】:
我在小猎犬骨黑色上使用 Pyhton(2.7) 中的代码来创建我将填充数据复制到的文件夹。这些文件夹安装到 micro-SD 卡(存档)和拇指驱动器(实时数据副本)。该文件正在我的工作目录中制作。
代码:
@staticmethod # Creates a folder if not present
def create_folder(folder_name):
directory = os.path.dirname(folder_name)
try:
os.path.exists(directory)
print("Folder failed")
except:
os.makedirs(directory, 0o777)
print("Folder created")
错误:
Traceback (most recent call last):
File "/var/lib/cloud9/TEMS_Operations/System_Files.py", line 125, in <module>
temp.create_folder(temp.main_folder)
File "/var/lib/cloud9/TEMS_Operations/System_Files.py", line 41, in create_folder
directory = os.path.dirname(folder_name)
File "/usr/lib/python2.7/posixpath.py", line 122, in dirname
i = p.rfind('/') + 1
AttributeError: 'function' object has no attribute 'rfind'
有什么建议吗?
测试程序:
def test(self): # System file test
name1 = self.alarm_file()
print(name1)
name2 = self.data_file()
print(name2)
name3 = self.main_folder()
print(name3)
name4 = self.arch_folder()
print(name4)
self.create_data_file(name2)
self.create_alarm_file(name1)
self.create_folder(name3)
self.create_folder(name4)
file_to = name3 + name1
file_from = mane4 +name1
self.copyfile(file_from, file_to)
temp = SystemFiles("ZapOFS", "ZapLab")
print(os.getcwd())
temp.test()
错误:
/media/mmc/2019/1
/media/usb/2019/1
File created
File created
<type 'str'>
Folder failed
<type 'str'>
Folder failed
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/ikpdb.py", line 1866, in main
ikpdb._runscript(mainpyfile)
File "/usr/local/lib/python2.7/dist-packages/ikpdb.py", line 1415, in _runscript
exec(statement, globals, locals)
File "<string>", line 1, in <module>
File "/var/lib/cloud9/TEMS_Operations/System_Files.py", line 132, in <module>
temp.test()
File "/var/lib/cloud9/TEMS_Operations/System_Files.py", line 127, in test
copyfile(file_from, file_to)
File "/usr/lib/python2.7/shutil.py", line 82, in copyfile
with open(src, 'rb') as fsrc:
IOError: [Errno 2] No such file or directory: '/media/usb/2019/1ZapOFS_ZapLab_Alarm_File_2019_1.csv'
[IKPdb-g] 16:34:52,604104 - INFO - Uncaught exception. Entering post mortem debugging
【问题讨论】:
-
你在 create_folder 方法中传递了什么?
-
我正在为目的地发送字符串。 “/媒体/usb/存档/日期”
-
您可以尝试在
def create_folder(folder_name):行之后添加print type(folder_name)并检查folder_name的类型是什么 -
有关信息,请参见上文
-
请在
temp.create_folder(temp.main_folder) 中添加此代码 sn-p 文件“/var/lib/cloud9/TEMS_Operations/System_Files.py”,第 125 行跨度>
标签: python-2.7 usb directory beagleboneblack mmc