在Python中的BeagleBone Black上创建文件夹

时间:2019-01-23 21:04:11

标签: python-2.7 usb directory beagleboneblack mmc

我在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

1 个答案:

答案 0 :(得分:0)

允许在已安装的MMC和/或BeagleBone黑色的USB驱动器上的python中创建文件夹的唯一方法是,删除当前用户的sudo密码,并为该程序添加-rw权限。

# sudo echo "debian  ALL=NOPASSWD: ALL" >>/etc/sudoers

不是我希望的,而是我能找到的唯一方法。

https://elinux.org/Beagleboard:BeagleBoneBlack_Debian