LiClipse Python

时间:2018-02-15 09:26:14

标签: python liclipse

doc_holder_str = ''
sample_H_value = open("C:\testGupixwin\BX-N-H.HED", "r")
standard_conc_value = open("C:\testGupixwin\gupixwin_H_stdConc.txt", "r")
sample_H_value_str = sample_H_value.readline()
while sample_H_value_str is not '' :
    stripper_sample_H = float(sample_H_value_str[5:].lstrip(' '))

我正在尝试编写一段代码(如上所示),它读取一些值,对其进行一些计算并返回所述值。我正在使用LiClipse IDE,用于python。

我已经测试了我的代码并且它可以工作,但是当我尝试使用真实数据运行它时(为此我创建了一个新文件夹以放入我将使用的所有文件中)我收到操作系统错误,提示我插入了无效的参数。

错误报告说;

Traceback (most recent call last):
File "C:\Python34\workspace\Gupixwin_Project.py", line 11, in <module>
sample_H_value = open("C:\testGupixwin\BX-N-H.HED", "r")
OSError: [Errno 22] Invalid argument: 'C:\testGupixwin\\BX-N-H.HED'

点击C:\testGupixwin\\BX-N-H.HED会弹出一个消息框,提示,我引用,

  

该定义见于C:\ testGupixwin \ BX-N-H.HED,(其中   无法打开,因为它是一个已编译的扩展名)

我必须指出,我觉得错误是系统看到...... \\ BX-N ....而不是.. \ BX-N ...我期待的。

有人建议我这样做

  

[打开窗口 - &gt;偏好,转到PyDev - &gt;编辑 - &gt;代码风格 - &gt;   文件类型,查找“有效源文件(逗号分隔)”并追加   “,记录”。]

我已经完成了这一点但我仍然得到了OSERROR报告。

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我认为问题在于 public static bool RemoveDrive(string driveCharWithColon) { // open the storage volume IntPtr hVolume = CreateFile(@"\\.\" + driveCharWithColon, 0, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero); if (hVolume.ToInt32() == -1) return false; // get the volume's device number long DeviceNumber = GetDeviceNumber(hVolume); if (DeviceNumber == -1) return false; // get the drive type which is required to match the device numbers correctely string rootPath = driveCharWithColon + "\\"; DriveType driveType = GetDriveType(rootPath); // get the dos device name (like \device\floppy0) to decide if it's a floppy or not - who knows a better way? StringBuilder pathInformation = new StringBuilder(250); uint res = QueryDosDevice(driveCharWithColon, pathInformation, 250); if (res == 0) return false; // get the device instance handle of the storage volume by means of a SetupDi enum and matching the device number long DevInst = GetDrivesDevInstByDeviceNumber(DeviceNumber, driveType, pathInformation.ToString()); if (DevInst == 0) return false; // get drives's parent, e.g. the USB bridge, the SATA port, an IDE channel with two drives! int DevInstParent = 0; CM_Get_Parent(ref DevInstParent, (int)DevInst, 0); // Lock and dismount the volume. bool e = LockVolume(hVolume); int error = Marshal.GetLastWin32Error(); bool f = DismountVolume(hVolume); int error2 = Marshal.GetLastWin32Error(); // Close the volume so other processes can use the drive. if (!CloseVolume(hVolume)) return false; for (int tries = 1; tries <= 3; tries++) // sometimes we need some tries... { int r = CM_Request_Device_Eject_NoUi(DevInstParent, IntPtr.Zero, null, 0, 0); if (r == 0) return true; Thread.Sleep(500); } return false; }

的转义

将字符串替换为:\ 用:

open("C:\testGupixwin\BX-N-H.HED", "r")

(也在以下行中执行此操作)